summaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
authorEric Andersen2000-09-14 21:12:20 +0000
committerEric Andersen2000-09-14 21:12:20 +0000
commit31e6829bd8661711b8f5ec3d8b4fb7cb6a512ca9 (patch)
tree7dab593e927d4234f70b2dd84afcb5afa86e9744 /utility.c
parent131241f71cbb6e0dd997fc1f65a6a4f3c8b9d625 (diff)
downloadbusybox-31e6829bd8661711b8f5ec3d8b4fb7cb6a512ca9.zip
busybox-31e6829bd8661711b8f5ec3d8b4fb7cb6a512ca9.tar.gz
Fix the halt/reboot/poweroff segfault when used from within an initrd...
-Erik
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c18
1 files changed, 3 insertions, 15 deletions
diff --git a/utility.c b/utility.c
index 4defbfc..8c3c5e5 100644
--- a/utility.c
+++ b/utility.c
@@ -1360,14 +1360,12 @@ extern pid_t* findPidByName( char* pidName)
FILE *status;
char filename[256];
char buffer[256];
- char* p;
/* If it isn't a number, we don't want it */
if (!isdigit(*next->d_name))
continue;
- /* Now open the status file */
- sprintf(filename, "/proc/%s/status", next->d_name);
+ sprintf(filename, "/proc/%s/cmdline", next->d_name);
status = fopen(filename, "r");
if (!status) {
continue;
@@ -1375,22 +1373,12 @@ extern pid_t* findPidByName( char* pidName)
fgets(buffer, 256, status);
fclose(status);
- /* 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 ((strstr(p, pidName) != NULL)
- && (strlen(pidName) == strlen(p))) {
+ if (strstr(get_last_path_component(buffer), pidName) != NULL) {
pidList=xrealloc( pidList, sizeof(pid_t) * (i+2));
pidList[i++]=strtol(next->d_name, NULL, 0);
}
}
+
if (pidList)
pidList[i]=0;
return pidList;