diff options
| author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-09-14 21:12:20 +0000 |
|---|---|---|
| committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-09-14 21:12:20 +0000 |
| commit | fe7a20b973c4717df06a1437ec0012f1f3ccfcfe (patch) | |
| tree | 7dab593e927d4234f70b2dd84afcb5afa86e9744 | |
| parent | e368f738675c86eb17afcab60f2ae0c02d8a4fe1 (diff) | |
| download | busybox-w32-fe7a20b973c4717df06a1437ec0012f1f3ccfcfe.tar.gz busybox-w32-fe7a20b973c4717df06a1437ec0012f1f3ccfcfe.tar.bz2 busybox-w32-fe7a20b973c4717df06a1437ec0012f1f3ccfcfe.zip | |
Fix the halt/reboot/poweroff segfault when used from within an initrd...
-Erik
git-svn-id: svn://busybox.net/trunk/busybox@1049 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | utility.c | 18 |
1 files changed, 3 insertions, 15 deletions
| @@ -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; |
