diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-28 21:30:22 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-28 21:30:22 +0000 |
commit | 19fb67eee4d69e6b473c784ed95b8c08ccf24b14 (patch) | |
tree | dcd9ce660cab8836d76a1c450744033e0beefdf8 | |
parent | b29028e35102df5dfb27f57c94c3e033740f849b (diff) | |
download | busybox-w32-19fb67eee4d69e6b473c784ed95b8c08ccf24b14.tar.gz busybox-w32-19fb67eee4d69e6b473c784ed95b8c08ccf24b14.tar.bz2 busybox-w32-19fb67eee4d69e6b473c784ed95b8c08ccf24b14.zip |
run-parts: add --reverse
-rw-r--r-- | debianutils/run_parts.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index 338817f8f..20f8b3ab8 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c | |||
@@ -23,11 +23,11 @@ | |||
23 | * report mode. As the original run-parts support only long options, I've | 23 | * report mode. As the original run-parts support only long options, I've |
24 | * broken compatibility because the BusyBox policy doesn't allow them. | 24 | * broken compatibility because the BusyBox policy doesn't allow them. |
25 | * The supported options are: | 25 | * The supported options are: |
26 | * -t test. Print the name of the files to be executed, without | 26 | * -t test. Print the name of the files to be executed, without |
27 | * execute them. | 27 | * execute them. |
28 | * -a ARG argument. Pass ARG as an argument the program executed. It can | 28 | * -a ARG argument. Pass ARG as an argument the program executed. It can |
29 | * be repeated to pass multiple arguments. | 29 | * be repeated to pass multiple arguments. |
30 | * -u MASK umask. Set the umask of the program executed to MASK. | 30 | * -u MASK umask. Set the umask of the program executed to MASK. |
31 | */ | 31 | */ |
32 | 32 | ||
33 | #include <getopt.h> | 33 | #include <getopt.h> |
@@ -47,14 +47,15 @@ struct globals { | |||
47 | enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(struct globals)) / sizeof(cmd[0]) }; | 47 | enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(struct globals)) / sizeof(cmd[0]) }; |
48 | 48 | ||
49 | enum { | 49 | enum { |
50 | RUN_PARTS_OPT_a = (1 << 0), | 50 | OPT_r = (1 << 0), |
51 | RUN_PARTS_OPT_u = (1 << 1), | 51 | OPT_a = (1 << 1), |
52 | RUN_PARTS_OPT_t = (1 << 2), | 52 | OPT_u = (1 << 2), |
53 | RUN_PARTS_OPT_l = (1 << 3) * ENABLE_FEATURE_RUN_PARTS_FANCY, | 53 | OPT_t = (1 << 3), |
54 | OPT_l = (1 << 4) * ENABLE_FEATURE_RUN_PARTS_FANCY, | ||
54 | }; | 55 | }; |
55 | 56 | ||
56 | #if ENABLE_FEATURE_RUN_PARTS_FANCY | 57 | #if ENABLE_FEATURE_RUN_PARTS_FANCY |
57 | #define list_mode (option_mask32 & RUN_PARTS_OPT_l) | 58 | #define list_mode (option_mask32 & OPT_l) |
58 | #else | 59 | #else |
59 | #define list_mode 0 | 60 | #define list_mode 0 |
60 | #endif | 61 | #endif |
@@ -74,7 +75,8 @@ static bool invalid_name(const char *c) | |||
74 | 75 | ||
75 | static int bb_alphasort(const void *p1, const void *p2) | 76 | static int bb_alphasort(const void *p1, const void *p2) |
76 | { | 77 | { |
77 | return strcmp(*(char **) p1, *(char **) p2); | 78 | int r = strcmp(*(char **) p1, *(char **) p2); |
79 | return (option_mask32 & OPT_r) ? -r : r; | ||
78 | } | 80 | } |
79 | 81 | ||
80 | static int act(const char *file, struct stat *statbuf, void *args, int depth) | 82 | static int act(const char *file, struct stat *statbuf, void *args, int depth) |
@@ -104,7 +106,7 @@ static const char runparts_longopts[] ALIGN1 = | |||
104 | "test\0" No_argument "t" | 106 | "test\0" No_argument "t" |
105 | #if ENABLE_FEATURE_RUN_PARTS_FANCY | 107 | #if ENABLE_FEATURE_RUN_PARTS_FANCY |
106 | "list\0" No_argument "l" | 108 | "list\0" No_argument "l" |
107 | //TODO: "reverse\0" No_argument "r" | 109 | "reverse\0" No_argument "r" |
108 | //TODO: "verbose\0" No_argument "v" | 110 | //TODO: "verbose\0" No_argument "v" |
109 | #endif | 111 | #endif |
110 | ; | 112 | ; |
@@ -122,8 +124,9 @@ int run_parts_main(int argc, char **argv) | |||
122 | applet_long_options = runparts_longopts; | 124 | applet_long_options = runparts_longopts; |
123 | #endif | 125 | #endif |
124 | /* We require exactly one argument: the directory name */ | 126 | /* We require exactly one argument: the directory name */ |
127 | /* We require exactly one argument: the directory name */ | ||
125 | opt_complementary = "=1:a::"; | 128 | opt_complementary = "=1:a::"; |
126 | getopt32(argv, "a:u:t"USE_FEATURE_RUN_PARTS_FANCY("l"), &arg_list, &umask_p); | 129 | getopt32(argv, "ra:u:t"USE_FEATURE_RUN_PARTS_FANCY("l"), &arg_list, &umask_p); |
127 | 130 | ||
128 | umask(xstrtou_range(umask_p, 8, 0, 07777)); | 131 | umask(xstrtou_range(umask_p, 8, 0, 07777)); |
129 | 132 | ||
@@ -155,7 +158,7 @@ int run_parts_main(int argc, char **argv) | |||
155 | char *name = *names++; | 158 | char *name = *names++; |
156 | if (!name) | 159 | if (!name) |
157 | break; | 160 | break; |
158 | if (option_mask32 & (RUN_PARTS_OPT_t | RUN_PARTS_OPT_l)) { | 161 | if (option_mask32 & (OPT_t | OPT_l)) { |
159 | puts(name); | 162 | puts(name); |
160 | continue; | 163 | continue; |
161 | } | 164 | } |
@@ -165,9 +168,9 @@ int run_parts_main(int argc, char **argv) | |||
165 | continue; | 168 | continue; |
166 | n = 1; | 169 | n = 1; |
167 | if (ret < 0) | 170 | if (ret < 0) |
168 | bb_perror_msg("failed to exec %s", name); | 171 | bb_perror_msg("can't exec %s", name); |
169 | else /* ret > 0 */ | 172 | else /* ret > 0 */ |
170 | bb_error_msg("%s exited with return code %d", name, ret); | 173 | bb_error_msg("%s exited with code %d", name, ret); |
171 | } | 174 | } |
172 | 175 | ||
173 | return n; | 176 | return n; |