From 57e0fbaf580fb875b849e2644961960f0912bee3 Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Wed, 6 May 2020 17:14:36 +0200 Subject: [PATCH] debug --- main.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) 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);