diff --git a/main.c b/main.c index 859eb6a..a966d5f 100644 --- a/main.c +++ b/main.c @@ -20,6 +20,28 @@ int isinarray( int pid, int array[], int n ) return 0; } +int null2space( char str[] ) +{ + int flag =0; + int x = 0; + + while ( flag == 0 ) + { + if ( (int) str[x] == 0 ) + { + if ( (int) str[x+1] != 0 ) + { + str[x] = ' '; + }else + { + flag = 1; + } + } + x++; + } + return x-1 ; +} + int getpids(int pid, int exploded[]) { FILE *fh; @@ -92,20 +114,7 @@ int getprocinfo( int ppid, char cmdline[], char cmd[], char user[] ) } fgets( str, 1024, fh1); flag = 0; - while ( flag == 0 ) - { - if ( (int) str[x] == 0 ) - { - if ( (int) str[x+1] != 0 ) - { - str[x] = ' '; - }else - { - flag = 1; - } - } - x++; - } + null2space( str ); sprintf(cmdline, "%s", str); fclose(fh1); sprintf( child_path, "/proc/%d/comm", pid ); @@ -123,6 +132,7 @@ int getprocinfo( int ppid, char cmdline[], char cmd[], char user[] ) return 5; } fgets( str, 1024, fh1); + null2space( str ); pos = strstr( str, "USER="); sprintf( user, "%s", pos+5); fclose(fh1);