diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-23 14:56:43 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-23 14:56:43 +0000 |
commit | 198badafd82905c9a2e76eeacb7ce463d8518bda (patch) | |
tree | fcb367654b5c6cafdca09ef189342fc7019095fc /procps | |
parent | 118b81df76be0e372309d76196c8eedf19ac56cd (diff) | |
download | busybox-w32-198badafd82905c9a2e76eeacb7ce463d8518bda.tar.gz busybox-w32-198badafd82905c9a2e76eeacb7ce463d8518bda.tar.bz2 busybox-w32-198badafd82905c9a2e76eeacb7ce463d8518bda.zip |
pidof: size optimizations (-50 bytes)
Diffstat (limited to 'procps')
-rw-r--r-- | procps/pidof.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/procps/pidof.c b/procps/pidof.c index 3541aeee0..01e587cbf 100644 --- a/procps/pidof.c +++ b/procps/pidof.c | |||
@@ -20,9 +20,9 @@ int pidof_main(int argc, char **argv); | |||
20 | int pidof_main(int argc, char **argv) | 20 | int pidof_main(int argc, char **argv) |
21 | { | 21 | { |
22 | unsigned first = 1; | 22 | unsigned first = 1; |
23 | unsigned fail = 1; | ||
24 | unsigned opt; | 23 | unsigned opt; |
25 | #if ENABLE_FEATURE_PIDOF_OMIT | 24 | #if ENABLE_FEATURE_PIDOF_OMIT |
25 | char ppid_str[sizeof(int)*3 + 1]; | ||
26 | llist_t *omits = NULL; /* list of pids to omit */ | 26 | llist_t *omits = NULL; /* list of pids to omit */ |
27 | opt_complementary = "o::"; | 27 | opt_complementary = "o::"; |
28 | #endif | 28 | #endif |
@@ -35,14 +35,12 @@ int pidof_main(int argc, char **argv) | |||
35 | #if ENABLE_FEATURE_PIDOF_OMIT | 35 | #if ENABLE_FEATURE_PIDOF_OMIT |
36 | /* fill omit list. */ | 36 | /* fill omit list. */ |
37 | { | 37 | { |
38 | char getppid_str[sizeof(int)*3 + 1]; | 38 | llist_t *omits_p = omits; |
39 | llist_t * omits_p = omits; | ||
40 | while (omits_p) { | 39 | while (omits_p) { |
41 | /* are we asked to exclude the parent's process ID? */ | 40 | /* are we asked to exclude the parent's process ID? */ |
42 | if (!strncmp(omits_p->data, "%PPID", 5)) { | 41 | if (strcmp(omits_p->data, "%PPID") == 0) { |
43 | llist_pop(&omits_p); | 42 | sprintf(ppid_str, "%u", (unsigned)getppid()); |
44 | snprintf(getppid_str, sizeof(getppid_str), "%u", (unsigned)getppid()); | 43 | omits_p->data = ppid_str; |
45 | llist_add_to(&omits_p, getppid_str); | ||
46 | } | 44 | } |
47 | omits_p = omits_p->link; | 45 | omits_p = omits_p->link; |
48 | } | 46 | } |
@@ -56,27 +54,24 @@ int pidof_main(int argc, char **argv) | |||
56 | /* reverse the pidlist like GNU pidof does. */ | 54 | /* reverse the pidlist like GNU pidof does. */ |
57 | pidList = pidlist_reverse(find_pid_by_name(argv[optind])); | 55 | pidList = pidlist_reverse(find_pid_by_name(argv[optind])); |
58 | for (pl = pidList; *pl; pl++) { | 56 | for (pl = pidList; *pl; pl++) { |
59 | SKIP_FEATURE_PIDOF_OMIT(const) unsigned omitted = 0; | ||
60 | #if ENABLE_FEATURE_PIDOF_OMIT | 57 | #if ENABLE_FEATURE_PIDOF_OMIT |
61 | if (opt & OPT_OMIT) { | 58 | if (opt & OPT_OMIT) { |
62 | llist_t *omits_p = omits; | 59 | llist_t *omits_p = omits; |
63 | while (omits_p) { | 60 | while (omits_p) { |
64 | if (xatoul(omits_p->data) == *pl) { | 61 | if (xatoul(omits_p->data) == *pl) { |
65 | omitted = 1; | 62 | goto omitting; |
66 | break; | 63 | } |
67 | } else | 64 | omits_p = omits_p->link; |
68 | omits_p = omits_p->link; | ||
69 | } | 65 | } |
70 | } | 66 | } |
71 | #endif | 67 | #endif |
72 | if (!omitted) { | 68 | printf(" %u" + first, (unsigned)*pl); |
73 | printf(" %u" + first, (unsigned)*pl); | 69 | first = 0; |
74 | first = 0; | ||
75 | } | ||
76 | fail = (!ENABLE_FEATURE_PIDOF_OMIT && omitted); | ||
77 | |||
78 | if (ENABLE_FEATURE_PIDOF_SINGLE && (opt & OPT_SINGLE)) | 70 | if (ENABLE_FEATURE_PIDOF_SINGLE && (opt & OPT_SINGLE)) |
79 | break; | 71 | break; |
72 | #if ENABLE_FEATURE_PIDOF_OMIT | ||
73 | omitting: ; | ||
74 | #endif | ||
80 | } | 75 | } |
81 | free(pidList); | 76 | free(pidList); |
82 | optind++; | 77 | optind++; |
@@ -87,5 +82,5 @@ int pidof_main(int argc, char **argv) | |||
87 | if (ENABLE_FEATURE_CLEAN_UP) | 82 | if (ENABLE_FEATURE_CLEAN_UP) |
88 | llist_free(omits, NULL); | 83 | llist_free(omits, NULL); |
89 | #endif | 84 | #endif |
90 | return fail ? EXIT_FAILURE : EXIT_SUCCESS; | 85 | return first; /* 1 (failure) - no processes found */ |
91 | } | 86 | } |