Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/procps/pidof.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/procps/pidof.c
r1765 r2725 5 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 6 6 * 7 * Licensed under the GPL version 2, see the file LICENSE in this tarball.7 * Licensed under GPLv2, see file LICENSE in this source tree. 8 8 */ 9 9 … … 11 11 12 12 enum { 13 USE_FEATURE_PIDOF_SINGLE(OPTBIT_SINGLE,)14 USE_FEATURE_PIDOF_OMIT( OPTBIT_OMIT ,)15 OPT_SINGLE = USE_FEATURE_PIDOF_SINGLE((1<<OPTBIT_SINGLE)) + 0,16 OPT_OMIT = USE_FEATURE_PIDOF_OMIT( (1<<OPTBIT_OMIT )) + 0,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, 17 17 }; 18 18 19 int pidof_main(int argc, char **argv) ;20 int pidof_main(int argc , char **argv)19 int pidof_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 20 int pidof_main(int argc UNUSED_PARAM, char **argv) 21 21 { 22 22 unsigned first = 1; 23 23 unsigned opt; 24 24 #if ENABLE_FEATURE_PIDOF_OMIT 25 char ppid_str[sizeof(int)*3 + 1];26 25 llist_t *omits = NULL; /* list of pids to omit */ 27 26 opt_complementary = "o::"; … … 30 29 /* do unconditional option parsing */ 31 30 opt = getopt32(argv, "" 32 USE_FEATURE_PIDOF_SINGLE ("s")33 USE_FEATURE_PIDOF_OMIT("o:", &omits));31 IF_FEATURE_PIDOF_SINGLE ("s") 32 IF_FEATURE_PIDOF_OMIT("o:", &omits)); 34 33 35 34 #if ENABLE_FEATURE_PIDOF_OMIT … … 37 36 { 38 37 llist_t *omits_p = omits; 39 while (omits_p) { 38 while (1) { 39 omits_p = llist_find_str(omits_p, "%PPID"); 40 if (!omits_p) 41 break; 40 42 /* are we asked to exclude the parent's process ID? */ 41 if (strcmp(omits_p->data, "%PPID") == 0) { 42 sprintf(ppid_str, "%u", (unsigned)getppid()); 43 omits_p->data = ppid_str; 44 } 45 omits_p = omits_p->link; 43 omits_p->data = utoa((unsigned)getppid()); 46 44 } 47 45 } 48 46 #endif 49 47 /* Looks like everything is set to go. */ 50 while (optind < argc) { 48 argv += optind; 49 while (*argv) { 51 50 pid_t *pidList; 52 51 pid_t *pl; 53 52 54 53 /* reverse the pidlist like GNU pidof does. */ 55 pidList = pidlist_reverse(find_pid_by_name( argv[optind]));54 pidList = pidlist_reverse(find_pid_by_name(*argv)); 56 55 for (pl = pidList; *pl; pl++) { 57 56 #if ENABLE_FEATURE_PIDOF_OMIT … … 59 58 llist_t *omits_p = omits; 60 59 while (omits_p) { 61 if (xatoul(omits_p->data) == *pl) {60 if (xatoul(omits_p->data) == (unsigned long)(*pl)) { 62 61 goto omitting; 63 62 } … … 75 74 } 76 75 free(pidList); 77 optind++;76 argv++; 78 77 } 79 putchar('\n'); 78 if (!first) 79 bb_putchar('\n'); 80 80 81 81 #if ENABLE_FEATURE_PIDOF_OMIT
Note:
See TracChangeset
for help on using the changeset viewer.