From 7c6209d6c336df74984e62aa88679c06641ae309 Mon Sep 17 00:00:00 2001 From: Elie De Brauwer Date: Sat, 8 Dec 2012 20:10:05 +0100 Subject: Adding -s (single shot) and -o (omit pids) options to pidof --- lib/lib.c | 7 ++++--- lib/lib.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/lib.c b/lib/lib.c index f452bf3c..148a7652 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -975,7 +975,7 @@ int yesno(char *prompt, int def) } // Execute a callback for each PID that matches a process name from a list. -void for_each_pid_with_name_in(char **names, void (*callback)(pid_t pid)) +void for_each_pid_with_name_in(char **names, int (*callback)(pid_t pid)) { DIR *dp; struct dirent *entry; @@ -998,9 +998,10 @@ void for_each_pid_with_name_in(char **names, void (*callback)(pid_t pid)) if (n<1) continue; for (curname = names; *curname; curname++) - if (!strcmp(basename(cmd), *curname)) callback(atol(entry->d_name)); + if (!strcmp(basename(cmd), *curname)) + if (!callback(atol(entry->d_name))) goto done; } - +done: closedir(dp); } diff --git a/lib/lib.h b/lib/lib.h index 1c0350e0..7cc4d5ca 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -144,7 +144,7 @@ void replace_tempfile(int fdin, int fdout, char **tempname); void crc_init(unsigned int *crc_table, int little_endian); void terminal_size(unsigned *x, unsigned *y); int yesno(char *prompt, int def); -void for_each_pid_with_name_in(char **names, void (*callback)(pid_t pid)); +void for_each_pid_with_name_in(char **names, int (*callback)(pid_t pid)); unsigned long xstrtoul(const char *nptr, char **endptr, int base); // getmountlist.c -- cgit v1.2.3