mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
6b06cb80be
Some are fixing real bugs. function old new delta syslogd_main 938 958 +20 get_signum 136 143 +7 obj_load 777 782 +5 recv_from_to 210 214 +4 get_next_block 1795 1799 +4 display_topmem_process_list 1117 1121 +4 logread_main 484 487 +3 buffer_fill_and_print 73 76 +3 kill_main 687 689 +2 ll_remember_index 240 241 +1 do_stats 452 453 +1 if_readconf 166 165 -1 display_process_list 1192 1191 -1 run_applet_and_exit 507 505 -2 print_signames 33 31 -2 parse_one_line 1092 1090 -2 find_out_spec 57 55 -2 add_ksymoops_symbols 421 419 -2 ash_main 1407 1402 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 11/8 up/down: 54/-17) Total: 37 bytes
89 lines
2.1 KiB
C
89 lines
2.1 KiB
C
/* vi: set sw=4 ts=4: */
|
|
/*
|
|
* pidof implementation for busybox
|
|
*
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
|
*
|
|
* Licensed under the GPL version 2, see the file LICENSE in this tarball.
|
|
*/
|
|
|
|
#include "libbb.h"
|
|
|
|
enum {
|
|
USE_FEATURE_PIDOF_SINGLE(OPTBIT_SINGLE,)
|
|
USE_FEATURE_PIDOF_OMIT( OPTBIT_OMIT ,)
|
|
OPT_SINGLE = USE_FEATURE_PIDOF_SINGLE((1<<OPTBIT_SINGLE)) + 0,
|
|
OPT_OMIT = USE_FEATURE_PIDOF_OMIT( (1<<OPTBIT_OMIT )) + 0,
|
|
};
|
|
|
|
int pidof_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
int pidof_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
|
{
|
|
unsigned first = 1;
|
|
unsigned opt;
|
|
#if ENABLE_FEATURE_PIDOF_OMIT
|
|
char ppid_str[sizeof(int)*3 + 1];
|
|
llist_t *omits = NULL; /* list of pids to omit */
|
|
opt_complementary = "o::";
|
|
#endif
|
|
|
|
/* 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 (omits_p) {
|
|
/* are we asked to exclude the parent's process ID? */
|
|
if (strcmp(omits_p->data, "%PPID") == 0) {
|
|
sprintf(ppid_str, "%u", (unsigned)getppid());
|
|
omits_p->data = ppid_str;
|
|
}
|
|
omits_p = omits_p->link;
|
|
}
|
|
}
|
|
#endif
|
|
/* Looks like everything is set to go. */
|
|
argv += optind;
|
|
while (*argv) {
|
|
pid_t *pidList;
|
|
pid_t *pl;
|
|
|
|
/* 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);
|
|
argv++;
|
|
}
|
|
if (!first)
|
|
bb_putchar('\n');
|
|
|
|
#if ENABLE_FEATURE_PIDOF_OMIT
|
|
if (ENABLE_FEATURE_CLEAN_UP)
|
|
llist_free(omits, NULL);
|
|
#endif
|
|
return first; /* 1 (failure) - no processes found */
|
|
}
|