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[ 256 ]; | 197 | char cGroup[ 256 ]; | ||
198 | 198 | | |||
199 | /** Mandatory Access Control (SELinux or AppArmor) context */ | ||||
200 | char macContext[ 256 ]; | ||||
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 | strncpy( ps->cGroup, &buf[3], sizeof( ps->cGroup ) - 1 ); | 423 | strncpy( ps->cGroup, &buf[3], sizeof( ps->cGroup ) - 1 ); | ||
421 | ps->cGroup[ sizeof( ps->cGroup ) - 1 ] = '\0'; | 424 | ps->cGroup[ sizeof( ps->cGroup ) - 1 ] = '\0'; | ||
422 | validateStr( ps->cGroup ); | 425 | validateStr( ps->cGroup ); | ||
423 | } | 426 | } | ||
424 | } | 427 | } | ||
425 | 428 | | |||
429 | /* Mandatory Access Control (SELinux or AppArmor) context */ | ||||
430 | ps->macContext[ 0 ] = '\0'; | ||||
431 | snprintf( buf, BUFSIZE - 1, "/proc/%d/attr/current", pid ); | ||||
432 | if ( ( fd = fopen( buf, "r" ) ) != 0 ) { | ||||
433 | if (fgets( ps->macContext, sizeof( ps->macContext ), fd )) | ||||
434 | validateStr( ps->macContext ); | ||||
435 | fclose ( fd ); | ||||
436 | } | ||||
437 | | ||||
426 | return true; | 438 | return true; | ||
427 | } | 439 | } | ||
428 | 440 | | |||
429 | void printProcessList( const char* cmd) | 441 | void printProcessList( const char* cmd) | ||
430 | { | 442 | { | ||
431 | (void)cmd; | 443 | (void)cmd; | ||
432 | struct dirent* entry; | 444 | struct dirent* entry; | ||
433 | 445 | | |||
434 | ProcessInfo ps; | 446 | ProcessInfo ps; | ||
435 | ProcessCount = 0; | 447 | ProcessCount = 0; | ||
436 | rewinddir(procDir); | 448 | rewinddir(procDir); | ||
437 | while ( ( entry = readdir( procDir ) ) ) { | 449 | while ( ( entry = readdir( procDir ) ) ) { | ||
438 | if ( isdigit( entry->d_name[ 0 ] ) ) { | 450 | if ( isdigit( entry->d_name[ 0 ] ) ) { | ||
439 | long pid; | 451 | long pid; | ||
440 | pid = atol( entry->d_name ); | 452 | 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 */ | 453 | 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", | 454 | 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, | 455 | ps.name, pid, (long)ps.ppid, | ||
444 | (long)ps.uid, (long)ps.gid, ps.status, ps.userTime, | 456 | (long)ps.uid, (long)ps.gid, ps.status, ps.userTime, | ||
445 | ps.sysTime, ps.niceLevel, ps.vmSize, ps.vmRss, ps.vmURss, | 457 | ps.sysTime, ps.niceLevel, ps.vmSize, ps.vmRss, ps.vmURss, | ||
446 | (ps.userName[0]==0)?" ":ps.userName, (long)ps.tracerpid, | 458 | (ps.userName[0]==0)?" ":ps.userName, (long)ps.tracerpid, | ||
447 | (ps.tty[0]==0)?" ":ps.tty, (ps.cmdline[0]==0)?" ":ps.cmdline, | 459 | (ps.tty[0]==0)?" ":ps.tty, (ps.cmdline[0]==0)?" ":ps.cmdline, | ||
448 | ps.ioPriorityClass, ps.ioPriority, ps.noNewPrivileges, ps.cGroup | 460 | ps.ioPriorityClass, ps.ioPriority, ps.noNewPrivileges, ps.cGroup, ps.macContext | ||
449 | ); | 461 | ); | ||
450 | } | 462 | } | ||
451 | } | 463 | } | ||
452 | output( "\n" ); | 464 | output( "\n" ); | ||
453 | return; | 465 | return; | ||
454 | } | 466 | } | ||
455 | 467 | | |||
456 | void getIOnice( int pid, ProcessInfo *ps ) { | 468 | void getIOnice( int pid, ProcessInfo *ps ) { | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | 514 | { | |||
511 | 523 | | |||
512 | exitPWUIDCache(); | 524 | exitPWUIDCache(); | ||
513 | } | 525 | } | ||
514 | 526 | | |||
515 | void printProcessListInfo( const char* cmd ) | 527 | void printProcessListInfo( const char* cmd ) | ||
516 | { | 528 | { | ||
517 | (void)cmd; | 529 | (void)cmd; | ||
518 | output( "Name\tPID\tPPID\tUID\tGID\tStatus\tUser Time\tSystem Time\tNice\tVmSize" | 530 | output( "Name\tPID\tPPID\tUID\tGID\tStatus\tUser Time\tSystem Time\tNice\tVmSize" | ||
519 | "\tVmRss\tVmURss\tLogin\tTracerPID\tTTY\tCommand\tIO Priority Class\tIO Priority\tNNP\tCGroup\n" ); | 531 | "\tVmRss\tVmURss\tLogin\tTracerPID\tTTY\tCommand\tIO Priority Class\tIO Priority\tNNP\tCGroup\tMAC Context\n" ); | ||
520 | output( "s\td\td\td\td\tS\td\td\td\tD\tD\tD\ts\td\ts\ts\td\td\td\ts\n" ); | 532 | output( "s\td\td\td\td\tS\td\td\td\tD\tD\tD\ts\td\ts\ts\td\td\td\ts\ts\n" ); | ||
521 | } | 533 | } | ||
522 | 534 | | |||
523 | void printProcessCount( const char* cmd ) | 535 | void printProcessCount( const char* cmd ) | ||
524 | { | 536 | { | ||
525 | (void)cmd; | 537 | (void)cmd; | ||
526 | struct dirent* entry; | 538 | struct dirent* entry; | ||
527 | ProcessCount = 0; | 539 | ProcessCount = 0; | ||
528 | rewinddir(procDir); | 540 | rewinddir(procDir); | ||
▲ Show 20 Lines • Show All 179 Lines • Show Last 20 Lines |