@@ -3786,7 +3786,6 @@ static void SysOsVersionMajor(EvalContext *ctx)
3786
3786
3787
3787
static const char * OSReleaseGet (EvalContext * ctx , const char * field )
3788
3788
{
3789
- #ifndef __MINGW32__
3790
3789
DataType type_out ;
3791
3790
const JsonElement * os_rel = EvalContextVariableGetSpecial (
3792
3791
ctx , SPECIAL_SCOPE_SYS , "os_release" , & type_out );
@@ -3802,52 +3801,75 @@ static const char *OSReleaseGet(EvalContext *ctx, const char *field)
3802
3801
}
3803
3802
const char * result = JsonPrimitiveGetAsString (child );
3804
3803
return result ;
3804
+ }
3805
3805
3806
- #else
3807
-
3808
- Log (LOG_LEVEL_ERR , "os-release is not defined on Windows" )
3809
- return NULL ;
3810
-
3811
- #endif
3806
+ static void OSVersionMinorPut (EvalContext * ctx , const char * minor )
3807
+ {
3808
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3809
+ "os_version_minor" ,
3810
+ (minor == NULL ) ? "Unknown" : minor ,
3811
+ CF_DATA_TYPE_STRING ,
3812
+ "source=agent,derived-from=os_release" );
3812
3813
}
3813
3814
3814
3815
static void SysOSVersionMinor (EvalContext * ctx )
3815
3816
{
3817
+ #ifndef __MINGW32__
3818
+
3816
3819
const char * version_id = OSReleaseGet (ctx , "VERSION_ID" );
3817
3820
const char * name = OSReleaseGet (ctx , "NAME" );
3818
-
3819
- char * minor ;
3820
- if (version_id != NULL )
3821
+ if (version_id == NULL )
3821
3822
{
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 );
3823
+ return OSVersionMinorPut (ctx , NULL );
3836
3824
}
3837
-
3838
- if (NULL_OR_EMPTY (minor ))
3825
+ if (name == NULL )
3839
3826
{
3840
- EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3841
- "os_version_minor" , "Unknown" ,
3842
- CF_DATA_TYPE_STRING , "source=agent" );
3827
+ return OSVersionMinorPut (ctx , NULL );
3843
3828
}
3844
- else
3829
+ Item * version_tuple = SplitString (version_id , '.' );
3830
+ if (version_tuple == NULL )
3831
+ {
3832
+ return OSVersionMinorPut (ctx , NULL );
3833
+ }
3834
+ if (name != NULL && (StringStartsWith (name , "solaris" ) || StringStartsWith (name , "sunos" )))
3845
3835
{
3836
+ OSVersionMinorPut (ctx , version_tuple -> name );
3837
+ return DeleteItemList (version_tuple );
3838
+ }
3839
+ if (version_tuple -> next == NULL )
3840
+ {
3841
+ OSVersionMinorPut (ctx , NULL );
3842
+ return DeleteItemList (version_tuple );
3843
+ }
3844
+ OSVersionMinorPut (ctx , version_tuple -> next -> name );
3845
+ return DeleteItemList (version_tuple );
3846
+
3847
+ #else
3848
+
3849
+ char * release = SafeStringDuplicate (VSYSNAME .release );
3850
+ char * major = NULL ;
3851
+ char * minor = NULL ;
3852
+ char * rel ;
3853
+ rel = FindNextInteger (release , & major );
3854
+ if (rel == NULL )
3855
+ {
3856
+ free (release );
3846
3857
EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3847
- "os_version_minor" , minor ,
3848
- CF_DATA_TYPE_STRING ,
3849
- "source=agent,derived-from=os_release" );
3858
+ "os_version_minor" ,
3859
+ "Unknown" ,
3860
+ CF_DATA_TYPE_STRING ,
3861
+ "source=agent" )
3862
+ return ;
3850
3863
}
3864
+ rel = FindNextInteger (rel , & minor );
3865
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3866
+ "os_version_minor" ,
3867
+ (minor == NULL ) ? "Unknown" : minor ,
3868
+ CF_DATA_TYPE_STRING ,
3869
+ "source=agent" );
3870
+ free (release );
3871
+
3872
+ #endif
3851
3873
}
3852
3874
3853
3875
0 commit comments