Skip to content

Commit e9cb703

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 a24760e commit e9cb703

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

libenv/sysinfo.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,6 +3771,58 @@ static void SysOsVersionMajor(EvalContext *ctx)
37713771
free(flavor);
37723772
}
37733773

3774+
/*****************************************************************************/
3775+
3776+
static const char *OSReleaseGet(EvalContext *ctx, const char *field)
3777+
{
3778+
DataType type_out;
3779+
const JsonElement *os_rel = EvalContextVariableGetSpecial(
3780+
ctx, SPECIAL_SCOPE_SYS, "os_release", &type_out);
3781+
3782+
if (type_out != CF_DATA_TYPE_CONTAINER)
3783+
{
3784+
return NULL;
3785+
}
3786+
const JsonElement *child = JsonObjectGet(os_rel, field);
3787+
if (child == NULL)
3788+
{
3789+
return NULL;
3790+
}
3791+
const char *result = JsonPrimitiveGetAsString(child);
3792+
return result;
3793+
}
3794+
3795+
static void SysOSVersionMinor(EvalContext *ctx)
3796+
{
3797+
const char *version_id = OSReleaseGet(ctx, "VERSION_ID");
3798+
3799+
char *minor;
3800+
if (version_id != NULL)
3801+
{
3802+
Item *version_tuple = SplitString(version_id, '.');
3803+
3804+
if (version_tuple != NULL && version_tuple->next != NULL)
3805+
{
3806+
minor = version_tuple->next->name;
3807+
}
3808+
}
3809+
3810+
if (NULL_OR_EMPTY(minor))
3811+
{
3812+
EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS,
3813+
"os_version_minor", "Unknown",
3814+
CF_DATA_TYPE_STRING, "source=agent");
3815+
}
3816+
else
3817+
{
3818+
EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS,
3819+
"os_version_minor", minor,
3820+
CF_DATA_TYPE_STRING,
3821+
"source=agent,derived-from=os_release");
3822+
}
3823+
}
3824+
3825+
37743826
/*****************************************************************************/
37753827

37763828
void DetectEnvironment(EvalContext *ctx)
@@ -3785,4 +3837,5 @@ void DetectEnvironment(EvalContext *ctx)
37853837
GetDefVars(ctx);
37863838
SysOSNameHuman(ctx);
37873839
SysOsVersionMajor(ctx);
3840+
SysOSVersionMinor(ctx);
37883841
}

0 commit comments

Comments
 (0)