Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/debianutils/run_parts.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/debianutils/run_parts.c
r3232 r3621 22 22 * report mode. As the original run-parts support only long options, I've 23 23 * broken compatibility because the BusyBox policy doesn't allow them. 24 * The supported options are:25 * -t test. Print the name of the files to be executed, without26 * execute them.27 * -a ARG argument. Pass ARG as an argument the program executed. It can28 * be repeated to pass multiple arguments.29 * -u MASK umask. Set the umask of the program executed to MASK.30 24 */ 25 //config:config RUN_PARTS 26 //config: bool "run-parts" 27 //config: default y 28 //config: help 29 //config: run-parts is a utility designed to run all the scripts in a directory. 30 //config: 31 //config: It is useful to set up a directory like cron.daily, where you need to 32 //config: execute all the scripts in that directory. 33 //config: 34 //config: In this implementation of run-parts some features (such as report 35 //config: mode) are not implemented. 36 //config: 37 //config: Unless you know that run-parts is used in some of your scripts 38 //config: you can safely say N here. 39 //config: 40 //config:config FEATURE_RUN_PARTS_LONG_OPTIONS 41 //config: bool "Enable long options" 42 //config: default y 43 //config: depends on RUN_PARTS && LONG_OPTS 44 //config: help 45 //config: Support long options for the run-parts applet. 46 //config: 47 //config:config FEATURE_RUN_PARTS_FANCY 48 //config: bool "Support additional arguments" 49 //config: default y 50 //config: depends on RUN_PARTS 51 //config: help 52 //config: Support additional options: 53 //config: -l --list print the names of the all matching files (not 54 //config: limited to executables), but don't actually run them. 55 56 //applet:IF_RUN_PARTS(APPLET_ODDNAME(run-parts, run_parts, BB_DIR_BIN, BB_SUID_DROP, run_parts)) 57 58 //kbuild:lib-$(CONFIG_RUN_PARTS) += run_parts.o 31 59 32 60 //usage:#define run_parts_trivial_usage 33 //usage: "[-t"IF_FEATURE_RUN_PARTS_FANCY("l")"] [-a ARG]... [-u MASK] DIRECTORY" 61 //usage: "[-a ARG]... [-u UMASK] " 62 //usage: IF_FEATURE_RUN_PARTS_LONG_OPTIONS("[--reverse] [--test] [--exit-on-error] "IF_FEATURE_RUN_PARTS_FANCY("[--list] ")) 63 //usage: "DIRECTORY" 34 64 //usage:#define run_parts_full_usage "\n\n" 35 65 //usage: "Run a bunch of scripts in DIRECTORY\n" 36 //usage: "\n -t Dry run" 66 //usage: "\n -a ARG Pass ARG as argument to scripts" 67 //usage: "\n -u UMASK Set UMASK before running scripts" 68 //usage: IF_FEATURE_RUN_PARTS_LONG_OPTIONS( 69 //usage: "\n --reverse Reverse execution order" 70 //usage: "\n --test Dry run" 71 //usage: "\n --exit-on-error Exit if a script exits with non-zero" 37 72 //usage: IF_FEATURE_RUN_PARTS_FANCY( 38 //usage: "\n - lPrint names of matching files even if they are not executable"73 //usage: "\n --list Print names of matching files even if they are not executable" 39 74 //usage: ) 40 //usage: "\n -a ARG Pass ARG as argument to programs" 41 //usage: "\n -u MASK Set umask to MASK before running programs" 75 //usage: ) 42 76 //usage: 43 77 //usage:#define run_parts_example_usage … … 56 90 57 91 #include "libbb.h" 92 #include "common_bufsiz.h" 58 93 59 94 struct globals { 60 95 char **names; 61 96 int cur; 62 char *cmd[ 1];97 char *cmd[2 /* using 1 provokes compiler warning */]; 63 98 } FIX_ALIASING; 64 #define G (*(struct globals*) &bb_common_bufsiz1)99 #define G (*(struct globals*)bb_common_bufsiz1) 65 100 #define names (G.names) 66 101 #define cur (G.cur ) 67 102 #define cmd (G.cmd ) 68 #define INIT_G() do { } while (0)103 #define INIT_G() do { setup_common_bufsiz(); } while (0) 69 104 70 105 enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(G)) / sizeof(cmd[0]) - 1 }; 71 106 72 107 enum { 73 OPT_r = (1 << 0), 74 OPT_a = (1 << 1), 75 OPT_u = (1 << 2), 76 OPT_t = (1 << 3), 77 OPT_l = (1 << 4) * ENABLE_FEATURE_RUN_PARTS_FANCY, 108 OPT_a = (1 << 0), 109 OPT_u = (1 << 1), 110 OPT_r = (1 << 2) * ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS, 111 OPT_t = (1 << 3) * ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS, 112 OPT_e = (1 << 4) * ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS, 113 OPT_l = (1 << 5) * ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS 114 * ENABLE_FEATURE_RUN_PARTS_FANCY, 78 115 }; 79 80 #if ENABLE_FEATURE_RUN_PARTS_FANCY81 #define list_mode (option_mask32 & OPT_l)82 #else83 #define list_mode 084 #endif85 116 86 117 /* Is this a valid filename (upper/lower alpha, digits, … … 111 142 && ( !(statbuf->st_mode & (S_IFREG | S_IFLNK)) 112 143 || invalid_name(file) 113 || (! list_mode&& access(file, X_OK) != 0))144 || (!(option_mask32 & OPT_l) && access(file, X_OK) != 0)) 114 145 ) { 115 146 return SKIP; … … 127 158 "arg\0" Required_argument "a" 128 159 "umask\0" Required_argument "u" 129 "test\0" No_argument "t" 160 //TODO: "verbose\0" No_argument "v" 161 "reverse\0" No_argument "\xf0" 162 "test\0" No_argument "\xf1" 163 "exit-on-error\0" No_argument "\xf2" 130 164 #if ENABLE_FEATURE_RUN_PARTS_FANCY 131 "list\0" No_argument "l" 132 "reverse\0" No_argument "r" 133 //TODO: "verbose\0" No_argument "v" 165 "list\0" No_argument "\xf3" 134 166 #endif 135 167 ; … … 151 183 /* We require exactly one argument: the directory name */ 152 184 opt_complementary = "=1:a::"; 153 getopt32(argv, " ra:u:t"IF_FEATURE_RUN_PARTS_FANCY("l"), &arg_list, &umask_p);185 getopt32(argv, "a:u:", &arg_list, &umask_p); 154 186 155 187 umask(xstrtou_range(umask_p, 8, 0, 07777)); … … 193 225 bb_perror_msg("can't execute '%s'", name); 194 226 else /* ret > 0 */ 195 bb_error_msg("%s exited with code %d", name, ret & 0xff); 227 bb_error_msg("%s: exit status %u", name, ret & 0xff); 228 229 if (option_mask32 & OPT_e) 230 xfunc_die(); 196 231 } 197 232
Note:
See TracChangeset
for help on using the changeset viewer.