aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-09-14 21:12:20 +0000
committerEric Andersen <andersen@codepoet.org>2000-09-14 21:12:20 +0000
commit31e6829bd8661711b8f5ec3d8b4fb7cb6a512ca9 (patch)
tree7dab593e927d4234f70b2dd84afcb5afa86e9744
parent131241f71cbb6e0dd997fc1f65a6a4f3c8b9d625 (diff)
downloadbusybox-w32-31e6829bd8661711b8f5ec3d8b4fb7cb6a512ca9.tar.gz
busybox-w32-31e6829bd8661711b8f5ec3d8b4fb7cb6a512ca9.tar.bz2
busybox-w32-31e6829bd8661711b8f5ec3d8b4fb7cb6a512ca9.zip
Fix the halt/reboot/poweroff segfault when used from within an initrd...
-Erik
-rw-r--r--utility.c18
1 files changed, 3 insertions, 15 deletions
diff --git a/utility.c b/utility.c
index 4defbfc81..8c3c5e5fa 100644
--- a/utility.c
+++ b/utility.c
@@ -1360,14 +1360,12 @@ extern pid_t* findPidByName( char* pidName)
1360 FILE *status; 1360 FILE *status;
1361 char filename[256]; 1361 char filename[256];
1362 char buffer[256]; 1362 char buffer[256];
1363 char* p;
1364 1363
1365 /* If it isn't a number, we don't want it */ 1364 /* If it isn't a number, we don't want it */
1366 if (!isdigit(*next->d_name)) 1365 if (!isdigit(*next->d_name))
1367 continue; 1366 continue;
1368 1367
1369 /* Now open the status file */ 1368 sprintf(filename, "/proc/%s/cmdline", next->d_name);
1370 sprintf(filename, "/proc/%s/status", next->d_name);
1371 status = fopen(filename, "r"); 1369 status = fopen(filename, "r");
1372 if (!status) { 1370 if (!status) {
1373 continue; 1371 continue;
@@ -1375,22 +1373,12 @@ extern pid_t* findPidByName( char* pidName)
1375 fgets(buffer, 256, status); 1373 fgets(buffer, 256, status);
1376 fclose(status); 1374 fclose(status);
1377 1375
1378 /* Make sure we only match on the process name */ 1376 if (strstr(get_last_path_component(buffer), pidName) != NULL) {
1379 p=buffer+5; /* Skip the name */
1380 while ((p)++) {
1381 if (*p==0 || *p=='\n') {
1382 *p='\0';
1383 break;
1384 }
1385 }
1386 p=buffer+6; /* Skip the "Name:\t" */
1387
1388 if ((strstr(p, pidName) != NULL)
1389 && (strlen(pidName) == strlen(p))) {
1390 pidList=xrealloc( pidList, sizeof(pid_t) * (i+2)); 1377 pidList=xrealloc( pidList, sizeof(pid_t) * (i+2));
1391 pidList[i++]=strtol(next->d_name, NULL, 0); 1378 pidList[i++]=strtol(next->d_name, NULL, 0);
1392 } 1379 }
1393 } 1380 }
1381
1394 if (pidList) 1382 if (pidList)
1395 pidList[i]=0; 1383 pidList[i]=0;
1396 return pidList; 1384 return pidList;