Skip to content

Commit e57cbe7

Browse files
committed
Added os_version_minor sys variable
Ticket: ENT-8118 Changelog: Title Signed-off-by: Victor Moene <victor.moene@northern.tech>
1 parent e8974b5 commit e57cbe7

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

libenv/sysinfo.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3782,6 +3782,75 @@ static void SysOsVersionMajor(EvalContext *ctx)
37823782
free(flavor);
37833783
}
37843784

3785+
/*****************************************************************************/
3786+
3787+
static const char *OSReleaseGet(EvalContext *ctx, const char *field)
3788+
{
3789+
#ifndef __MINGW32__
3790+
DataType type_out;
3791+
const JsonElement *os_rel = EvalContextVariableGetSpecial(
3792+
ctx, SPECIAL_SCOPE_SYS, "os_release", &type_out);
3793+
3794+
if (type_out != CF_DATA_TYPE_CONTAINER)
3795+
{
3796+
return NULL;
3797+
}
3798+
const JsonElement *child = JsonObjectGet(os_rel, field);
3799+
if (child == NULL)
3800+
{
3801+
return NULL;
3802+
}
3803+
const char *result = JsonPrimitiveGetAsString(child);
3804+
return result;
3805+
3806+
#else
3807+
3808+
Log(LOG_LEVEL_ERR, "os-release is not defined on Windows")
3809+
return NULL;
3810+
3811+
#endif
3812+
}
3813+
3814+
static void SysOSVersionMinor(EvalContext *ctx)
3815+
{
3816+
const char *version_id = OSReleaseGet(ctx, "VERSION_ID");
3817+
const char *name = OSReleaseGet(ctx, "NAME");
3818+
3819+
char *minor;
3820+
if (version_id != NULL)
3821+
{
3822+
Item *version_tuple = SplitString(version_id, '.');
3823+
3824+
if (version_tuple != NULL)
3825+
{
3826+
if (name != NULL && (StringStartsWith(name, "solaris") || StringStartsWith(name, "sunos")))
3827+
{
3828+
minor = version_tuple->name;
3829+
}
3830+
else if (version_tuple->next != NULL)
3831+
{
3832+
minor = version_tuple->next->name;
3833+
}
3834+
}
3835+
free(version_tuple);
3836+
}
3837+
3838+
if (NULL_OR_EMPTY(minor))
3839+
{
3840+
EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS,
3841+
"os_version_minor", "Unknown",
3842+
CF_DATA_TYPE_STRING, "source=agent");
3843+
}
3844+
else
3845+
{
3846+
EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS,
3847+
"os_version_minor", minor,
3848+
CF_DATA_TYPE_STRING,
3849+
"source=agent,derived-from=os_release");
3850+
}
3851+
}
3852+
3853+
37853854
/*****************************************************************************/
37863855

37873856
void DetectEnvironment(EvalContext *ctx)
@@ -3796,4 +3865,5 @@ void DetectEnvironment(EvalContext *ctx)
37963865
GetDefVars(ctx);
37973866
SysOSNameHuman(ctx);
37983867
SysOsVersionMajor(ctx);
3868+
SysOSVersionMinor(ctx);
37993869
}

0 commit comments

Comments
 (0)