diff --git a/ksysguardd/CMakeLists.txt b/ksysguardd/CMakeLists.txt --- a/ksysguardd/CMakeLists.txt +++ b/ksysguardd/CMakeLists.txt @@ -45,7 +45,7 @@ PWUIDCache.c ) add_executable(ksysguardd ${ksysguardd_SRCS}) - + set_property(TARGET ksysguardd PROPERTY C_STANDARD 11) target_link_libraries(ksysguardd libksysguardd) if( ${CMAKE_SYSTEM_NAME} MATCHES "NetBSD" ) diff --git a/ksysguardd/Command.c b/ksysguardd/Command.c --- a/ksysguardd/Command.c +++ b/ksysguardd/Command.c @@ -51,12 +51,10 @@ { if ( v ) { Command* c = v; - if ( c->command ) - free ( c->command ); - if ( c->type ) - free ( c->type ); - free ( v ); + free ( c->command ); + free ( c->type ); } + free ( v ); } /* @@ -152,8 +150,7 @@ if ( cmd->command && strcmp( cmd->command, command ) == 0 ) { remove_ctnr( CommandList ); free( cmd->command ); - if ( cmd->type ) - free( cmd->type ); + free( cmd->type ); free( cmd ); } } diff --git a/ksysguardd/PWUIDCache.c b/ksysguardd/PWUIDCache.c --- a/ksysguardd/PWUIDCache.c +++ b/ksysguardd/PWUIDCache.c @@ -51,13 +51,11 @@ void PWUIDCache_cleanup( void* c ) { - if ( c ) { - if ( ((CachedPWUID*)c)->uName ) - free ( ((CachedPWUID*)c)->uName ); - free ( c ); - } + if ( c ) + free ( ((CachedPWUID*)c)->uName ); + free ( c ); } - + void initPWUIDCache() { UIDCache = new_ctnr(); @@ -100,10 +98,7 @@ entry->uid = uid; pwent = getpwuid( uid ); - if ( pwent ) - entry->uName = strdup( pwent->pw_name ); - else - entry->uName = strdup( "?" ); + entry->uName = strdup( pwent ? pwent->pw_name : "?" ); push_ctnr( UIDCache, entry ); bsort_ctnr( UIDCache, uidCmp ); diff --git a/ksysguardd/conf.c b/ksysguardd/conf.c --- a/ksysguardd/conf.c +++ b/ksysguardd/conf.c @@ -38,11 +38,9 @@ void LogFileList_cleanup( void *ptr ) { if ( ptr ) { - if ( ((ConfigLogFile*)ptr)->name ) free( ((ConfigLogFile*)ptr)->name ); - - free( ptr ); } + free( ptr ); } void freeConfigFile( void ) diff --git a/ksysguardd/ksysguardd.c b/ksysguardd/ksysguardd.c --- a/ksysguardd/ksysguardd.c +++ b/ksysguardd/ksysguardd.c @@ -268,9 +268,7 @@ void resetClientList( void ) { - int i; - - for ( i = 0; i < MAX_CLIENTS; i++ ) { + for (int i = 0; i < MAX_CLIENTS; i++ ) { ClientList[ i ].socket = -1; ClientList[ i ].out = 0; } @@ -281,10 +279,9 @@ */ int addClient( int client ) { - int i; FILE* out; - for ( i = 0; i < MAX_CLIENTS; i++ ) { + for (int i = 0; i < MAX_CLIENTS; i++ ) { if ( ClientList[ i ].socket == -1 ) { ClientList[ i ].socket = client; if ( ( out = fdopen( client, "w+" ) ) == NULL ) { @@ -310,9 +307,7 @@ */ int delClient( int client ) { - int i; - - for ( i = 0; i < MAX_CLIENTS; i++ ) { + for (int i = 0; i < MAX_CLIENTS; i++ ) { if ( ClientList[i].socket == client ) { fclose( ClientList[ i ].out ); ClientList[ i ].out = 0; @@ -356,10 +351,7 @@ memset( &s_in, 0, sizeof( struct sockaddr_in ) ); s_in.sin_family = AF_INET; - if ( BindToAllInterfaces ) - s_in.sin_addr.s_addr = htonl( INADDR_ANY ); - else - s_in.sin_addr.s_addr = htonl( INADDR_LOOPBACK ); + s_in.sin_addr.s_addr = htonl( BindToAllInterfaces ? INADDR_ANY : INADDR_LOOPBACK ); s_in.sin_port = htons( SocketPort ); if ( bind( newSocket, (struct sockaddr*)&s_in, sizeof( s_in ) ) < 0 ) { @@ -417,8 +409,6 @@ char cmdBuf[ CMDBUFSIZE ]; if ( RunAsDaemon ) { - int i; - if ( FD_ISSET( socketNo, fds ) ) { int clientsocket; struct sockaddr addr; @@ -432,7 +422,7 @@ addClient( clientsocket ); } - for ( i = 0; i < MAX_CLIENTS; i++ ) { + for (int i = 0; i < MAX_CLIENTS; i++ ) { if ( ClientList[ i ].socket != -1 ) { CurrentSocket = ClientList[ i ].socket; if ( FD_ISSET( ClientList[ i ].socket, fds ) ) {