Patch to make killall actually kill all PIDs with the specified name,
rather then busylooping trying to kill the first one until it dies. Should be more efficient now, and will only send one signal to each specified process. -Erik
This commit is contained in:
parent
93d6513d93
commit
825aead68b
@ -3097,7 +3097,7 @@ local void set_file_type()
|
|||||||
bin_freq += dyn_ltree[n++].Freq;
|
bin_freq += dyn_ltree[n++].Freq;
|
||||||
*file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
|
*file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
|
||||||
if (*file_type == BINARY && translate_eol) {
|
if (*file_type == BINARY && translate_eol) {
|
||||||
errorMsg("-l used on binary file", "");
|
errorMsg("-l used on binary file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
gzip.c
2
gzip.c
@ -3097,7 +3097,7 @@ local void set_file_type()
|
|||||||
bin_freq += dyn_ltree[n++].Freq;
|
bin_freq += dyn_ltree[n++].Freq;
|
||||||
*file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
|
*file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
|
||||||
if (*file_type == BINARY && translate_eol) {
|
if (*file_type == BINARY && translate_eol) {
|
||||||
errorMsg("-l used on binary file", "");
|
errorMsg("-l used on binary file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
halt.c
2
halt.c
@ -28,7 +28,7 @@ extern int halt_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
#ifdef BB_FEATURE_LINUXRC
|
#ifdef BB_FEATURE_LINUXRC
|
||||||
/* don't assume init's pid == 1 */
|
/* don't assume init's pid == 1 */
|
||||||
exit(kill(findPidByName("init"), SIGUSR1));
|
exit(kill(*(findPidByName("init")), SIGUSR1));
|
||||||
#else
|
#else
|
||||||
exit(kill(1, SIGUSR1));
|
exit(kill(1, SIGUSR1));
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,7 +28,7 @@ extern int halt_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
#ifdef BB_FEATURE_LINUXRC
|
#ifdef BB_FEATURE_LINUXRC
|
||||||
/* don't assume init's pid == 1 */
|
/* don't assume init's pid == 1 */
|
||||||
exit(kill(findPidByName("init"), SIGUSR1));
|
exit(kill(*(findPidByName("init")), SIGUSR1));
|
||||||
#else
|
#else
|
||||||
exit(kill(1, SIGUSR1));
|
exit(kill(1, SIGUSR1));
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,7 +28,7 @@ extern int poweroff_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
#ifdef BB_FEATURE_LINUXRC
|
#ifdef BB_FEATURE_LINUXRC
|
||||||
/* don't assume init's pid == 1 */
|
/* don't assume init's pid == 1 */
|
||||||
exit(kill(findPidByName("init"), SIGUSR2));
|
exit(kill(*(findPidByName("init")), SIGUSR2));
|
||||||
#else
|
#else
|
||||||
exit(kill(1, SIGUSR2));
|
exit(kill(1, SIGUSR2));
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,7 +28,7 @@ extern int reboot_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
#ifdef BB_FEATURE_LINUXRC
|
#ifdef BB_FEATURE_LINUXRC
|
||||||
/* don't assume init's pid == 1 */
|
/* don't assume init's pid == 1 */
|
||||||
exit(kill(findPidByName("init"), SIGINT));
|
exit(kill(*(findPidByName("init")), SIGINT));
|
||||||
#else
|
#else
|
||||||
exit(kill(1, SIGINT));
|
exit(kill(1, SIGINT));
|
||||||
#endif
|
#endif
|
||||||
|
@ -216,7 +216,7 @@ extern char *mtab_next(void **iter);
|
|||||||
extern char *mtab_getinfo(const char *match, const char which);
|
extern char *mtab_getinfo(const char *match, const char which);
|
||||||
extern int check_wildcard_match(const char* text, const char* pattern);
|
extern int check_wildcard_match(const char* text, const char* pattern);
|
||||||
extern long getNum (const char *cp);
|
extern long getNum (const char *cp);
|
||||||
extern pid_t findPidByName( char* pidName);
|
extern pid_t* findPidByName( char* pidName);
|
||||||
extern void *xmalloc (size_t size);
|
extern void *xmalloc (size_t size);
|
||||||
extern int find_real_root_device_name(char* name);
|
extern int find_real_root_device_name(char* name);
|
||||||
|
|
||||||
|
14
kill.c
14
kill.c
@ -224,12 +224,18 @@ extern int kill_main(int argc, char **argv)
|
|||||||
else {
|
else {
|
||||||
/* Looks like they want to do a killall. Do that */
|
/* Looks like they want to do a killall. Do that */
|
||||||
while (--argc >= 0) {
|
while (--argc >= 0) {
|
||||||
int pid;
|
pid_t* pidList;
|
||||||
|
|
||||||
while((pid = findPidByName( *argv))) {
|
pidList = findPidByName( *argv);
|
||||||
if (kill(pid, sig) != 0)
|
for(; pidList && pidList!=0; pidList++) {
|
||||||
fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
|
if (kill(*pidList, sig) != 0)
|
||||||
|
fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
|
||||||
|
else
|
||||||
|
errorMsg( "killed pid '%d'\n", *pidList);
|
||||||
}
|
}
|
||||||
|
/* Note that we don't bother to free the memory
|
||||||
|
* allocated in findPidByName(). It will be freed
|
||||||
|
* upon exit, so we can save a byte or two */
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ extern int poweroff_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
#ifdef BB_FEATURE_LINUXRC
|
#ifdef BB_FEATURE_LINUXRC
|
||||||
/* don't assume init's pid == 1 */
|
/* don't assume init's pid == 1 */
|
||||||
exit(kill(findPidByName("init"), SIGUSR2));
|
exit(kill(*(findPidByName("init")), SIGUSR2));
|
||||||
#else
|
#else
|
||||||
exit(kill(1, SIGUSR2));
|
exit(kill(1, SIGUSR2));
|
||||||
#endif
|
#endif
|
||||||
|
@ -224,12 +224,18 @@ extern int kill_main(int argc, char **argv)
|
|||||||
else {
|
else {
|
||||||
/* Looks like they want to do a killall. Do that */
|
/* Looks like they want to do a killall. Do that */
|
||||||
while (--argc >= 0) {
|
while (--argc >= 0) {
|
||||||
int pid;
|
pid_t* pidList;
|
||||||
|
|
||||||
while((pid = findPidByName( *argv))) {
|
pidList = findPidByName( *argv);
|
||||||
if (kill(pid, sig) != 0)
|
for(; pidList && pidList!=0; pidList++) {
|
||||||
fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
|
if (kill(*pidList, sig) != 0)
|
||||||
|
fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
|
||||||
|
else
|
||||||
|
errorMsg( "killed pid '%d'\n", *pidList);
|
||||||
}
|
}
|
||||||
|
/* Note that we don't bother to free the memory
|
||||||
|
* allocated in findPidByName(). It will be freed
|
||||||
|
* upon exit, so we can save a byte or two */
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
reboot.c
2
reboot.c
@ -28,7 +28,7 @@ extern int reboot_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
#ifdef BB_FEATURE_LINUXRC
|
#ifdef BB_FEATURE_LINUXRC
|
||||||
/* don't assume init's pid == 1 */
|
/* don't assume init's pid == 1 */
|
||||||
exit(kill(findPidByName("init"), SIGINT));
|
exit(kill(*(findPidByName("init")), SIGINT));
|
||||||
#else
|
#else
|
||||||
exit(kill(1, SIGINT));
|
exit(kill(1, SIGINT));
|
||||||
#endif
|
#endif
|
||||||
|
39
utility.c
39
utility.c
@ -1259,17 +1259,15 @@ extern int device_open(char *device, int mode)
|
|||||||
* This finds the pid of the specified process,
|
* This finds the pid of the specified process,
|
||||||
* by using the /dev/ps device driver.
|
* by using the /dev/ps device driver.
|
||||||
*
|
*
|
||||||
* [return]
|
* Returns a list of all matching PIDs
|
||||||
* 0 failure
|
|
||||||
* pid when the pid is found.
|
|
||||||
*/
|
*/
|
||||||
extern pid_t findPidByName( char* pidName)
|
extern pid_t* findPidByName( char* pidName)
|
||||||
{
|
{
|
||||||
int fd, i;
|
int fd, i, j;
|
||||||
char device[] = "/dev/ps";
|
char device[] = "/dev/ps";
|
||||||
pid_t thePid = 0;
|
|
||||||
pid_t num_pids;
|
pid_t num_pids;
|
||||||
pid_t* pid_array = NULL;
|
pid_t* pid_array = NULL;
|
||||||
|
pid_t* pidList=NULL;
|
||||||
|
|
||||||
/* open device */
|
/* open device */
|
||||||
fd = open(device, O_RDONLY);
|
fd = open(device, O_RDONLY);
|
||||||
@ -1300,10 +1298,13 @@ extern pid_t findPidByName( char* pidName)
|
|||||||
fatalError( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno));
|
fatalError( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno));
|
||||||
|
|
||||||
if ((strstr(info.command_line, pidName) != NULL)) {
|
if ((strstr(info.command_line, pidName) != NULL)) {
|
||||||
thePid = info.pid;
|
pidList=realloc( pidList, sizeof(pid_t) * (j+2));
|
||||||
break;
|
if (pidList==NULL)
|
||||||
|
fatalError("out of memory\n");
|
||||||
|
pidList[j++]=info.pid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pidList[j]=0;
|
||||||
|
|
||||||
/* Free memory */
|
/* Free memory */
|
||||||
free( pid_array);
|
free( pid_array);
|
||||||
@ -1312,7 +1313,7 @@ extern pid_t findPidByName( char* pidName)
|
|||||||
if (close (fd) != 0)
|
if (close (fd) != 0)
|
||||||
fatalError( "close failed for `%s': %s\n",device, strerror (errno));
|
fatalError( "close failed for `%s': %s\n",device, strerror (errno));
|
||||||
|
|
||||||
return thePid;
|
return pidList;
|
||||||
}
|
}
|
||||||
#else /* BB_FEATURE_USE_DEVPS_PATCH */
|
#else /* BB_FEATURE_USE_DEVPS_PATCH */
|
||||||
#if ! defined BB_FEATURE_USE_PROCFS
|
#if ! defined BB_FEATURE_USE_PROCFS
|
||||||
@ -1325,14 +1326,14 @@ extern pid_t findPidByName( char* pidName)
|
|||||||
* Currently, it's implemented by rummaging through
|
* Currently, it's implemented by rummaging through
|
||||||
* the proc filesystem.
|
* the proc filesystem.
|
||||||
*
|
*
|
||||||
* [return]
|
* Returns a list of all matching PIDs
|
||||||
* 0 failure
|
|
||||||
* pid when the pid is found.
|
|
||||||
*/
|
*/
|
||||||
extern pid_t findPidByName( char* pidName)
|
extern pid_t* findPidByName( char* pidName)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *next;
|
struct dirent *next;
|
||||||
|
pid_t* pidList=NULL;
|
||||||
|
int i=0;
|
||||||
|
|
||||||
dir = opendir("/proc");
|
dir = opendir("/proc");
|
||||||
if (!dir)
|
if (!dir)
|
||||||
@ -1347,7 +1348,7 @@ extern pid_t findPidByName( char* pidName)
|
|||||||
if (!isdigit(*next->d_name))
|
if (!isdigit(*next->d_name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Now open the command line file */
|
/* Now open the status file */
|
||||||
sprintf(filename, "/proc/%s/status", next->d_name);
|
sprintf(filename, "/proc/%s/status", next->d_name);
|
||||||
status = fopen(filename, "r");
|
status = fopen(filename, "r");
|
||||||
if (!status) {
|
if (!status) {
|
||||||
@ -1357,10 +1358,14 @@ extern pid_t findPidByName( char* pidName)
|
|||||||
fclose(status);
|
fclose(status);
|
||||||
|
|
||||||
if ((strstr(buffer, pidName) != NULL)) {
|
if ((strstr(buffer, pidName) != NULL)) {
|
||||||
return strtol(next->d_name, NULL, 0);
|
pidList=realloc( pidList, sizeof(pid_t) * (i+2));
|
||||||
|
if (pidList==NULL)
|
||||||
|
fatalError("out of memory\n");
|
||||||
|
pidList[i++]=strtol(next->d_name, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
pidList[i]=0;
|
||||||
|
return pidList;
|
||||||
}
|
}
|
||||||
#endif /* BB_FEATURE_USE_DEVPS_PATCH */
|
#endif /* BB_FEATURE_USE_DEVPS_PATCH */
|
||||||
#endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */
|
#endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */
|
||||||
@ -1371,7 +1376,7 @@ extern void *xmalloc(size_t size)
|
|||||||
void *cp = malloc(size);
|
void *cp = malloc(size);
|
||||||
|
|
||||||
if (cp == NULL)
|
if (cp == NULL)
|
||||||
fatalError("out of memory");
|
fatalError("out of memory\n");
|
||||||
return cp;
|
return cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user