summaryrefslogtreecommitdiff
path: root/src/system.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-09-18 15:27:15 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2014-09-18 15:27:15 +0200
commit360a2f310b17f3610db6d6915eb5cbe7b646cf25 (patch)
tree7ea653f06afdc3971b5ea925e8262109387d51ba /src/system.c
parent1669c1b67706905500ab397c95afb796466cf2a6 (diff)
downloadbiruda-360a2f310b17f3610db6d6915eb5cbe7b646cf25.tar.gz
biruda-360a2f310b17f3610db6d6915eb5cbe7b646cf25.tar.bz2
system_cpe_name, code cleanup
Diffstat (limited to 'src/system.c')
-rw-r--r--src/system.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/system.c b/src/system.c
index 6e5e054..158a68d 100644
--- a/src/system.c
+++ b/src/system.c
@@ -55,8 +55,9 @@ void system_cpe_name( char *name, size_t len )
char line[100];
char *key;
- char *os = NULL;
- char *version = NULL;
+ char *id = NULL;
+ char *version_id = NULL;
+ char *cpe_name = NULL;
while( !feof( f ) ) {
fgets( line, sizeof( line ), f );
if( line[0] == '#' ) continue;
@@ -83,33 +84,35 @@ void system_cpe_name( char *name, size_t len )
*q = '\0';
if( strcmp( key, "CPE_NAME" ) == 0 ) {
- snprintf( name, len, "%s", value );
- if( os != NULL ) free( os );
- if( version != NULL ) free( version );
- fclose( f );
- return;
- } else if( strcmp( key, "NAME" ) == 0 ) {
- os = strdup( value );
+ cpe_name = strdup( value );
+ } else if( strcmp( key, "ID" ) == 0 ) {
+ id = strdup( value );
} else if( strcmp( key, "VERSION_ID" ) == 0 ) {
- version = strdup( value );
+ version_id = strdup( value );
}
}
fclose( f ) ;
- if( strcmp( os, "Arch Linux" ) == 0 ) {
- free( os );
- os = strdup( "archlinux" );
- }
+ /* do we have a CPE_NAME? In this case CPE_NAME takes
+ precedence */
+ if( cpe_name != NULL ) {
+ snprintf( name, len, "%s", cpe_name );
+ } else {
+ /* construct CPE_NAME from ID and VERSION_ID and any other
+ information we find */
- if( version == NULL ) {
- version = strdup( "rolling" );
- }
+ /* no version information, so we have a rolling release */
+ if( version_id == NULL ) {
+ version_id = strdup( "rolling" );
+ }
- snprintf( name, len, "cpe:/o:%s:%s:%s", os, os, version );
+ snprintf( name, len, "cpe:/o:%s:%s:%s", id, id, version_id );
+ }
- if( os != NULL ) free( os );
- if( version != NULL ) free( version );
+ if( id != NULL ) free( id );
+ if( version_id != NULL ) free( version_id );
+ if( cpe_name != NULL ) free( cpe_name );
#elif defined( __FreeBSD__ )
/* resort to uname */