aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-09-03 18:43:32 -0500
committerRob Landley <rob@landley.net>2013-09-03 18:43:32 -0500
commit7d64dae54bde70744a9154b8ac1cbb09d03881c9 (patch)
tree1ee92b4e0254f07b71e1d51227ede4116db7b51c /toys
parentb7ca39c9473ecc3f5fbb71e2c9e40ad99b79e03e (diff)
downloadtoybox-7d64dae54bde70744a9154b8ac1cbb09d03881c9.tar.gz
Replace for_each_pid_with_name_in_array_perform_callback_function_upon_translated_value() with name_to_pid(), comparing absolute paths or just basename() consistently as spotted by Lukasz Skalski, and adjust callers.
Diffstat (limited to 'toys')
-rw-r--r--toys/lsb/killall.c15
-rw-r--r--toys/lsb/pidof.c4
2 files changed, 9 insertions, 10 deletions
diff --git a/toys/lsb/killall.c b/toys/lsb/killall.c
index fe433282..59151d8b 100644
--- a/toys/lsb/killall.c
+++ b/toys/lsb/killall.c
@@ -32,21 +32,20 @@ static int kill_process(pid_t pid, char *name)
{
int ret;
- if (pid == TT.cur_pid) return 1;
+ if (pid == TT.cur_pid) return 0;
if (toys.optflags & FLAG_i) {
sprintf(toybuf, "Signal %s(%d) ?", name, pid);
- if (yesno(toybuf, 0) == 0) return 1;
+ if (yesno(toybuf, 0) == 0) return 0;
}
- toys.exitval = 0;
-
ret = kill(pid, TT.signum);
- if (toys.optflags & FLAG_v)
+ if (ret == -1 && !(toys.optflags & FLAG_q))
+ error_msg("bad %u", (unsigned)pid);
+ else if (toys.optflags & FLAG_v)
printf("Killed %s(%d) with signal %d\n", name, pid, TT.signum);
- if (ret == -1 && !(toys.optflags & FLAG_q)) perror("kill");
- return 1;
+ return 0;
}
void killall_main(void)
@@ -76,7 +75,7 @@ void killall_main(void)
TT.cur_pid = getpid();
- for_each_pid_with_name_in(names, kill_process);
+ names_to_pid(names, kill_process);
if (toys.exitval && !(toys.optflags & FLAG_q)) error_exit("No such process");
}
diff --git a/toys/lsb/pidof.c b/toys/lsb/pidof.c
index 7285b6ae..70582a51 100644
--- a/toys/lsb/pidof.c
+++ b/toys/lsb/pidof.c
@@ -43,12 +43,12 @@ static int print_pid(pid_t pid, char * name)
xprintf("%*s", len+(!toys.exitval), toybuf);
toys.exitval = 0;
- return !(toys.optflags & FLAG_s);
+ return toys.optflags & FLAG_s;
}
void pidof_main(void)
{
toys.exitval = 1;
- for_each_pid_with_name_in(toys.optargs, print_pid);
+ name_to_pid(toys.optargs, print_pid);
if (!toys.exitval) xputc('\n');
}