From 0a64de9b4f7b3254008affe21b3ad4174c26f7f5 Mon Sep 17 00:00:00 2001 From: Erik Andersen Date: Tue, 18 Apr 2000 20:00:03 +0000 Subject: More little stuff. -Erik --- utility.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'utility.c') diff --git a/utility.c b/utility.c index b844c3b52..29934cdc3 100644 --- a/utility.c +++ b/utility.c @@ -1291,12 +1291,21 @@ extern pid_t* findPidByName( char* pidName) /* Now search for a match */ for (i=1; id_name)) @@ -1358,15 +1368,25 @@ extern pid_t* findPidByName( char* pidName) fgets(buffer, 256, status); fclose(status); - if (((p=strstr(buffer, pidName)) != NULL) - && (strncmp(p, pidName, strlen(pidName)) != 0)) { + /* Make sure we only match on the process name */ + p=buffer+5; /* Skip the name */ + while ((p)++) { + if (*p==0 || *p=='\n') { + *p='\0'; + break; + } + } + p=buffer+6; /* Skip the "Name:\t" */ + + if (((q=strstr(q, pidName)) != NULL) + && (strncmp(q, pidName, strlen(pidName)) != 0)) { pidList=realloc( pidList, sizeof(pid_t) * (i+2)); if (pidList==NULL) fatalError("out of memory\n"); pidList[i++]=strtol(next->d_name, NULL, 0); } } - if (pidList!=NULL) + if (pidList) pidList[i]=0; return pidList; } -- cgit v1.2.3