aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/gzip.c2
-rw-r--r--gzip.c2
-rw-r--r--halt.c2
-rw-r--r--init/halt.c2
-rw-r--r--init/poweroff.c2
-rw-r--r--init/reboot.c2
-rw-r--r--internal.h2
-rw-r--r--kill.c16
-rw-r--r--poweroff.c2
-rw-r--r--procps/kill.c16
-rw-r--r--reboot.c2
-rw-r--r--utility.c39
12 files changed, 53 insertions, 36 deletions
diff --git a/archival/gzip.c b/archival/gzip.c
index e275fa274..0a969d8db 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -3097,7 +3097,7 @@ local void set_file_type()
3097 bin_freq += dyn_ltree[n++].Freq; 3097 bin_freq += dyn_ltree[n++].Freq;
3098 *file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII; 3098 *file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
3099 if (*file_type == BINARY && translate_eol) { 3099 if (*file_type == BINARY && translate_eol) {
3100 errorMsg("-l used on binary file", ""); 3100 errorMsg("-l used on binary file");
3101 } 3101 }
3102} 3102}
3103 3103
diff --git a/gzip.c b/gzip.c
index e275fa274..0a969d8db 100644
--- a/gzip.c
+++ b/gzip.c
@@ -3097,7 +3097,7 @@ local void set_file_type()
3097 bin_freq += dyn_ltree[n++].Freq; 3097 bin_freq += dyn_ltree[n++].Freq;
3098 *file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII; 3098 *file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
3099 if (*file_type == BINARY && translate_eol) { 3099 if (*file_type == BINARY && translate_eol) {
3100 errorMsg("-l used on binary file", ""); 3100 errorMsg("-l used on binary file");
3101 } 3101 }
3102} 3102}
3103 3103
diff --git a/halt.c b/halt.c
index 81d24cf2d..bcd69b952 100644
--- a/halt.c
+++ b/halt.c
@@ -28,7 +28,7 @@ extern int halt_main(int argc, char **argv)
28{ 28{
29#ifdef BB_FEATURE_LINUXRC 29#ifdef BB_FEATURE_LINUXRC
30 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
31 exit(kill(findPidByName("init"), SIGUSR1)); 31 exit(kill(*(findPidByName("init")), SIGUSR1));
32#else 32#else
33 exit(kill(1, SIGUSR1)); 33 exit(kill(1, SIGUSR1));
34#endif 34#endif
diff --git a/init/halt.c b/init/halt.c
index 81d24cf2d..bcd69b952 100644
--- a/init/halt.c
+++ b/init/halt.c
@@ -28,7 +28,7 @@ extern int halt_main(int argc, char **argv)
28{ 28{
29#ifdef BB_FEATURE_LINUXRC 29#ifdef BB_FEATURE_LINUXRC
30 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
31 exit(kill(findPidByName("init"), SIGUSR1)); 31 exit(kill(*(findPidByName("init")), SIGUSR1));
32#else 32#else
33 exit(kill(1, SIGUSR1)); 33 exit(kill(1, SIGUSR1));
34#endif 34#endif
diff --git a/init/poweroff.c b/init/poweroff.c
index 0f23b9562..bc8e67716 100644
--- a/init/poweroff.c
+++ b/init/poweroff.c
@@ -28,7 +28,7 @@ extern int poweroff_main(int argc, char **argv)
28{ 28{
29#ifdef BB_FEATURE_LINUXRC 29#ifdef BB_FEATURE_LINUXRC
30 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
31 exit(kill(findPidByName("init"), SIGUSR2)); 31 exit(kill(*(findPidByName("init")), SIGUSR2));
32#else 32#else
33 exit(kill(1, SIGUSR2)); 33 exit(kill(1, SIGUSR2));
34#endif 34#endif
diff --git a/init/reboot.c b/init/reboot.c
index 2f8b2b4a5..6e1f3d53b 100644
--- a/init/reboot.c
+++ b/init/reboot.c
@@ -28,7 +28,7 @@ extern int reboot_main(int argc, char **argv)
28{ 28{
29#ifdef BB_FEATURE_LINUXRC 29#ifdef BB_FEATURE_LINUXRC
30 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
31 exit(kill(findPidByName("init"), SIGINT)); 31 exit(kill(*(findPidByName("init")), SIGINT));
32#else 32#else
33 exit(kill(1, SIGINT)); 33 exit(kill(1, SIGINT));
34#endif 34#endif
diff --git a/internal.h b/internal.h
index c8c813640..1313f3644 100644
--- a/internal.h
+++ b/internal.h
@@ -216,7 +216,7 @@ extern char *mtab_next(void **iter);
216extern char *mtab_getinfo(const char *match, const char which); 216extern char *mtab_getinfo(const char *match, const char which);
217extern int check_wildcard_match(const char* text, const char* pattern); 217extern int check_wildcard_match(const char* text, const char* pattern);
218extern long getNum (const char *cp); 218extern long getNum (const char *cp);
219extern pid_t findPidByName( char* pidName); 219extern pid_t* findPidByName( char* pidName);
220extern void *xmalloc (size_t size); 220extern void *xmalloc (size_t size);
221extern int find_real_root_device_name(char* name); 221extern int find_real_root_device_name(char* name);
222 222
diff --git a/kill.c b/kill.c
index 260f4a074..c6dc79f65 100644
--- a/kill.c
+++ b/kill.c
@@ -224,12 +224,18 @@ extern int kill_main(int argc, char **argv)
224 else { 224 else {
225 /* Looks like they want to do a killall. Do that */ 225 /* Looks like they want to do a killall. Do that */
226 while (--argc >= 0) { 226 while (--argc >= 0) {
227 int pid; 227 pid_t* pidList;
228 228
229 while((pid = findPidByName( *argv))) { 229 pidList = findPidByName( *argv);
230 if (kill(pid, sig) != 0) 230 for(; pidList && pidList!=0; pidList++) {
231 fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno)); 231 if (kill(*pidList, sig) != 0)
232 fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
233 else
234 errorMsg( "killed pid '%d'\n", *pidList);
232 } 235 }
236 /* Note that we don't bother to free the memory
237 * allocated in findPidByName(). It will be freed
238 * upon exit, so we can save a byte or two */
233 argv++; 239 argv++;
234 } 240 }
235 } 241 }
diff --git a/poweroff.c b/poweroff.c
index 0f23b9562..bc8e67716 100644
--- a/poweroff.c
+++ b/poweroff.c
@@ -28,7 +28,7 @@ extern int poweroff_main(int argc, char **argv)
28{ 28{
29#ifdef BB_FEATURE_LINUXRC 29#ifdef BB_FEATURE_LINUXRC
30 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
31 exit(kill(findPidByName("init"), SIGUSR2)); 31 exit(kill(*(findPidByName("init")), SIGUSR2));
32#else 32#else
33 exit(kill(1, SIGUSR2)); 33 exit(kill(1, SIGUSR2));
34#endif 34#endif
diff --git a/procps/kill.c b/procps/kill.c
index 260f4a074..c6dc79f65 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -224,12 +224,18 @@ extern int kill_main(int argc, char **argv)
224 else { 224 else {
225 /* Looks like they want to do a killall. Do that */ 225 /* Looks like they want to do a killall. Do that */
226 while (--argc >= 0) { 226 while (--argc >= 0) {
227 int pid; 227 pid_t* pidList;
228 228
229 while((pid = findPidByName( *argv))) { 229 pidList = findPidByName( *argv);
230 if (kill(pid, sig) != 0) 230 for(; pidList && pidList!=0; pidList++) {
231 fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno)); 231 if (kill(*pidList, sig) != 0)
232 fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
233 else
234 errorMsg( "killed pid '%d'\n", *pidList);
232 } 235 }
236 /* Note that we don't bother to free the memory
237 * allocated in findPidByName(). It will be freed
238 * upon exit, so we can save a byte or two */
233 argv++; 239 argv++;
234 } 240 }
235 } 241 }
diff --git a/reboot.c b/reboot.c
index 2f8b2b4a5..6e1f3d53b 100644
--- a/reboot.c
+++ b/reboot.c
@@ -28,7 +28,7 @@ extern int reboot_main(int argc, char **argv)
28{ 28{
29#ifdef BB_FEATURE_LINUXRC 29#ifdef BB_FEATURE_LINUXRC
30 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
31 exit(kill(findPidByName("init"), SIGINT)); 31 exit(kill(*(findPidByName("init")), SIGINT));
32#else 32#else
33 exit(kill(1, SIGINT)); 33 exit(kill(1, SIGINT));
34#endif 34#endif
diff --git a/utility.c b/utility.c
index b91da4ce4..c3a102c5e 100644
--- a/utility.c
+++ b/utility.c
@@ -1259,17 +1259,15 @@ extern int device_open(char *device, int mode)
1259 * This finds the pid of the specified process, 1259 * This finds the pid of the specified process,
1260 * by using the /dev/ps device driver. 1260 * by using the /dev/ps device driver.
1261 * 1261 *
1262 * [return] 1262 * Returns a list of all matching PIDs
1263 * 0 failure
1264 * pid when the pid is found.
1265 */ 1263 */
1266extern pid_t findPidByName( char* pidName) 1264extern pid_t* findPidByName( char* pidName)
1267{ 1265{
1268 int fd, i; 1266 int fd, i, j;
1269 char device[] = "/dev/ps"; 1267 char device[] = "/dev/ps";
1270 pid_t thePid = 0;
1271 pid_t num_pids; 1268 pid_t num_pids;
1272 pid_t* pid_array = NULL; 1269 pid_t* pid_array = NULL;
1270 pid_t* pidList=NULL;
1273 1271
1274 /* open device */ 1272 /* open device */
1275 fd = open(device, O_RDONLY); 1273 fd = open(device, O_RDONLY);
@@ -1300,10 +1298,13 @@ extern pid_t findPidByName( char* pidName)
1300 fatalError( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno)); 1298 fatalError( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno));
1301 1299
1302 if ((strstr(info.command_line, pidName) != NULL)) { 1300 if ((strstr(info.command_line, pidName) != NULL)) {
1303 thePid = info.pid; 1301 pidList=realloc( pidList, sizeof(pid_t) * (j+2));
1304 break; 1302 if (pidList==NULL)
1303 fatalError("out of memory\n");
1304 pidList[j++]=info.pid;
1305 } 1305 }
1306 } 1306 }
1307 pidList[j]=0;
1307 1308
1308 /* Free memory */ 1309 /* Free memory */
1309 free( pid_array); 1310 free( pid_array);
@@ -1312,7 +1313,7 @@ extern pid_t findPidByName( char* pidName)
1312 if (close (fd) != 0) 1313 if (close (fd) != 0)
1313 fatalError( "close failed for `%s': %s\n",device, strerror (errno)); 1314 fatalError( "close failed for `%s': %s\n",device, strerror (errno));
1314 1315
1315 return thePid; 1316 return pidList;
1316} 1317}
1317#else /* BB_FEATURE_USE_DEVPS_PATCH */ 1318#else /* BB_FEATURE_USE_DEVPS_PATCH */
1318#if ! defined BB_FEATURE_USE_PROCFS 1319#if ! defined BB_FEATURE_USE_PROCFS
@@ -1325,14 +1326,14 @@ extern pid_t findPidByName( char* pidName)
1325 * Currently, it's implemented by rummaging through 1326 * Currently, it's implemented by rummaging through
1326 * the proc filesystem. 1327 * the proc filesystem.
1327 * 1328 *
1328 * [return] 1329 * Returns a list of all matching PIDs
1329 * 0 failure
1330 * pid when the pid is found.
1331 */ 1330 */
1332extern pid_t findPidByName( char* pidName) 1331extern pid_t* findPidByName( char* pidName)
1333{ 1332{
1334 DIR *dir; 1333 DIR *dir;
1335 struct dirent *next; 1334 struct dirent *next;
1335 pid_t* pidList=NULL;
1336 int i=0;
1336 1337
1337 dir = opendir("/proc"); 1338 dir = opendir("/proc");
1338 if (!dir) 1339 if (!dir)
@@ -1347,7 +1348,7 @@ extern pid_t findPidByName( char* pidName)
1347 if (!isdigit(*next->d_name)) 1348 if (!isdigit(*next->d_name))
1348 continue; 1349 continue;
1349 1350
1350 /* Now open the command line file */ 1351 /* Now open the status file */
1351 sprintf(filename, "/proc/%s/status", next->d_name); 1352 sprintf(filename, "/proc/%s/status", next->d_name);
1352 status = fopen(filename, "r"); 1353 status = fopen(filename, "r");
1353 if (!status) { 1354 if (!status) {
@@ -1357,10 +1358,14 @@ extern pid_t findPidByName( char* pidName)
1357 fclose(status); 1358 fclose(status);
1358 1359
1359 if ((strstr(buffer, pidName) != NULL)) { 1360 if ((strstr(buffer, pidName) != NULL)) {
1360 return strtol(next->d_name, NULL, 0); 1361 pidList=realloc( pidList, sizeof(pid_t) * (i+2));
1362 if (pidList==NULL)
1363 fatalError("out of memory\n");
1364 pidList[i++]=strtol(next->d_name, NULL, 0);
1361 } 1365 }
1362 } 1366 }
1363 return 0; 1367 pidList[i]=0;
1368 return pidList;
1364} 1369}
1365#endif /* BB_FEATURE_USE_DEVPS_PATCH */ 1370#endif /* BB_FEATURE_USE_DEVPS_PATCH */
1366#endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */ 1371#endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */
@@ -1371,7 +1376,7 @@ extern void *xmalloc(size_t size)
1371 void *cp = malloc(size); 1376 void *cp = malloc(size);
1372 1377
1373 if (cp == NULL) 1378 if (cp == NULL)
1374 fatalError("out of memory"); 1379 fatalError("out of memory\n");
1375 return cp; 1380 return cp;
1376} 1381}
1377 1382