aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
Diffstat (limited to 'toys')
-rw-r--r--toys/lsb/killall.c2
-rw-r--r--toys/lsb/pidof.c5
-rw-r--r--toys/pending/bootchartd.c38
3 files changed, 16 insertions, 29 deletions
diff --git a/toys/lsb/killall.c b/toys/lsb/killall.c
index 47aea23d..c81360b1 100644
--- a/toys/lsb/killall.c
+++ b/toys/lsb/killall.c
@@ -89,7 +89,7 @@ void killall_main(void)
TT.err = xmalloc(2*toys.optc);
for (i=0; i<toys.optc; i++) TT.err[i] = ESRCH;
- names_to_pid(TT.names, kill_process);
+ names_to_pid(TT.names, kill_process, 1);
for (i=0; i<toys.optc; i++) {
if (TT.err[i]) {
toys.exitval = 1;
diff --git a/toys/lsb/pidof.c b/toys/lsb/pidof.c
index 4f266b84..cd705a7c 100644
--- a/toys/lsb/pidof.c
+++ b/toys/lsb/pidof.c
@@ -5,7 +5,7 @@
*
* http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/pidof.html
-USE_PIDOF(NEWTOY(pidof, "<1so:", TOYFLAG_BIN))
+USE_PIDOF(NEWTOY(pidof, "<1so:x", TOYFLAG_BIN))
config PIDOF
bool "pidof"
@@ -17,6 +17,7 @@ config PIDOF
-s Single shot, only return one pid
-o Omit PID(s)
+ -x Match shell scripts too
*/
#define FOR_pidof
@@ -39,6 +40,6 @@ static int print_pid(pid_t pid, char *name)
void pidof_main(void)
{
toys.exitval = 1;
- names_to_pid(toys.optargs, print_pid);
+ names_to_pid(toys.optargs, print_pid, FLAG(x));
if (!toys.exitval) xputc('\n');
}
diff --git a/toys/pending/bootchartd.c b/toys/pending/bootchartd.c
index 7e5a136f..1fe6aff6 100644
--- a/toys/pending/bootchartd.c
+++ b/toys/pending/bootchartd.c
@@ -34,24 +34,9 @@ GLOBALS(
int proc_accounting;
int is_login;
- void *head;
+ pid_t cur_pid;
)
-struct pid_list {
- struct pid_list *next, *prev;
- int pid;
-};
-
-static int push_pids_in_list(pid_t pid, char *name)
-{
- struct pid_list *new = xzalloc(sizeof(struct pid_list));
-
- new->pid = pid;
- dlist_add_nomalloc((void *)&TT.head, (void *)new);
-
- return 0;
-}
-
static void dump_data_in_file(char *fname, int wfd)
{
int rfd = open(fname, O_RDONLY);
@@ -253,13 +238,21 @@ static void stop_logging(char *tmp_dir, char *prog)
}
}
+static int signal_pid(pid_t pid, char *name)
+{
+ if (pid != TT.cur_pid) kill(pid, SIGUSR1);
+ return 0;
+}
+
void bootchartd_main()
{
- pid_t lgr_pid, self_pid = getpid();
+ pid_t lgr_pid;
int bchartd_opt = 0; // 0=PID1, 1=start, 2=stop, 3=init
+
+ TT.cur_pid = getpid();
TT.smpl_period_usec = 200 * 1000;
- TT.is_login = (self_pid == 1);
+ TT.is_login = (TT.cur_pid == 1);
if (*toys.optargs) {
if (!strcmp("start", *toys.optargs)) bchartd_opt = 1;
else if (!strcmp("stop", *toys.optargs)) bchartd_opt = 2;
@@ -267,16 +260,9 @@ void bootchartd_main()
else error_exit("Unknown option '%s'", *toys.optargs);
if (bchartd_opt == 2) {
- struct pid_list *temp;
char *process_name[] = {"bootchartd", NULL};
- names_to_pid(process_name, push_pids_in_list);
- temp = TT.head;
- if (temp) temp->prev->next = 0;
- for (; temp; temp = temp->next)
- if (temp->pid != self_pid) kill(temp->pid, SIGUSR1);
- llist_traverse(TT.head, free);
-
+ names_to_pid(process_name, signal_pid, 0);
return;
}
} else if (!TT.is_login) error_exit("not PID 1");