From 4aca87515a5083ae0e31ce3177189fd43b6d05ac Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 3 Jan 2015 13:58:15 +0100 Subject: patch to Vanilla Tomato 1.28 --- release/src/router/busybox/procps/pidof.c | 115 +++++++++++++++++------------- 1 file changed, 65 insertions(+), 50 deletions(-) (limited to 'release/src/router/busybox/procps/pidof.c') diff --git a/release/src/router/busybox/procps/pidof.c b/release/src/router/busybox/procps/pidof.c index 2fe8ecd2..19423996 100644 --- a/release/src/router/busybox/procps/pidof.c +++ b/release/src/router/busybox/procps/pidof.c @@ -2,70 +2,85 @@ /* * pidof implementation for busybox * - * Copyright (C) 1999-2003 by Erik Andersen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Copyright (C) 1999-2004 by Erik Andersen * + * Licensed under the GPL version 2, see the file LICENSE in this tarball. */ +#include "libbb.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "busybox.h" - +enum { + USE_FEATURE_PIDOF_SINGLE(OPTBIT_SINGLE,) + USE_FEATURE_PIDOF_OMIT( OPTBIT_OMIT ,) + OPT_SINGLE = USE_FEATURE_PIDOF_SINGLE((1< 0) { - switch (opt) { - case 's': - single_flag = 1; + /* do unconditional option parsing */ + opt = getopt32(argv, "" + USE_FEATURE_PIDOF_SINGLE ("s") + USE_FEATURE_PIDOF_OMIT("o:", &omits)); + +#if ENABLE_FEATURE_PIDOF_OMIT + /* fill omit list. */ + { + llist_t *omits_p = omits; + while (1) { + omits_p = llist_find_str(omits_p, "%PPID"); + if (!omits_p) break; - default: - bb_show_usage(); + /* are we asked to exclude the parent's process ID? */ + omits_p->data = utoa((unsigned)getppid()); } } +#endif + /* Looks like everything is set to go. */ + argv += optind; + while (*argv) { + pid_t *pidList; + pid_t *pl; - /* Looks like everything is set to go. */ - while(optind < argc) { - long *pidList; - long *pl; - - pidList = find_pid_by_name(argv[optind]); - for(pl = pidList; *pl > 0; pl++) { - printf("%s%ld", (n++ ? " " : ""), *pl); - fail = 0; - if (single_flag) + /* reverse the pidlist like GNU pidof does. */ + pidList = pidlist_reverse(find_pid_by_name(*argv)); + for (pl = pidList; *pl; pl++) { +#if ENABLE_FEATURE_PIDOF_OMIT + if (opt & OPT_OMIT) { + llist_t *omits_p = omits; + while (omits_p) { + if (xatoul(omits_p->data) == (unsigned long)(*pl)) { + goto omitting; + } + omits_p = omits_p->link; + } + } +#endif + printf(" %u" + first, (unsigned)*pl); + first = 0; + if (ENABLE_FEATURE_PIDOF_SINGLE && (opt & OPT_SINGLE)) break; +#if ENABLE_FEATURE_PIDOF_OMIT + omitting: ; +#endif } free(pidList); - optind++; - + argv++; } - printf("\n"); + if (!first) + bb_putchar('\n'); - return fail ? EXIT_FAILURE : EXIT_SUCCESS; +#if ENABLE_FEATURE_PIDOF_OMIT + if (ENABLE_FEATURE_CLEAN_UP) + llist_free(omits, NULL); +#endif + return first; /* 1 (failure) - no processes found */ } -- cgit v1.2.3-54-g00ecf