diff options
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/find_pid_by_name.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c index a22ee1ff8..ea1cba65b 100644 --- a/libbb/find_pid_by_name.c +++ b/libbb/find_pid_by_name.c | |||
| @@ -32,6 +32,8 @@ | |||
| 32 | #include <stdlib.h> | 32 | #include <stdlib.h> |
| 33 | #include "libbb.h" | 33 | #include "libbb.h" |
| 34 | 34 | ||
| 35 | #define READ_BUF_SIZE 50 | ||
| 36 | |||
| 35 | 37 | ||
| 36 | /* For Erik's nifty devps device driver */ | 38 | /* For Erik's nifty devps device driver */ |
| 37 | #ifdef BB_FEATURE_USE_DEVPS_PATCH | 39 | #ifdef BB_FEATURE_USE_DEVPS_PATCH |
| @@ -131,22 +133,27 @@ extern pid_t* find_pid_by_name( char* pidName) | |||
| 131 | 133 | ||
| 132 | while ((next = readdir(dir)) != NULL) { | 134 | while ((next = readdir(dir)) != NULL) { |
| 133 | FILE *status; | 135 | FILE *status; |
| 134 | char filename[256]; | 136 | char filename[READ_BUF_SIZE]; |
| 135 | char buffer[256]; | 137 | char buffer[READ_BUF_SIZE]; |
| 138 | char name[READ_BUF_SIZE]; | ||
| 136 | 139 | ||
| 137 | /* If it isn't a number, we don't want it */ | 140 | /* If it isn't a number, we don't want it */ |
| 138 | if (!isdigit(*next->d_name)) | 141 | if (!isdigit(*next->d_name)) |
| 139 | continue; | 142 | continue; |
| 140 | 143 | ||
| 141 | sprintf(filename, "/proc/%s/cmdline", next->d_name); | 144 | sprintf(filename, "/proc/%s/status", next->d_name); |
| 142 | status = fopen(filename, "r"); | 145 | if (! (status = fopen(filename, "r")) ) { |
| 143 | if (!status) { | 146 | continue; |
| 147 | } | ||
| 148 | if (fgets(buffer, READ_BUF_SIZE-1, status) == NULL) { | ||
| 149 | fclose(status); | ||
| 144 | continue; | 150 | continue; |
| 145 | } | 151 | } |
| 146 | fgets(buffer, 256, status); | ||
| 147 | fclose(status); | 152 | fclose(status); |
| 148 | 153 | ||
| 149 | if (strstr(get_last_path_component(buffer), pidName) != NULL) { | 154 | /* Buffer should contain a string like "Name: binary_name" */ |
| 155 | sscanf(buffer, "%*s %s", name); | ||
| 156 | if (strcmp(name, pidName) == 0) { | ||
| 150 | pidList=xrealloc( pidList, sizeof(pid_t) * (i+2)); | 157 | pidList=xrealloc( pidList, sizeof(pid_t) * (i+2)); |
| 151 | pidList[i++]=strtol(next->d_name, NULL, 0); | 158 | pidList[i++]=strtol(next->d_name, NULL, 0); |
| 152 | } | 159 | } |
