source: MondoRescue/branches/2.2.9/mindi-busybox/procps/pidof.c@ 2725

Last change on this file since 2725 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 2.0 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
2/*
3 * pidof implementation for busybox
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
[2725]7 * Licensed under GPLv2, see file LICENSE in this source tree.
[821]8 */
9
[1765]10#include "libbb.h"
[821]11
[1765]12enum {
[2725]13 IF_FEATURE_PIDOF_SINGLE(OPTBIT_SINGLE,)
14 IF_FEATURE_PIDOF_OMIT( OPTBIT_OMIT ,)
15 OPT_SINGLE = IF_FEATURE_PIDOF_SINGLE((1<<OPTBIT_SINGLE)) + 0,
16 OPT_OMIT = IF_FEATURE_PIDOF_OMIT( (1<<OPTBIT_OMIT )) + 0,
[1765]17};
[821]18
[2725]19int pidof_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
20int pidof_main(int argc UNUSED_PARAM, char **argv)
[821]21{
[1765]22 unsigned first = 1;
23 unsigned opt;
[821]24#if ENABLE_FEATURE_PIDOF_OMIT
25 llist_t *omits = NULL; /* list of pids to omit */
[1765]26 opt_complementary = "o::";
[821]27#endif
28
29 /* do unconditional option parsing */
[1765]30 opt = getopt32(argv, ""
[2725]31 IF_FEATURE_PIDOF_SINGLE ("s")
32 IF_FEATURE_PIDOF_OMIT("o:", &omits));
[821]33
34#if ENABLE_FEATURE_PIDOF_OMIT
35 /* fill omit list. */
36 {
[1765]37 llist_t *omits_p = omits;
[2725]38 while (1) {
39 omits_p = llist_find_str(omits_p, "%PPID");
40 if (!omits_p)
41 break;
[821]42 /* are we asked to exclude the parent's process ID? */
[2725]43 omits_p->data = utoa((unsigned)getppid());
[821]44 }
45 }
46#endif
47 /* Looks like everything is set to go. */
[2725]48 argv += optind;
49 while (*argv) {
[1765]50 pid_t *pidList;
51 pid_t *pl;
[821]52
53 /* reverse the pidlist like GNU pidof does. */
[2725]54 pidList = pidlist_reverse(find_pid_by_name(*argv));
[1765]55 for (pl = pidList; *pl; pl++) {
[821]56#if ENABLE_FEATURE_PIDOF_OMIT
[1765]57 if (opt & OPT_OMIT) {
[821]58 llist_t *omits_p = omits;
[1765]59 while (omits_p) {
[2725]60 if (xatoul(omits_p->data) == (unsigned long)(*pl)) {
[1765]61 goto omitting;
62 }
63 omits_p = omits_p->link;
64 }
[821]65 }
66#endif
[1765]67 printf(" %u" + first, (unsigned)*pl);
68 first = 0;
69 if (ENABLE_FEATURE_PIDOF_SINGLE && (opt & OPT_SINGLE))
[821]70 break;
[1765]71#if ENABLE_FEATURE_PIDOF_OMIT
72 omitting: ;
73#endif
[821]74 }
75 free(pidList);
[2725]76 argv++;
[821]77 }
[2725]78 if (!first)
79 bb_putchar('\n');
[821]80
81#if ENABLE_FEATURE_PIDOF_OMIT
82 if (ENABLE_FEATURE_CLEAN_UP)
83 llist_free(omits, NULL);
84#endif
[1765]85 return first; /* 1 (failure) - no processes found */
[821]86}
Note: See TracBrowser for help on using the repository browser.