Changeset View
Changeset View
Standalone View
Standalone View
ksysguardd/Linux/ProcessList.c
Show First 20 Lines • Show All 190 Lines • ▼ Show 20 Line(s) | 111 | typedef struct { | |||
---|---|---|---|---|---|
191 | char userName[ 32 ]; | 191 | char userName[ 32 ]; | ||
192 | 192 | | |||
193 | /** NoNewPrivileges: task can't gain higher privileges via setuid etc. */ | 193 | /** NoNewPrivileges: task can't gain higher privileges via setuid etc. */ | ||
194 | int noNewPrivileges; | 194 | int noNewPrivileges; | ||
195 | 195 | | |||
196 | /** cgroup: Linux process control group */ | 196 | /** cgroup: Linux process control group */ | ||
197 | char *cGroup; | 197 | char *cGroup; | ||
198 | 198 | | |||
199 | /** SELinux context */ | ||||
200 | char *seLinuxContext; | ||||
201 | | ||||
199 | } ProcessInfo; | 202 | } ProcessInfo; | ||
200 | 203 | | |||
201 | void getIOnice( int pid, ProcessInfo *ps ); | 204 | void getIOnice( int pid, ProcessInfo *ps ); | ||
202 | void ioniceProcess( const char* cmd ); | 205 | void ioniceProcess( const char* cmd ); | ||
203 | 206 | | |||
204 | static unsigned ProcessCount; | 207 | static unsigned ProcessCount; | ||
205 | static DIR* procDir; | 208 | static DIR* procDir; | ||
206 | static void validateStr( char* str ) | 209 | static void validateStr( char* str ) | ||
▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Line(s) | 416 | if ( ( fd = fopen( buf, "r" ) ) != 0 ) { | |||
418 | 421 | | |||
419 | if ( buf[0] == '0' && buf[1] == ':' && buf[2] == ':' ) { | 422 | if ( buf[0] == '0' && buf[1] == ':' && buf[2] == ':' ) { | ||
420 | while (buf[strlen(buf) - 1] == '\n') | 423 | while (buf[strlen(buf) - 1] == '\n') | ||
421 | buf[strlen(buf) - 1] = '\0'; /* trim trailing newlines */ | 424 | buf[strlen(buf) - 1] = '\0'; /* trim trailing newlines */ | ||
422 | ps->cGroup = strdup( &buf[3] ); | 425 | ps->cGroup = strdup( &buf[3] ); | ||
423 | } | 426 | } | ||
424 | } | 427 | } | ||
425 | 428 | | |||
429 | /* SELinux context */ | ||||
430 | snprintf( buf, BUFSIZE - 1, "/proc/%d/attr/current", pid ); | ||||
431 | buf[ BUFSIZE - 1 ] = '\0'; | ||||
432 | ps->seLinuxContext = NULL; | ||||
433 | if ( ( fd = fopen( buf, "r" ) ) != 0 ) { | ||||
434 | if (fgets( buf, BUFSIZE, fd )) | ||||
435 | ps->seLinuxContext = strdup( buf ); | ||||
436 | fclose ( fd ); | ||||
437 | } | ||||
438 | | ||||
426 | return true; | 439 | return true; | ||
427 | } | 440 | } | ||
428 | 441 | | |||
429 | void printProcessList( const char* cmd) | 442 | void printProcessList( const char* cmd) | ||
430 | { | 443 | { | ||
431 | (void)cmd; | 444 | (void)cmd; | ||
432 | struct dirent* entry; | 445 | struct dirent* entry; | ||
433 | 446 | | |||
434 | ProcessInfo ps; | 447 | ProcessInfo ps; | ||
435 | ProcessCount = 0; | 448 | ProcessCount = 0; | ||
436 | rewinddir(procDir); | 449 | rewinddir(procDir); | ||
437 | while ( ( entry = readdir( procDir ) ) ) { | 450 | while ( ( entry = readdir( procDir ) ) ) { | ||
438 | if ( isdigit( entry->d_name[ 0 ] ) ) { | 451 | if ( isdigit( entry->d_name[ 0 ] ) ) { | ||
439 | long pid; | 452 | long pid; | ||
440 | pid = atol( entry->d_name ); | 453 | pid = atol( entry->d_name ); | ||
441 | if(getProcess( pid, &ps )) /* Print out the details of the process. Because of a stupid bug in kde3 ksysguard, make sure cmdline and tty are not empty */ | 454 | if(getProcess( pid, &ps )) /* Print out the details of the process. Because of a stupid bug in kde3 ksysguard, make sure cmdline and tty are not empty */ | ||
442 | output( "%s\t%ld\t%ld\t%lu\t%lu\t%s\t%lu\t%lu\t%d\t%lu\t%lu\t%lu\t%s\t%ld\t%s\t%s\t%d\t%d\t%d\t%s\n", | 455 | output( "%s\t%ld\t%ld\t%lu\t%lu\t%s\t%lu\t%lu\t%d\t%lu\t%lu\t%lu\t%s\t%ld\t%s\t%s\t%d\t%d\t%d\t%s\t%s\n", | ||
443 | ps.name, pid, (long)ps.ppid, | 456 | ps.name, pid, (long)ps.ppid, | ||
444 | (long)ps.uid, (long)ps.gid, ps.status, ps.userTime, | 457 | (long)ps.uid, (long)ps.gid, ps.status, ps.userTime, | ||
445 | ps.sysTime, ps.niceLevel, ps.vmSize, ps.vmRss, ps.vmURss, | 458 | ps.sysTime, ps.niceLevel, ps.vmSize, ps.vmRss, ps.vmURss, | ||
446 | (ps.userName[0]==0)?" ":ps.userName, (long)ps.tracerpid, | 459 | (ps.userName[0]==0)?" ":ps.userName, (long)ps.tracerpid, | ||
447 | (ps.tty[0]==0)?" ":ps.tty, (ps.cmdline[0]==0)?" ":ps.cmdline, | 460 | (ps.tty[0]==0)?" ":ps.tty, (ps.cmdline[0]==0)?" ":ps.cmdline, | ||
448 | ps.ioPriorityClass, ps.ioPriority, ps.noNewPrivileges, ps.cGroup | 461 | ps.ioPriorityClass, ps.ioPriority, ps.noNewPrivileges, ps.cGroup, (ps.seLinuxContext?ps.seLinuxContext:" ") | ||
449 | ); | 462 | ); | ||
450 | free( ps.cGroup ); | 463 | free( ps.cGroup ); | ||
464 | free( ps.seLinuxContext ); | ||||
451 | } | 465 | } | ||
452 | } | 466 | } | ||
453 | output( "\n" ); | 467 | output( "\n" ); | ||
454 | return; | 468 | return; | ||
455 | } | 469 | } | ||
456 | 470 | | |||
457 | void getIOnice( int pid, ProcessInfo *ps ) { | 471 | void getIOnice( int pid, ProcessInfo *ps ) { | ||
458 | #ifdef HAVE_IONICE | 472 | #ifdef HAVE_IONICE | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 517 | { | |||
512 | 526 | | |||
513 | exitPWUIDCache(); | 527 | exitPWUIDCache(); | ||
514 | } | 528 | } | ||
515 | 529 | | |||
516 | void printProcessListInfo( const char* cmd ) | 530 | void printProcessListInfo( const char* cmd ) | ||
517 | { | 531 | { | ||
518 | (void)cmd; | 532 | (void)cmd; | ||
519 | output( "Name\tPID\tPPID\tUID\tGID\tStatus\tUser Time\tSystem Time\tNice\tVmSize" | 533 | output( "Name\tPID\tPPID\tUID\tGID\tStatus\tUser Time\tSystem Time\tNice\tVmSize" | ||
520 | "\tVmRss\tVmURss\tLogin\tTracerPID\tTTY\tCommand\tIO Priority Class\tIO Priority\tNNP\tCGroup\n" ); | 534 | "\tVmRss\tVmURss\tLogin\tTracerPID\tTTY\tCommand\tIO Priority Class\tIO Priority\tNNP\tCGroup\tSELinux Context\n" ); | ||
521 | output( "s\td\td\td\td\tS\td\td\td\tD\tD\tD\ts\td\ts\ts\td\td\td\ts\n" ); | 535 | output( "s\td\td\td\td\tS\td\td\td\tD\tD\tD\ts\td\ts\ts\td\td\td\ts\ts\n" ); | ||
522 | } | 536 | } | ||
523 | 537 | | |||
524 | void printProcessCount( const char* cmd ) | 538 | void printProcessCount( const char* cmd ) | ||
525 | { | 539 | { | ||
526 | (void)cmd; | 540 | (void)cmd; | ||
527 | struct dirent* entry; | 541 | struct dirent* entry; | ||
528 | ProcessCount = 0; | 542 | ProcessCount = 0; | ||
529 | rewinddir(procDir); | 543 | rewinddir(procDir); | ||
▲ Show 20 Lines • Show All 179 Lines • Show Last 20 Lines |