diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-25 22:55:34 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-25 22:55:34 +0000 |
commit | 1fc6238ffab2cbd09b9ce573b99d82f3eaeb5b77 (patch) | |
tree | fc7c75badddb78021ae50a64914a27f6b32d0d4f | |
parent | 80b8b39899a09c7516920cda5fd343b3086d4824 (diff) | |
download | busybox-w32-1fc6238ffab2cbd09b9ce573b99d82f3eaeb5b77.tar.gz busybox-w32-1fc6238ffab2cbd09b9ce573b99d82f3eaeb5b77.tar.bz2 busybox-w32-1fc6238ffab2cbd09b9ce573b99d82f3eaeb5b77.zip |
devfsd: fix formatting (Tito <farmatito@tiscali.it>)
ash: fix SEGV if type has zero parameters
-rw-r--r-- | miscutils/devfsd.c | 955 | ||||
-rw-r--r-- | shell/ash.c | 2 |
2 files changed, 447 insertions, 510 deletions
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index ad934a3a4..0aec94232 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c | |||
@@ -158,88 +158,88 @@ struct devfsd_notify_struct | |||
158 | 158 | ||
159 | struct permissions_type | 159 | struct permissions_type |
160 | { | 160 | { |
161 | mode_t mode; | 161 | mode_t mode; |
162 | uid_t uid; | 162 | uid_t uid; |
163 | gid_t gid; | 163 | gid_t gid; |
164 | }; | 164 | }; |
165 | 165 | ||
166 | struct execute_type | 166 | struct execute_type |
167 | { | 167 | { |
168 | char *argv[MAX_ARGS + 1]; /* argv[0] must always be the programme */ | 168 | char *argv[MAX_ARGS + 1]; /* argv[0] must always be the programme */ |
169 | }; | 169 | }; |
170 | 170 | ||
171 | struct copy_type | 171 | struct copy_type |
172 | { | 172 | { |
173 | const char *source; | 173 | const char *source; |
174 | const char *destination; | 174 | const char *destination; |
175 | }; | 175 | }; |
176 | 176 | ||
177 | struct action_type | 177 | struct action_type |
178 | { | 178 | { |
179 | unsigned int what; | 179 | unsigned int what; |
180 | unsigned int when; | 180 | unsigned int when; |
181 | }; | 181 | }; |
182 | 182 | ||
183 | struct config_entry_struct | 183 | struct config_entry_struct |
184 | { | 184 | { |
185 | struct action_type action; | 185 | struct action_type action; |
186 | regex_t preg; | 186 | regex_t preg; |
187 | union | 187 | union |
188 | { | 188 | { |
189 | struct permissions_type permissions; | 189 | struct permissions_type permissions; |
190 | struct execute_type execute; | 190 | struct execute_type execute; |
191 | struct copy_type copy; | 191 | struct copy_type copy; |
192 | } | 192 | } |
193 | u; | 193 | u; |
194 | struct config_entry_struct *next; | 194 | struct config_entry_struct *next; |
195 | }; | 195 | }; |
196 | 196 | ||
197 | struct get_variable_info | 197 | struct get_variable_info |
198 | { | 198 | { |
199 | const struct devfsd_notify_struct *info; | 199 | const struct devfsd_notify_struct *info; |
200 | const char *devname; | 200 | const char *devname; |
201 | char devpath[STRING_LENGTH]; | 201 | char devpath[STRING_LENGTH]; |
202 | }; | 202 | }; |
203 | 203 | ||
204 | static void dir_operation(int , const char * , int, unsigned long* ); | 204 | static void dir_operation(int , const char * , int, unsigned long*); |
205 | static void service(struct stat statbuf, char *path); | 205 | static void service(struct stat statbuf, char *path); |
206 | static int st_expr_expand(char *, unsigned, const char *, const char *(*) (const char *, void *), void *); | 206 | static int st_expr_expand(char *, unsigned, const char *, const char *(*)(const char *, void *), void *); |
207 | static const char *get_old_name(const char *, unsigned, char *, unsigned, unsigned); | 207 | static const char *get_old_name(const char *, unsigned, char *, unsigned, unsigned); |
208 | static int mksymlink (const char *oldpath, const char *newpath); | 208 | static int mksymlink(const char *oldpath, const char *newpath); |
209 | static void read_config_file (char *path, int optional, unsigned long *event_mask); | 209 | static void read_config_file(char *path, int optional, unsigned long *event_mask); |
210 | static void process_config_line (const char *, unsigned long *); | 210 | static void process_config_line(const char *, unsigned long *); |
211 | static int do_servicing (int, unsigned long); | 211 | static int do_servicing(int, unsigned long); |
212 | static void service_name (const struct devfsd_notify_struct *); | 212 | static void service_name(const struct devfsd_notify_struct *); |
213 | static void action_permissions (const struct devfsd_notify_struct *, const struct config_entry_struct *); | 213 | static void action_permissions(const struct devfsd_notify_struct *, const struct config_entry_struct *); |
214 | static void action_execute (const struct devfsd_notify_struct *, const struct config_entry_struct *, | 214 | static void action_execute(const struct devfsd_notify_struct *, const struct config_entry_struct *, |
215 | const regmatch_t *, unsigned); | 215 | const regmatch_t *, unsigned); |
216 | static void action_modload (const struct devfsd_notify_struct *info, const struct config_entry_struct *entry); | 216 | static void action_modload(const struct devfsd_notify_struct *info, const struct config_entry_struct *entry); |
217 | static void action_copy (const struct devfsd_notify_struct *, const struct config_entry_struct *, | 217 | static void action_copy(const struct devfsd_notify_struct *, const struct config_entry_struct *, |
218 | const regmatch_t *, unsigned); | 218 | const regmatch_t *, unsigned); |
219 | static void action_compat (const struct devfsd_notify_struct *, unsigned); | 219 | static void action_compat(const struct devfsd_notify_struct *, unsigned); |
220 | static void free_config (void); | 220 | static void free_config(void); |
221 | static void restore(char *spath, struct stat source_stat, int rootlen); | 221 | static void restore(char *spath, struct stat source_stat, int rootlen); |
222 | static int copy_inode (const char *, const struct stat *, mode_t, const char *, const struct stat *); | 222 | static int copy_inode(const char *, const struct stat *, mode_t, const char *, const struct stat *); |
223 | static mode_t get_mode (const char *); | 223 | static mode_t get_mode(const char *); |
224 | static void signal_handler (int); | 224 | static void signal_handler(int); |
225 | static const char *get_variable (const char *, void *); | 225 | static const char *get_variable(const char *, void *); |
226 | static int make_dir_tree (const char *); | 226 | static int make_dir_tree(const char *); |
227 | static int expand_expression(char *, unsigned, const char *, const char *(*)(const char *, void *), void *, | 227 | static int expand_expression(char *, unsigned, const char *, const char *(*)(const char *, void *), void *, |
228 | const char *, const regmatch_t *, unsigned ); | 228 | const char *, const regmatch_t *, unsigned); |
229 | static void expand_regexp (char *, size_t, const char *, const char *, const regmatch_t *, unsigned ); | 229 | static void expand_regexp(char *, size_t, const char *, const char *, const regmatch_t *, unsigned); |
230 | static const char *expand_variable( char *, unsigned, unsigned *, const char *, | 230 | static const char *expand_variable( char *, unsigned, unsigned *, const char *, |
231 | const char *(*) (const char *, void *), void * ); | 231 | const char *(*)(const char *, void *), void *); |
232 | static const char *get_variable_v2(const char *, const char *(*) (const char *, void *), void *); | 232 | static const char *get_variable_v2(const char *, const char *(*)(const char *, void *), void *); |
233 | static char get_old_ide_name (unsigned , unsigned); | 233 | static char get_old_ide_name(unsigned , unsigned); |
234 | static char *write_old_sd_name (char *, unsigned, unsigned, const char *); | 234 | static char *write_old_sd_name(char *, unsigned, unsigned, const char *); |
235 | 235 | ||
236 | /* busybox functions */ | 236 | /* busybox functions */ |
237 | static void msg_logger(int pri, const char * fmt, ... )__attribute__ ((format (printf, 2, 3))); | 237 | static void msg_logger(int pri, const char * fmt, ...)__attribute__((format(printf, 2, 3))); |
238 | static void msg_logger_and_die(int pri, const char * fmt, ... )__attribute__ ((noreturn, format (printf, 2, 3))); | 238 | static void msg_logger_and_die(int pri, const char * fmt, ...)__attribute__((noreturn, format(printf, 2, 3))); |
239 | static void do_ioctl_and_die(int fd, int request, unsigned long event_mask_flag); | 239 | static void do_ioctl_and_die(int fd, int request, unsigned long event_mask_flag); |
240 | static void fork_and_execute(int die, char *arg0, char **arg ); | 240 | static void fork_and_execute(int die, char *arg0, char **arg); |
241 | static int get_uid_gid ( int, const char *); | 241 | static int get_uid_gid(int, const char *); |
242 | static void safe_memcpy( char * dest, const char * src, int len); | 242 | static void safe_memcpy(char * dest, const char * src, int len); |
243 | static unsigned int scan_dev_name_common(const char *d, unsigned int n, int addendum, char *ptr); | 243 | static unsigned int scan_dev_name_common(const char *d, unsigned int n, int addendum, char *ptr); |
244 | static unsigned int scan_dev_name(const char *d, unsigned int n, char *ptr); | 244 | static unsigned int scan_dev_name(const char *d, unsigned int n, char *ptr); |
245 | 245 | ||
@@ -251,32 +251,32 @@ static volatile int caught_signal = FALSE; | |||
251 | static volatile int caught_sighup = FALSE; | 251 | static volatile int caught_sighup = FALSE; |
252 | static struct initial_symlink_struct | 252 | static struct initial_symlink_struct |
253 | { | 253 | { |
254 | const char *dest; | 254 | const char *dest; |
255 | const char *name; | 255 | const char *name; |
256 | } initial_symlinks[] = | 256 | } initial_symlinks[] = |
257 | { | 257 | { |
258 | {"/proc/self/fd", "fd"}, | 258 | {"/proc/self/fd", "fd"}, |
259 | {"fd/0", "stdin"}, | 259 | {"fd/0", "stdin"}, |
260 | {"fd/1", "stdout"}, | 260 | {"fd/1", "stdout"}, |
261 | {"fd/2", "stderr"}, | 261 | {"fd/2", "stderr"}, |
262 | {NULL, NULL}, | 262 | {NULL, NULL}, |
263 | }; | 263 | }; |
264 | 264 | ||
265 | static struct event_type | 265 | static struct event_type |
266 | { | 266 | { |
267 | unsigned int type; /* The DEVFSD_NOTIFY_* value */ | 267 | unsigned int type; /* The DEVFSD_NOTIFY_* value */ |
268 | const char *config_name; /* The name used in the config file */ | 268 | const char *config_name; /* The name used in the config file */ |
269 | } event_types[] = | 269 | } event_types[] = |
270 | { | 270 | { |
271 | {DEVFSD_NOTIFY_REGISTERED, "REGISTER"}, | 271 | {DEVFSD_NOTIFY_REGISTERED, "REGISTER"}, |
272 | {DEVFSD_NOTIFY_UNREGISTERED, "UNREGISTER"}, | 272 | {DEVFSD_NOTIFY_UNREGISTERED, "UNREGISTER"}, |
273 | {DEVFSD_NOTIFY_ASYNC_OPEN, "ASYNC_OPEN"}, | 273 | {DEVFSD_NOTIFY_ASYNC_OPEN, "ASYNC_OPEN"}, |
274 | {DEVFSD_NOTIFY_CLOSE, "CLOSE"}, | 274 | {DEVFSD_NOTIFY_CLOSE, "CLOSE"}, |
275 | {DEVFSD_NOTIFY_LOOKUP, "LOOKUP"}, | 275 | {DEVFSD_NOTIFY_LOOKUP, "LOOKUP"}, |
276 | {DEVFSD_NOTIFY_CHANGE, "CHANGE"}, | 276 | {DEVFSD_NOTIFY_CHANGE, "CHANGE"}, |
277 | {DEVFSD_NOTIFY_CREATE, "CREATE"}, | 277 | {DEVFSD_NOTIFY_CREATE, "CREATE"}, |
278 | {DEVFSD_NOTIFY_DELETE, "DELETE"}, | 278 | {DEVFSD_NOTIFY_DELETE, "DELETE"}, |
279 | {0xffffffff, NULL} | 279 | {0xffffffff, NULL} |
280 | }; | 280 | }; |
281 | 281 | ||
282 | /* Busybox messages */ | 282 | /* Busybox messages */ |
@@ -287,16 +287,16 @@ static const char * const bb_msg_small_buffer = "buffer too small"; | |||
287 | static const char * const bb_msg_variable_not_found = "variable: %s not found"; | 287 | static const char * const bb_msg_variable_not_found = "variable: %s not found"; |
288 | 288 | ||
289 | /* Busybox functions */ | 289 | /* Busybox functions */ |
290 | static void msg_logger(int pri, const char * fmt, ... ) | 290 | static void msg_logger(int pri, const char * fmt, ...) |
291 | { | 291 | { |
292 | va_list ap; | 292 | va_list ap; |
293 | int ret; | 293 | int ret; |
294 | 294 | ||
295 | va_start(ap, fmt); | 295 | va_start(ap, fmt); |
296 | ret = access ("/dev/log", F_OK); | 296 | ret = access("/dev/log", F_OK); |
297 | if (ret == 0) { | 297 | if (ret == 0) { |
298 | openlog(applet_name, 0, LOG_DAEMON); | 298 | openlog(applet_name, 0, LOG_DAEMON); |
299 | vsyslog( pri , fmt, ap); | 299 | vsyslog(pri , fmt, ap); |
300 | /* Man: A trailing newline is added when needed. */ | 300 | /* Man: A trailing newline is added when needed. */ |
301 | closelog(); | 301 | closelog(); |
302 | } | 302 | } |
@@ -338,84 +338,82 @@ static void msg_logger_and_die(int pri, const char* fmt, ...) | |||
338 | 338 | ||
339 | static void do_ioctl_and_die(int fd, int request, unsigned long event_mask_flag) | 339 | static void do_ioctl_and_die(int fd, int request, unsigned long event_mask_flag) |
340 | { | 340 | { |
341 | if (ioctl (fd, request, event_mask_flag) == -1) | 341 | if (ioctl(fd, request, event_mask_flag) == -1) |
342 | msg_logger_and_die(LOG_ERR, "ioctl"); | 342 | msg_logger_and_die(LOG_ERR, "ioctl"); |
343 | } | 343 | } |
344 | 344 | ||
345 | static void fork_and_execute(int die, char *arg0, char **arg ) | 345 | static void fork_and_execute(int die, char *arg0, char **arg) |
346 | { | 346 | { |
347 | switch ( fork () ) | 347 | switch (fork()) { |
348 | { | 348 | case 0: |
349 | case 0: | 349 | /* Child */ |
350 | /* Child */ | 350 | break; |
351 | break; | 351 | case -1: |
352 | case -1: | 352 | /* Parent: Error : die or return */ |
353 | /* Parent: Error : die or return */ | 353 | msg_logger(LOG_ERR,(char *)bb_msg_memory_exhausted); |
354 | msg_logger(LOG_ERR,(char *) bb_msg_memory_exhausted); | 354 | if (die) |
355 | if(die) | 355 | exit(EXIT_FAILURE); |
356 | exit(EXIT_FAILURE); | ||
357 | return; | ||
358 | default: | ||
359 | /* Parent : ok : return or exit */ | ||
360 | if(arg0 != NULL) | ||
361 | { | ||
362 | wait (NULL); | ||
363 | return; | 356 | return; |
364 | } | 357 | default: |
365 | exit (EXIT_SUCCESS); | 358 | /* Parent : ok : return or exit */ |
359 | if (arg0 != NULL) { | ||
360 | wait(NULL); | ||
361 | return; | ||
362 | } | ||
363 | exit(EXIT_SUCCESS); | ||
366 | } | 364 | } |
367 | /* Child : if arg0 != NULL do execvp */ | 365 | /* Child : if arg0 != NULL do execvp */ |
368 | if(arg0 != NULL ) | 366 | if (arg0 != NULL) { |
369 | { | ||
370 | BB_EXECVP(arg0, arg); | 367 | BB_EXECVP(arg0, arg); |
371 | msg_logger_and_die(LOG_ERR, "execvp"); | 368 | msg_logger_and_die(LOG_ERR, "execvp"); |
372 | } | 369 | } |
373 | } | 370 | } |
374 | 371 | ||
375 | static void safe_memcpy( char *dest, const char *src, int len) | 372 | static void safe_memcpy(char *dest, const char *src, int len) |
376 | { | 373 | { |
377 | memcpy (dest , src , len ); | 374 | memcpy(dest , src, len); |
378 | dest[len] = '\0'; | 375 | dest[len] = '\0'; |
379 | } | 376 | } |
380 | 377 | ||
381 | static unsigned int scan_dev_name_common(const char *d, unsigned int n, int addendum, char *ptr) | 378 | static unsigned int scan_dev_name_common(const char *d, unsigned int n, int addendum, char *ptr) |
382 | { | 379 | { |
383 | if(d[n - 4]=='d' && d[n - 3]=='i' && d[n - 2]=='s' && d[n - 1]=='c') | 380 | if (d[n - 4] == 'd' && d[n - 3] == 'i' && d[n - 2] == 's' && d[n - 1] == 'c') |
384 | return 2 + addendum; | 381 | return 2 + addendum; |
385 | if(d[n - 2]=='c' && d[n - 1]=='d') | 382 | if (d[n - 2] == 'c' && d[n - 1] == 'd') |
386 | return 3 + addendum; | 383 | return 3 + addendum; |
387 | if(ptr[0]=='p' && ptr[1]=='a' && ptr[2]=='r' && ptr[3]=='t') | 384 | if (ptr[0] == 'p' && ptr[1] == 'a' && ptr[2] == 'r' && ptr[3] == 't') |
388 | return 4 + addendum; | 385 | return 4 + addendum; |
389 | if(ptr[n - 2]=='m' && ptr[n - 1]=='t') | 386 | if (ptr[n - 2] == 'm' && ptr[n - 1] == 't') |
390 | return 5 + addendum; | 387 | return 5 + addendum; |
391 | return 0; | 388 | return 0; |
392 | } | 389 | } |
393 | 390 | ||
394 | static unsigned int scan_dev_name(const char *d, unsigned int n, char *ptr) | 391 | static unsigned int scan_dev_name(const char *d, unsigned int n, char *ptr) |
395 | { | 392 | { |
396 | if(d[0]=='s' && d[1]=='c' && d[2]=='s' && d[3]=='i' && d[4]=='/') { | 393 | if (d[0] == 's' && d[1] == 'c' && d[2] == 's' && d[3] == 'i' && d[4] == '/') { |
397 | if( d[n - 7]=='g' && d[n - 6]=='e' && d[n - 5]=='n' && | 394 | if (d[n - 7] == 'g' && d[n - 6] == 'e' && d[n - 5] == 'n' |
398 | d[n - 4]=='e' && d[n - 3]=='r' && d[n - 2]=='i' && | 395 | && d[n - 4] == 'e' && d[n - 3] == 'r' && d[n - 2] == 'i' && d[n - 1] == 'c' |
399 | d[n - 1]=='c' ) | 396 | ) |
400 | return 1; | 397 | return 1; |
401 | return scan_dev_name_common(d, n, 0, ptr); | 398 | return scan_dev_name_common(d, n, 0, ptr); |
402 | } | 399 | } |
403 | if(d[0]=='i' && d[1]=='d' && d[2]=='e' && d[3]=='/' && | 400 | if (d[0] == 'i' && d[1] == 'd' && d[2] == 'e' && d[3] == '/' |
404 | d[4]=='h' && d[5]=='o' && d[6]=='s' && d[7]=='t') | 401 | && d[4] == 'h' && d[5] == 'o' && d[6] == 's' && d[7] == 't' |
402 | ) | ||
405 | return scan_dev_name_common(d, n, 4, ptr); | 403 | return scan_dev_name_common(d, n, 4, ptr); |
406 | if(d[0]=='s' && d[1]=='b' && d[2]=='p' && d[3]=='/') | 404 | if (d[0] == 's' && d[1] == 'b' && d[2] == 'p' && d[3] == '/') |
407 | return 10; | 405 | return 10; |
408 | if(d[0]=='v' && d[1]=='c' && d[2]=='c' && d[3]=='/') | 406 | if (d[0] == 'v' && d[1] == 'c' && d[2] == 'c' && d[3] == '/') |
409 | return 11; | 407 | return 11; |
410 | if(d[0]=='p' && d[1]=='t' && d[2]=='y' && d[3]=='/') | 408 | if (d[0] == 'p' && d[1] == 't' && d[2] == 'y' && d[3] == '/') |
411 | return 12; | 409 | return 12; |
412 | return 0; | 410 | return 0; |
413 | } | 411 | } |
414 | 412 | ||
415 | /* Public functions follow */ | 413 | /* Public functions follow */ |
416 | 414 | ||
417 | int devfsd_main (int argc, char **argv); | 415 | int devfsd_main(int argc, char **argv); |
418 | int devfsd_main (int argc, char **argv) | 416 | int devfsd_main(int argc, char **argv) |
419 | { | 417 | { |
420 | int print_version = FALSE; | 418 | int print_version = FALSE; |
421 | int do_daemon = TRUE; | 419 | int do_daemon = TRUE; |
@@ -429,17 +427,15 @@ int devfsd_main (int argc, char **argv) | |||
429 | if (argc < 2) | 427 | if (argc < 2) |
430 | bb_show_usage(); | 428 | bb_show_usage(); |
431 | 429 | ||
432 | for (count = 2; count < argc; ++count) | 430 | for (count = 2; count < argc; ++count) { |
433 | { | 431 | if (argv[count][0] == '-') { |
434 | if(argv[count][0] == '-') | 432 | if (argv[count][1] == 'v' && !argv[count][2]) /* -v */ |
435 | { | ||
436 | if(argv[count][1]=='v' && !argv[count][2]) /* -v */ | ||
437 | print_version = TRUE; | 433 | print_version = TRUE; |
438 | else if(ENABLE_DEVFSD_FG_NP && argv[count][1]=='f' | 434 | else if (ENABLE_DEVFSD_FG_NP && argv[count][1] == 'f' |
439 | && argv[count][2]=='g' && !argv[count][3]) /* -fg */ | 435 | && argv[count][2] == 'g' && !argv[count][3]) /* -fg */ |
440 | do_daemon = FALSE; | 436 | do_daemon = FALSE; |
441 | else if(ENABLE_DEVFSD_FG_NP && argv[count][1]=='n' | 437 | else if (ENABLE_DEVFSD_FG_NP && argv[count][1] == 'n' |
442 | && argv[count][2]=='p' && !argv[count][3]) /* -np */ | 438 | && argv[count][2] == 'p' && !argv[count][3]) /* -np */ |
443 | no_polling = TRUE; | 439 | no_polling = TRUE; |
444 | else | 440 | else |
445 | bb_show_usage(); | 441 | bb_show_usage(); |
@@ -447,37 +443,37 @@ int devfsd_main (int argc, char **argv) | |||
447 | } | 443 | } |
448 | 444 | ||
449 | /* strip last / from mount point, so we don't need to check for it later */ | 445 | /* strip last / from mount point, so we don't need to check for it later */ |
450 | while (argv[1][1]!='\0' && argv[1][strlen(argv[1])-1] == '/' ) | 446 | while (argv[1][1] != '\0' && argv[1][strlen(argv[1]) - 1] == '/') |
451 | argv[1][strlen(argv[1]) -1] = '\0'; | 447 | argv[1][strlen(argv[1]) - 1] = '\0'; |
452 | 448 | ||
453 | mount_point = argv[1]; | 449 | mount_point = argv[1]; |
454 | 450 | ||
455 | if (chdir (mount_point) != 0) | 451 | if (chdir(mount_point) != 0) |
456 | devfsd_perror_msg_and_die(mount_point); | 452 | devfsd_perror_msg_and_die(mount_point); |
457 | 453 | ||
458 | fd = xopen (".devfsd", O_RDONLY); | 454 | fd = xopen(".devfsd", O_RDONLY); |
459 | 455 | ||
460 | if (fcntl (fd, F_SETFD, FD_CLOEXEC) != 0) | 456 | if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) |
461 | devfsd_perror_msg_and_die("FD_CLOEXEC"); | 457 | devfsd_perror_msg_and_die("FD_CLOEXEC"); |
462 | 458 | ||
463 | if (ioctl (fd, DEVFSDIOC_GET_PROTO_REV, &proto_rev) == -1) | 459 | if (ioctl(fd, DEVFSDIOC_GET_PROTO_REV, &proto_rev) == -1) |
464 | msg_logger_and_die(LOG_ERR, "ioctl"); | 460 | msg_logger_and_die(LOG_ERR, "ioctl"); |
465 | 461 | ||
466 | /*setup initial entries */ | 462 | /*setup initial entries */ |
467 | for (curr = initial_symlinks; curr->dest != NULL; ++curr) | 463 | for (curr = initial_symlinks; curr->dest != NULL; ++curr) |
468 | symlink (curr->dest, curr->name); | 464 | symlink(curr->dest, curr->name); |
469 | 465 | ||
470 | /* NB: The check for CONFIG_FILE is done in read_config_file() */ | 466 | /* NB: The check for CONFIG_FILE is done in read_config_file() */ |
471 | 467 | ||
472 | if (print_version || (DEVFSD_PROTOCOL_REVISION_DAEMON != proto_rev)) { | 468 | if (print_version ||(DEVFSD_PROTOCOL_REVISION_DAEMON != proto_rev)) { |
473 | printf("%s v%s\nDaemon %s:\t%d\nKernel-side %s:\t%d\n", | 469 | printf("%s v%s\nDaemon %s:\t%d\nKernel-side %s:\t%d\n", |
474 | applet_name,DEVFSD_VERSION,bb_msg_proto_rev, | 470 | applet_name, DEVFSD_VERSION, bb_msg_proto_rev, |
475 | DEVFSD_PROTOCOL_REVISION_DAEMON,bb_msg_proto_rev, proto_rev); | 471 | DEVFSD_PROTOCOL_REVISION_DAEMON,bb_msg_proto_rev, proto_rev); |
476 | if (DEVFSD_PROTOCOL_REVISION_DAEMON != proto_rev) | 472 | if (DEVFSD_PROTOCOL_REVISION_DAEMON != proto_rev) |
477 | bb_error_msg_and_die( "%s mismatch!",bb_msg_proto_rev); | 473 | bb_error_msg_and_die("%s mismatch!", bb_msg_proto_rev); |
478 | exit(EXIT_SUCCESS); /* -v */ | 474 | exit(EXIT_SUCCESS); /* -v */ |
479 | } | 475 | } |
480 | /* Tell kernel we are special (i.e. we get to see hidden entries) */ | 476 | /* Tell kernel we are special(i.e. we get to see hidden entries) */ |
481 | do_ioctl_and_die(fd, DEVFSDIOC_SET_EVENT_MASK, 0); | 477 | do_ioctl_and_die(fd, DEVFSDIOC_SET_EVENT_MASK, 0); |
482 | 478 | ||
483 | sigemptyset(&new_action.sa_mask); | 479 | sigemptyset(&new_action.sa_mask); |
@@ -485,8 +481,8 @@ int devfsd_main (int argc, char **argv) | |||
485 | 481 | ||
486 | /* Set up SIGHUP and SIGUSR1 handlers */ | 482 | /* Set up SIGHUP and SIGUSR1 handlers */ |
487 | new_action.sa_handler = signal_handler; | 483 | new_action.sa_handler = signal_handler; |
488 | if (sigaction(SIGHUP, &new_action, NULL) != 0 || sigaction (SIGUSR1, &new_action, NULL) != 0 ) | 484 | if (sigaction(SIGHUP, &new_action, NULL) != 0 || sigaction(SIGUSR1, &new_action, NULL) != 0) |
489 | devfsd_error_msg_and_die( "sigaction"); | 485 | devfsd_error_msg_and_die("sigaction"); |
490 | 486 | ||
491 | printf("%s v%s started for %s\n",applet_name, DEVFSD_VERSION, mount_point); | 487 | printf("%s v%s started for %s\n",applet_name, DEVFSD_VERSION, mount_point); |
492 | 488 | ||
@@ -494,26 +490,24 @@ int devfsd_main (int argc, char **argv) | |||
494 | umask(0); | 490 | umask(0); |
495 | read_config_file((char*)CONFIG_FILE, FALSE, &event_mask); | 491 | read_config_file((char*)CONFIG_FILE, FALSE, &event_mask); |
496 | /* Do the scan before forking, so that boot scripts see the finished product */ | 492 | /* Do the scan before forking, so that boot scripts see the finished product */ |
497 | dir_operation(SERVICE,mount_point,0,NULL); | 493 | dir_operation(SERVICE, mount_point, 0, NULL); |
498 | 494 | ||
499 | if (ENABLE_DEVFSD_FG_NP && no_polling) | 495 | if (ENABLE_DEVFSD_FG_NP && no_polling) |
500 | exit (0); | 496 | exit(0); |
501 | if (do_daemon) | 497 | if (do_daemon) { |
502 | { | ||
503 | /* Release so that the child can grab it */ | 498 | /* Release so that the child can grab it */ |
504 | do_ioctl_and_die(fd, DEVFSDIOC_RELEASE_EVENT_QUEUE, 0); | 499 | do_ioctl_and_die(fd, DEVFSDIOC_RELEASE_EVENT_QUEUE, 0); |
505 | fork_and_execute(DIE, NULL, NULL); | 500 | fork_and_execute(DIE, NULL, NULL); |
506 | setsid (); /* Prevent hangups and become pgrp leader */ | 501 | setsid(); /* Prevent hangups and become pgrp leader */ |
507 | } else if(ENABLE_DEVFSD_FG_NP) { | 502 | } else if (ENABLE_DEVFSD_FG_NP) { |
508 | setpgid (0, 0); /* Become process group leader */ | 503 | setpgid(0, 0); /* Become process group leader */ |
509 | } | 504 | } |
510 | 505 | ||
511 | while (TRUE) | 506 | while (TRUE) { |
512 | { | 507 | do_scan = do_servicing(fd, event_mask); |
513 | do_scan = do_servicing (fd, event_mask); | ||
514 | 508 | ||
515 | free_config (); | 509 | free_config(); |
516 | read_config_file ((char*)CONFIG_FILE, FALSE, &event_mask); | 510 | read_config_file((char*)CONFIG_FILE, FALSE, &event_mask); |
517 | if (do_scan) | 511 | if (do_scan) |
518 | dir_operation(SERVICE,mount_point,0,NULL); | 512 | dir_operation(SERVICE,mount_point,0,NULL); |
519 | } | 513 | } |
@@ -522,10 +516,10 @@ int devfsd_main (int argc, char **argv) | |||
522 | 516 | ||
523 | /* Private functions follow */ | 517 | /* Private functions follow */ |
524 | 518 | ||
525 | static void read_config_file (char *path, int optional, unsigned long *event_mask) | 519 | static void read_config_file(char *path, int optional, unsigned long *event_mask) |
526 | /* [SUMMARY] Read a configuration database. | 520 | /* [SUMMARY] Read a configuration database. |
527 | <path> The path to read the database from. If this is a directory, all | 521 | <path> The path to read the database from. If this is a directory, all |
528 | entries in that directory will be read (except hidden entries). | 522 | entries in that directory will be read(except hidden entries). |
529 | <optional> If TRUE, the routine will silently ignore a missing config file. | 523 | <optional> If TRUE, the routine will silently ignore a missing config file. |
530 | <event_mask> The event mask is written here. This is not initialised. | 524 | <event_mask> The event mask is written here. This is not initialised. |
531 | [RETURNS] Nothing. | 525 | [RETURNS] Nothing. |
@@ -538,43 +532,39 @@ static void read_config_file (char *path, int optional, unsigned long *event_mas | |||
538 | 532 | ||
539 | debug_msg_logger(LOG_INFO, "%s: %s", __FUNCTION__, path); | 533 | debug_msg_logger(LOG_INFO, "%s: %s", __FUNCTION__, path); |
540 | 534 | ||
541 | if (stat (path, &statbuf) == 0 ) | 535 | if (stat(path, &statbuf) == 0) { |
542 | { | ||
543 | /* Don't read 0 length files: ignored */ | 536 | /* Don't read 0 length files: ignored */ |
544 | /*if( statbuf.st_size == 0 ) | 537 | /*if (statbuf.st_size == 0) |
545 | return;*/ | 538 | return;*/ |
546 | if ( S_ISDIR (statbuf.st_mode) ) | 539 | if (S_ISDIR(statbuf.st_mode)) { |
547 | { | ||
548 | /* strip last / from dirname so we don't need to check for it later */ | 540 | /* strip last / from dirname so we don't need to check for it later */ |
549 | while (path && path[1]!='\0' && path[strlen(path)-1] == '/') | 541 | while (path && path[1] != '\0' && path[strlen(path) - 1] == '/') |
550 | path[strlen(path) -1] = '\0'; | 542 | path[strlen(path) - 1] = '\0'; |
551 | 543 | ||
552 | dir_operation(READ_CONFIG, path, 0, event_mask); | 544 | dir_operation(READ_CONFIG, path, 0, event_mask); |
553 | return; | 545 | return; |
554 | } | 546 | } |
555 | if ( ( fp = fopen (path, "r") ) != NULL ) | 547 | if ((fp = fopen(path, "r")) != NULL) { |
556 | { | 548 | while (fgets(buf, STRING_LENGTH, fp) != NULL) { |
557 | while (fgets (buf, STRING_LENGTH, fp) != NULL) | ||
558 | { | ||
559 | /* Skip whitespace */ | 549 | /* Skip whitespace */ |
560 | for (line = buf; isspace (*line); ++line) | 550 | for (line = buf; isspace(*line); ++line) |
561 | /*VOID*/; | 551 | /*VOID*/; |
562 | if (line[0] == '\0' || line[0] == '#' ) | 552 | if (line[0] == '\0' || line[0] == '#') |
563 | continue; | 553 | continue; |
564 | process_config_line (line, event_mask); | 554 | process_config_line(line, event_mask); |
565 | } | 555 | } |
566 | fclose (fp); | 556 | fclose(fp); |
567 | } else { | 557 | } else { |
568 | goto read_config_file_err; | 558 | goto read_config_file_err; |
569 | } | 559 | } |
570 | } else { | 560 | } else { |
571 | read_config_file_err: | 561 | read_config_file_err: |
572 | if(optional == 0 && errno == ENOENT) | 562 | if (optional == 0 && errno == ENOENT) |
573 | msg_logger_and_die(LOG_ERR, "read config file: %s: %m", path); | 563 | msg_logger_and_die(LOG_ERR, "read config file: %s: %m", path); |
574 | } | 564 | } |
575 | } /* End Function read_config_file */ | 565 | } /* End Function read_config_file */ |
576 | 566 | ||
577 | static void process_config_line (const char *line, unsigned long *event_mask) | 567 | static void process_config_line(const char *line, unsigned long *event_mask) |
578 | /* [SUMMARY] Process a line from a configuration file. | 568 | /* [SUMMARY] Process a line from a configuration file. |
579 | <line> The configuration line. | 569 | <line> The configuration line. |
580 | <event_mask> The event mask is written here. This is not initialised. | 570 | <event_mask> The event mask is written here. This is not initialised. |
@@ -601,77 +591,70 @@ static void process_config_line (const char *line, unsigned long *event_mask) | |||
601 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 591 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
602 | 592 | ||
603 | for (count = 0; count < MAX_ARGS; ++count) p[count][0] = '\0'; | 593 | for (count = 0; count < MAX_ARGS; ++count) p[count][0] = '\0'; |
604 | num_args = sscanf (line, "%s %s %s %s %s %s %s %s %s %s", | 594 | num_args = sscanf(line, "%s %s %s %s %s %s %s %s %s %s", |
605 | when, name, what, | 595 | when, name, what, |
606 | p[0], p[1], p[2], p[3], p[4], p[5], p[6]); | 596 | p[0], p[1], p[2], p[3], p[4], p[5], p[6]); |
607 | 597 | ||
608 | i = index_in_str_array(options, when ); | 598 | i = index_in_str_array(options, when); |
609 | 599 | ||
610 | /*"CLEAR_CONFIG"*/ | 600 | /*"CLEAR_CONFIG"*/ |
611 | if( i == 0) | 601 | if (i == 0) { |
612 | { | 602 | free_config(); |
613 | free_config (); | ||
614 | *event_mask = 0; | 603 | *event_mask = 0; |
615 | return; | 604 | return; |
616 | } | 605 | } |
617 | 606 | ||
618 | if ( num_args < 2) | 607 | if (num_args < 2) |
619 | goto process_config_line_err; | 608 | goto process_config_line_err; |
620 | 609 | ||
621 | /* "INCLUDE" & "OPTIONAL_INCLUDE" */ | 610 | /* "INCLUDE" & "OPTIONAL_INCLUDE" */ |
622 | if( i == 1 || i == 2 ) | 611 | if (i == 1 || i == 2) { |
623 | { | 612 | st_expr_expand(name, STRING_LENGTH, name, get_variable, NULL); |
624 | st_expr_expand (name, STRING_LENGTH, name, get_variable, NULL ); | 613 | msg_logger(LOG_INFO, "%sinclude: %s", (toupper(when[0]) == 'I') ? "": "optional_", name); |
625 | msg_logger(LOG_INFO, "%sinclude: %s",(toupper (when[0]) == 'I') ? "": "optional_", name); | 614 | read_config_file(name, (toupper(when[0]) == 'I') ? FALSE : TRUE, event_mask); |
626 | read_config_file (name, (toupper (when[0]) == 'I') ? FALSE : TRUE, event_mask); | ||
627 | return; | 615 | return; |
628 | } | 616 | } |
629 | /* "RESTORE" */ | 617 | /* "RESTORE" */ |
630 | if( i == 3) | 618 | if (i == 3) { |
631 | { | 619 | dir_operation(RESTORE,name, strlen(name),NULL); |
632 | dir_operation(RESTORE,name, strlen (name),NULL); | ||
633 | return; | 620 | return; |
634 | } | 621 | } |
635 | if (num_args < 3) | 622 | if (num_args < 3) |
636 | goto process_config_line_err; | 623 | goto process_config_line_err; |
637 | 624 | ||
638 | new = xmalloc (sizeof *new); | 625 | new = xmalloc(sizeof *new); |
639 | memset (new, 0, sizeof *new); | 626 | memset(new, 0, sizeof *new); |
640 | 627 | ||
641 | for (count = 0; event_types[count].config_name != NULL; ++count) | 628 | for (count = 0; event_types[count].config_name != NULL; ++count) { |
642 | { | 629 | if (strcasecmp(when, event_types[count].config_name) != 0) |
643 | if (strcasecmp (when, event_types[count].config_name) != 0) | ||
644 | continue; | 630 | continue; |
645 | new->action.when = event_types[count].type; | 631 | new->action.when = event_types[count].type; |
646 | break; | 632 | break; |
647 | } | 633 | } |
648 | if (event_types[count].config_name == NULL) | 634 | if (event_types[count].config_name == NULL) { |
649 | { | ||
650 | msg="WHEN in"; | 635 | msg="WHEN in"; |
651 | goto process_config_line_err; | 636 | goto process_config_line_err; |
652 | } | 637 | } |
653 | 638 | ||
654 | i = index_in_str_array(options, what ); | 639 | i = index_in_str_array(options, what); |
655 | 640 | ||
656 | switch (i) | 641 | switch (i) { |
657 | { | ||
658 | case 4: /* "PERMISSIONS" */ | 642 | case 4: /* "PERMISSIONS" */ |
659 | new->action.what = AC_PERMISSIONS; | 643 | new->action.what = AC_PERMISSIONS; |
660 | /* Get user and group */ | 644 | /* Get user and group */ |
661 | if ( ( ptr = strchr (p[0], '.') ) == NULL ) | 645 | if ((ptr = strchr(p[0], '.')) == NULL) { |
662 | { | ||
663 | msg="UID.GID"; | 646 | msg="UID.GID"; |
664 | goto process_config_line_err; /*"missing '.' in UID.GID"*/ | 647 | goto process_config_line_err; /*"missing '.' in UID.GID"*/ |
665 | } | 648 | } |
666 | 649 | ||
667 | *ptr++ = '\0'; | 650 | *ptr++ = '\0'; |
668 | new->u.permissions.uid = get_uid_gid (UID, p[0]); | 651 | new->u.permissions.uid = get_uid_gid(UID, p[0]); |
669 | new->u.permissions.gid = get_uid_gid (GID, ptr); | 652 | new->u.permissions.gid = get_uid_gid(GID, ptr); |
670 | /* Get mode */ | 653 | /* Get mode */ |
671 | new->u.permissions.mode = get_mode (p[1]); | 654 | new->u.permissions.mode = get_mode(p[1]); |
672 | break; | 655 | break; |
673 | case 5: /* MODLOAD */ | 656 | case 5: /* MODLOAD */ |
674 | /*This action will pass "/dev/$devname" (i.e. "/dev/" prefixed to | 657 | /*This action will pass "/dev/$devname"(i.e. "/dev/" prefixed to |
675 | the device name) to the module loading facility. In addition, | 658 | the device name) to the module loading facility. In addition, |
676 | the /etc/modules.devfs configuration file is used.*/ | 659 | the /etc/modules.devfs configuration file is used.*/ |
677 | if (ENABLE_DEVFSD_MODLOAD) | 660 | if (ENABLE_DEVFSD_MODLOAD) |
@@ -682,7 +665,7 @@ static void process_config_line (const char *line, unsigned long *event_mask) | |||
682 | num_args -= 3; | 665 | num_args -= 3; |
683 | 666 | ||
684 | for (count = 0; count < num_args; ++count) | 667 | for (count = 0; count < num_args; ++count) |
685 | new->u.execute.argv[count] = xstrdup (p[count]); | 668 | new->u.execute.argv[count] = xstrdup(p[count]); |
686 | 669 | ||
687 | new->u.execute.argv[num_args] = NULL; | 670 | new->u.execute.argv[num_args] = NULL; |
688 | break; | 671 | break; |
@@ -692,8 +675,8 @@ static void process_config_line (const char *line, unsigned long *event_mask) | |||
692 | if (num_args != 2) | 675 | if (num_args != 2) |
693 | goto process_config_line_err; /* missing path and function in line */ | 676 | goto process_config_line_err; /* missing path and function in line */ |
694 | 677 | ||
695 | new->u.copy.source = xstrdup (p[0]); | 678 | new->u.copy.source = xstrdup(p[0]); |
696 | new->u.copy.destination = xstrdup (p[1]); | 679 | new->u.copy.destination = xstrdup(p[1]); |
697 | break; | 680 | break; |
698 | case 8: /* IGNORE */ | 681 | case 8: /* IGNORE */ |
699 | /* FALLTROUGH */ | 682 | /* FALLTROUGH */ |
@@ -717,7 +700,7 @@ static void process_config_line (const char *line, unsigned long *event_mask) | |||
717 | /*esac*/ | 700 | /*esac*/ |
718 | } /* switch (i) */ | 701 | } /* switch (i) */ |
719 | 702 | ||
720 | xregcomp( &new->preg, name, REG_EXTENDED); | 703 | xregcomp(&new->preg, name, REG_EXTENDED); |
721 | 704 | ||
722 | *event_mask |= 1 << new->action.when; | 705 | *event_mask |= 1 << new->action.when; |
723 | new->next = NULL; | 706 | new->next = NULL; |
@@ -731,7 +714,7 @@ process_config_line_err: | |||
731 | msg_logger_and_die(LOG_ERR, bb_msg_bad_config, msg , line); | 714 | msg_logger_and_die(LOG_ERR, bb_msg_bad_config, msg , line); |
732 | } /* End Function process_config_line */ | 715 | } /* End Function process_config_line */ |
733 | 716 | ||
734 | static int do_servicing (int fd, unsigned long event_mask) | 717 | static int do_servicing(int fd, unsigned long event_mask) |
735 | /* [SUMMARY] Service devfs changes until a signal is received. | 718 | /* [SUMMARY] Service devfs changes until a signal is received. |
736 | <fd> The open control file. | 719 | <fd> The open control file. |
737 | <event_mask> The event mask. | 720 | <event_mask> The event mask. |
@@ -747,20 +730,18 @@ static int do_servicing (int fd, unsigned long event_mask) | |||
747 | /* Tell devfs what events we care about */ | 730 | /* Tell devfs what events we care about */ |
748 | tmp_event_mask = event_mask; | 731 | tmp_event_mask = event_mask; |
749 | do_ioctl_and_die(fd, DEVFSDIOC_SET_EVENT_MASK, tmp_event_mask); | 732 | do_ioctl_and_die(fd, DEVFSDIOC_SET_EVENT_MASK, tmp_event_mask); |
750 | while (!caught_signal) | 733 | while (!caught_signal) { |
751 | { | ||
752 | errno = 0; | 734 | errno = 0; |
753 | bytes = read (fd, (char *) &info, sizeof info); | 735 | bytes = read(fd,(char *) &info, sizeof info); |
754 | if (caught_signal) | 736 | if (caught_signal) |
755 | break; /* Must test for this first */ | 737 | break; /* Must test for this first */ |
756 | if (errno == EINTR) | 738 | if (errno == EINTR) |
757 | continue; /* Yes, the order is important */ | 739 | continue; /* Yes, the order is important */ |
758 | if (bytes < 1) | 740 | if (bytes < 1) |
759 | break; | 741 | break; |
760 | service_name (&info); | 742 | service_name(&info); |
761 | } | 743 | } |
762 | if (caught_signal) | 744 | if (caught_signal) { |
763 | { | ||
764 | int c_sighup = caught_sighup; | 745 | int c_sighup = caught_sighup; |
765 | 746 | ||
766 | caught_signal = FALSE; | 747 | caught_signal = FALSE; |
@@ -770,7 +751,7 @@ static int do_servicing (int fd, unsigned long event_mask) | |||
770 | msg_logger_and_die(LOG_ERR, "read error on control file"); | 751 | msg_logger_and_die(LOG_ERR, "read error on control file"); |
771 | } /* End Function do_servicing */ | 752 | } /* End Function do_servicing */ |
772 | 753 | ||
773 | static void service_name (const struct devfsd_notify_struct *info) | 754 | static void service_name(const struct devfsd_notify_struct *info) |
774 | /* [SUMMARY] Service a single devfs change. | 755 | /* [SUMMARY] Service a single devfs change. |
775 | <info> The devfs change. | 756 | <info> The devfs change. |
776 | [RETURNS] Nothing. | 757 | [RETURNS] Nothing. |
@@ -785,38 +766,39 @@ static void service_name (const struct devfsd_notify_struct *info) | |||
785 | debug_msg_logger(LOG_ERR, "lost %u events", info->overrun_count); | 766 | debug_msg_logger(LOG_ERR, "lost %u events", info->overrun_count); |
786 | 767 | ||
787 | /* Discard lookups on "/dev/log" and "/dev/initctl" */ | 768 | /* Discard lookups on "/dev/log" and "/dev/initctl" */ |
788 | if( info->type == DEVFSD_NOTIFY_LOOKUP && | 769 | if (info->type == DEVFSD_NOTIFY_LOOKUP |
789 | ((info->devname[0]=='l' && info->devname[1]=='o' && | 770 | && ((info->devname[0] == 'l' && info->devname[1] == 'o' |
790 | info->devname[2]=='g' && !info->devname[3]) || | 771 | && info->devname[2] == 'g' && !info->devname[3]) |
791 | ( info->devname[0]=='i' && info->devname[1]=='n' && | 772 | || (info->devname[0] == 'i' && info->devname[1] == 'n' |
792 | info->devname[2]=='i' && info->devname[3]=='t' && | 773 | && info->devname[2] == 'i' && info->devname[3] == 't' |
793 | info->devname[4]=='c' && info->devname[5]=='t' && | 774 | && info->devname[4] == 'c' && info->devname[5] == 't' |
794 | info->devname[6]=='l' && !info->devname[7]))) | 775 | && info->devname[6] == 'l' && !info->devname[7])) |
795 | return; | 776 | ) |
796 | for (entry = first_config; entry != NULL; entry = entry->next) | 777 | return; |
797 | { | 778 | |
779 | for (entry = first_config; entry != NULL; entry = entry->next) { | ||
798 | /* First check if action matches the type, then check if name matches */ | 780 | /* First check if action matches the type, then check if name matches */ |
799 | if (info->type != entry->action.when || regexec (&entry->preg, info->devname, MAX_SUBEXPR, mbuf, 0) != 0 ) | 781 | if (info->type != entry->action.when |
782 | || regexec(&entry->preg, info->devname, MAX_SUBEXPR, mbuf, 0) != 0) | ||
800 | continue; | 783 | continue; |
801 | for (n = 0; (n < MAX_SUBEXPR) && (mbuf[n].rm_so != -1); ++n) | 784 | for (n = 0;(n < MAX_SUBEXPR) && (mbuf[n].rm_so != -1); ++n) |
802 | /* VOID */; | 785 | /* VOID */; |
803 | 786 | ||
804 | debug_msg_logger(LOG_INFO, "%s: action.what %d", __FUNCTION__, entry->action.what); | 787 | debug_msg_logger(LOG_INFO, "%s: action.what %d", __FUNCTION__, entry->action.what); |
805 | 788 | ||
806 | switch (entry->action.what) | 789 | switch (entry->action.what) { |
807 | { | ||
808 | case AC_PERMISSIONS: | 790 | case AC_PERMISSIONS: |
809 | action_permissions (info, entry); | 791 | action_permissions(info, entry); |
810 | break; | 792 | break; |
811 | case AC_MODLOAD: | 793 | case AC_MODLOAD: |
812 | if(ENABLE_DEVFSD_MODLOAD) | 794 | if (ENABLE_DEVFSD_MODLOAD) |
813 | action_modload (info, entry); | 795 | action_modload(info, entry); |
814 | break; | 796 | break; |
815 | case AC_EXECUTE: | 797 | case AC_EXECUTE: |
816 | action_execute (info, entry, mbuf, n); | 798 | action_execute(info, entry, mbuf, n); |
817 | break; | 799 | break; |
818 | case AC_COPY: | 800 | case AC_COPY: |
819 | action_copy (info, entry, mbuf, n); | 801 | action_copy(info, entry, mbuf, n); |
820 | break; | 802 | break; |
821 | case AC_IGNORE: | 803 | case AC_IGNORE: |
822 | return; | 804 | return; |
@@ -825,7 +807,7 @@ static void service_name (const struct devfsd_notify_struct *info) | |||
825 | case AC_MKNEWCOMPAT: | 807 | case AC_MKNEWCOMPAT: |
826 | case AC_RMOLDCOMPAT: | 808 | case AC_RMOLDCOMPAT: |
827 | case AC_RMNEWCOMPAT: | 809 | case AC_RMNEWCOMPAT: |
828 | action_compat (info, entry->action.what); | 810 | action_compat(info, entry->action.what); |
829 | break; | 811 | break; |
830 | default: | 812 | default: |
831 | msg_logger_and_die(LOG_ERR, "Unknown action"); | 813 | msg_logger_and_die(LOG_ERR, "Unknown action"); |
@@ -833,7 +815,7 @@ static void service_name (const struct devfsd_notify_struct *info) | |||
833 | } | 815 | } |
834 | } /* End Function service_name */ | 816 | } /* End Function service_name */ |
835 | 817 | ||
836 | static void action_permissions (const struct devfsd_notify_struct *info, | 818 | static void action_permissions(const struct devfsd_notify_struct *info, |
837 | const struct config_entry_struct *entry) | 819 | const struct config_entry_struct *entry) |
838 | /* [SUMMARY] Update permissions for a device entry. | 820 | /* [SUMMARY] Update permissions for a device entry. |
839 | <info> The devfs change. | 821 | <info> The devfs change. |
@@ -845,15 +827,14 @@ static void action_permissions (const struct devfsd_notify_struct *info, | |||
845 | 827 | ||
846 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 828 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
847 | 829 | ||
848 | if ( stat (info->devname, &statbuf) != 0 || | 830 | if (stat(info->devname, &statbuf) != 0 || |
849 | chmod (info->devname,(statbuf.st_mode & S_IFMT) | (entry->u.permissions.mode & ~S_IFMT)) != 0 || | 831 | chmod(info->devname,(statbuf.st_mode & S_IFMT) |(entry->u.permissions.mode & ~S_IFMT)) != 0 || |
850 | chown (info->devname, entry->u.permissions.uid, entry->u.permissions.gid) != 0) | 832 | chown(info->devname, entry->u.permissions.uid, entry->u.permissions.gid) != 0) { |
851 | { | ||
852 | msg_logger(LOG_ERR, "Can't chmod or chown: %s: %m",info->devname); | 833 | msg_logger(LOG_ERR, "Can't chmod or chown: %s: %m",info->devname); |
853 | } | 834 | } |
854 | } /* End Function action_permissions */ | 835 | } /* End Function action_permissions */ |
855 | 836 | ||
856 | static void action_modload (const struct devfsd_notify_struct *info, | 837 | static void action_modload(const struct devfsd_notify_struct *info, |
857 | const struct config_entry_struct *entry ATTRIBUTE_UNUSED) | 838 | const struct config_entry_struct *entry ATTRIBUTE_UNUSED) |
858 | /* [SUMMARY] Load a module. | 839 | /* [SUMMARY] Load a module. |
859 | <info> The devfs change. | 840 | <info> The devfs change. |
@@ -864,25 +845,25 @@ static void action_modload (const struct devfsd_notify_struct *info, | |||
864 | char *argv[6]; | 845 | char *argv[6]; |
865 | char device[STRING_LENGTH]; | 846 | char device[STRING_LENGTH]; |
866 | 847 | ||
867 | argv[0] = (char*)MODPROBE; | 848 | argv[0] =(char*)MODPROBE; |
868 | argv[1] = (char*)MODPROBE_SWITCH_1; /* "-k" */ | 849 | argv[1] =(char*)MODPROBE_SWITCH_1; /* "-k" */ |
869 | argv[2] = (char*)MODPROBE_SWITCH_2; /* "-C" */ | 850 | argv[2] =(char*)MODPROBE_SWITCH_2; /* "-C" */ |
870 | argv[3] = (char*)CONFIG_MODULES_DEVFS; | 851 | argv[3] =(char*)CONFIG_MODULES_DEVFS; |
871 | argv[4] = device; | 852 | argv[4] = device; |
872 | argv[5] = NULL; | 853 | argv[5] = NULL; |
873 | 854 | ||
874 | snprintf (device, sizeof (device), "/dev/%s", info->devname); | 855 | snprintf(device, sizeof(device), "/dev/%s", info->devname); |
875 | debug_msg_logger(LOG_INFO, "%s: %s %s %s %s %s",__FUNCTION__, argv[0],argv[1],argv[2],argv[3],argv[4]); | 856 | debug_msg_logger(LOG_INFO, "%s: %s %s %s %s %s",__FUNCTION__, argv[0],argv[1],argv[2],argv[3],argv[4]); |
876 | fork_and_execute(DIE, argv[0], argv); | 857 | fork_and_execute(DIE, argv[0], argv); |
877 | } /* End Function action_modload */ | 858 | } /* End Function action_modload */ |
878 | 859 | ||
879 | static void action_execute (const struct devfsd_notify_struct *info, | 860 | static void action_execute(const struct devfsd_notify_struct *info, |
880 | const struct config_entry_struct *entry, | 861 | const struct config_entry_struct *entry, |
881 | const regmatch_t *regexpr, unsigned int numexpr) | 862 | const regmatch_t *regexpr, unsigned int numexpr) |
882 | /* [SUMMARY] Execute a programme. | 863 | /* [SUMMARY] Execute a programme. |
883 | <info> The devfs change. | 864 | <info> The devfs change. |
884 | <entry> The config file entry. | 865 | <entry> The config file entry. |
885 | <regexpr> The number of subexpression (start, end) offsets within the | 866 | <regexpr> The number of subexpression(start, end) offsets within the |
886 | device name. | 867 | device name. |
887 | <numexpr> The number of elements within <<regexpr>>. | 868 | <numexpr> The number of elements within <<regexpr>>. |
888 | [RETURNS] Nothing. | 869 | [RETURNS] Nothing. |
@@ -896,13 +877,12 @@ static void action_execute (const struct devfsd_notify_struct *info, | |||
896 | debug_msg_logger(LOG_INFO ,__FUNCTION__); | 877 | debug_msg_logger(LOG_INFO ,__FUNCTION__); |
897 | gv_info.info = info; | 878 | gv_info.info = info; |
898 | gv_info.devname = info->devname; | 879 | gv_info.devname = info->devname; |
899 | snprintf (gv_info.devpath, sizeof (gv_info.devpath), "%s/%s", mount_point, info->devname); | 880 | snprintf(gv_info.devpath, sizeof(gv_info.devpath), "%s/%s", mount_point, info->devname); |
900 | for (count = 0; entry->u.execute.argv[count] != NULL; ++count) | 881 | for (count = 0; entry->u.execute.argv[count] != NULL; ++count) { |
901 | { | 882 | expand_expression(largv[count], STRING_LENGTH, |
902 | expand_expression (largv[count], STRING_LENGTH, | ||
903 | entry->u.execute.argv[count], | 883 | entry->u.execute.argv[count], |
904 | get_variable, &gv_info, | 884 | get_variable, &gv_info, |
905 | gv_info.devname, regexpr, numexpr ); | 885 | gv_info.devname, regexpr, numexpr); |
906 | argv[count] = largv[count]; | 886 | argv[count] = largv[count]; |
907 | } | 887 | } |
908 | argv[count] = NULL; | 888 | argv[count] = NULL; |
@@ -910,13 +890,13 @@ static void action_execute (const struct devfsd_notify_struct *info, | |||
910 | } /* End Function action_execute */ | 890 | } /* End Function action_execute */ |
911 | 891 | ||
912 | 892 | ||
913 | static void action_copy (const struct devfsd_notify_struct *info, | 893 | static void action_copy(const struct devfsd_notify_struct *info, |
914 | const struct config_entry_struct *entry, | 894 | const struct config_entry_struct *entry, |
915 | const regmatch_t *regexpr, unsigned int numexpr) | 895 | const regmatch_t *regexpr, unsigned int numexpr) |
916 | /* [SUMMARY] Copy permissions. | 896 | /* [SUMMARY] Copy permissions. |
917 | <info> The devfs change. | 897 | <info> The devfs change. |
918 | <entry> The config file entry. | 898 | <entry> The config file entry. |
919 | <regexpr> This list of subexpression (start, end) offsets within the | 899 | <regexpr> This list of subexpression(start, end) offsets within the |
920 | device name. | 900 | device name. |
921 | <numexpr> The number of elements in <<regexpr>>. | 901 | <numexpr> The number of elements in <<regexpr>>. |
922 | [RETURNS] Nothing. | 902 | [RETURNS] Nothing. |
@@ -932,34 +912,34 @@ static void action_copy (const struct devfsd_notify_struct *info, | |||
932 | 912 | ||
933 | dest_stat.st_mode = 0; | 913 | dest_stat.st_mode = 0; |
934 | 914 | ||
935 | if ( (info->type == DEVFSD_NOTIFY_CHANGE) && S_ISLNK (info->mode) ) | 915 | if ((info->type == DEVFSD_NOTIFY_CHANGE) && S_ISLNK(info->mode)) |
936 | return; | 916 | return; |
937 | gv_info.info = info; | 917 | gv_info.info = info; |
938 | gv_info.devname = info->devname; | 918 | gv_info.devname = info->devname; |
939 | 919 | ||
940 | snprintf (gv_info.devpath, sizeof (gv_info.devpath), "%s/%s", mount_point, info->devname); | 920 | snprintf(gv_info.devpath, sizeof(gv_info.devpath), "%s/%s", mount_point, info->devname); |
941 | expand_expression (source, STRING_LENGTH, entry->u.copy.source, | 921 | expand_expression(source, STRING_LENGTH, entry->u.copy.source, |
942 | get_variable, &gv_info, gv_info.devname, | 922 | get_variable, &gv_info, gv_info.devname, |
943 | regexpr, numexpr); | 923 | regexpr, numexpr); |
944 | 924 | ||
945 | expand_expression (destination, STRING_LENGTH, entry->u.copy.destination, | 925 | expand_expression(destination, STRING_LENGTH, entry->u.copy.destination, |
946 | get_variable, &gv_info, gv_info.devname, | 926 | get_variable, &gv_info, gv_info.devname, |
947 | regexpr, numexpr); | 927 | regexpr, numexpr); |
948 | 928 | ||
949 | if ( !make_dir_tree (destination) || lstat (source, &source_stat) != 0) | 929 | if (!make_dir_tree(destination) || lstat(source, &source_stat) != 0) |
950 | return; | 930 | return; |
951 | lstat (destination, &dest_stat); | 931 | lstat(destination, &dest_stat); |
952 | new_mode = source_stat.st_mode & ~S_ISVTX; | 932 | new_mode = source_stat.st_mode & ~S_ISVTX; |
953 | if (info->type == DEVFSD_NOTIFY_CREATE) | 933 | if (info->type == DEVFSD_NOTIFY_CREATE) |
954 | new_mode |= S_ISVTX; | 934 | new_mode |= S_ISVTX; |
955 | else if ( (info->type == DEVFSD_NOTIFY_CHANGE) && (dest_stat.st_mode & S_ISVTX) ) | 935 | else if ((info->type == DEVFSD_NOTIFY_CHANGE) &&(dest_stat.st_mode & S_ISVTX)) |
956 | new_mode |= S_ISVTX; | 936 | new_mode |= S_ISVTX; |
957 | ret = copy_inode (destination, &dest_stat, new_mode, source, &source_stat); | 937 | ret = copy_inode(destination, &dest_stat, new_mode, source, &source_stat); |
958 | if (ENABLE_DEBUG && ret && (errno != EEXIST)) | 938 | if (ENABLE_DEBUG && ret &&(errno != EEXIST)) |
959 | debug_msg_logger(LOG_ERR, "copy_inode: %s to %s: %m", source, destination); | 939 | debug_msg_logger(LOG_ERR, "copy_inode: %s to %s: %m", source, destination); |
960 | } /* End Function action_copy */ | 940 | } /* End Function action_copy */ |
961 | 941 | ||
962 | static void action_compat (const struct devfsd_notify_struct *info, unsigned int action) | 942 | static void action_compat(const struct devfsd_notify_struct *info, unsigned int action) |
963 | /* [SUMMARY] Process a compatibility request. | 943 | /* [SUMMARY] Process a compatibility request. |
964 | <info> The devfs change. | 944 | <info> The devfs change. |
965 | <action> The action to take. | 945 | <action> The action to take. |
@@ -990,72 +970,69 @@ static void action_compat (const struct devfsd_notify_struct *info, unsigned int | |||
990 | }; | 970 | }; |
991 | 971 | ||
992 | /* First construct compatibility name */ | 972 | /* First construct compatibility name */ |
993 | switch (action) | 973 | switch (action) { |
994 | { | ||
995 | case AC_MKOLDCOMPAT: | 974 | case AC_MKOLDCOMPAT: |
996 | case AC_RMOLDCOMPAT: | 975 | case AC_RMOLDCOMPAT: |
997 | compat_name = get_old_name (info->devname, info->namelen, compat_buf, info->major, info->minor); | 976 | compat_name = get_old_name(info->devname, info->namelen, compat_buf, info->major, info->minor); |
998 | break; | 977 | break; |
999 | case AC_MKNEWCOMPAT: | 978 | case AC_MKNEWCOMPAT: |
1000 | case AC_RMNEWCOMPAT: | 979 | case AC_RMNEWCOMPAT: |
1001 | ptr = strrchr (info->devname, '/') + 1; | 980 | ptr = strrchr(info->devname, '/') + 1; |
1002 | i=scan_dev_name(info->devname, info->namelen, ptr); | 981 | i=scan_dev_name(info->devname, info->namelen, ptr); |
1003 | 982 | ||
1004 | debug_msg_logger(LOG_INFO, "%s: scan_dev_name = %d", __FUNCTION__, i); | 983 | debug_msg_logger(LOG_INFO, "%s: scan_dev_name = %d", __FUNCTION__, i); |
1005 | 984 | ||
1006 | /* nothing found */ | 985 | /* nothing found */ |
1007 | if(i==0 || i > 9) | 986 | if (i==0 || i > 9) |
1008 | return; | 987 | return; |
1009 | 988 | ||
1010 | sscanf (info->devname +((i<6)?5:4), "host%d/bus%d/target%d/lun%d/", &host, &bus, &target, &lun); | 989 | sscanf(info->devname +((i<6)?5:4), "host%d/bus%d/target%d/lun%d/", &host, &bus, &target, &lun); |
1011 | snprintf (dest_buf, sizeof (dest_buf), "../%s", info->devname + ((i>5)?4:0)); | 990 | snprintf(dest_buf, sizeof(dest_buf), "../%s", info->devname +((i>5)?4:0)); |
1012 | dest_name = dest_buf; | 991 | dest_name = dest_buf; |
1013 | compat_name = compat_buf; | 992 | compat_name = compat_buf; |
1014 | 993 | ||
1015 | 994 | ||
1016 | /* 1 == scsi/generic 2 == scsi/disc 3 == scsi/cd 6 == ide/host/disc 7 == ide/host/cd */ | 995 | /* 1 == scsi/generic 2 == scsi/disc 3 == scsi/cd 6 == ide/host/disc 7 == ide/host/cd */ |
1017 | if( i == 1 || i == 2 || i == 3 || i == 6 || i ==7 ) | 996 | if (i == 1 || i == 2 || i == 3 || i == 6 || i ==7) |
1018 | sprintf ( compat_buf, fmt[i], host, bus, target, lun); | 997 | sprintf(compat_buf, fmt[i], host, bus, target, lun); |
1019 | 998 | ||
1020 | /* 4 == scsi/part 8 == ide/host/part */ | 999 | /* 4 == scsi/part 8 == ide/host/part */ |
1021 | if( i == 4 || i == 8) | 1000 | if (i == 4 || i == 8) |
1022 | sprintf ( compat_buf, fmt[i], host, bus, target, lun, atoi (ptr + 4) ); | 1001 | sprintf(compat_buf, fmt[i], host, bus, target, lun, atoi(ptr + 4)); |
1023 | 1002 | ||
1024 | /* 5 == scsi/mt */ | 1003 | /* 5 == scsi/mt */ |
1025 | if( i == 5) | 1004 | if (i == 5) { |
1026 | { | ||
1027 | rewind_ = info->devname[info->namelen - 1]; | 1005 | rewind_ = info->devname[info->namelen - 1]; |
1028 | if (rewind_ != 'n') | 1006 | if (rewind_ != 'n') |
1029 | rewind_ = '\0'; | 1007 | rewind_ = '\0'; |
1030 | mode=0; | 1008 | mode=0; |
1031 | if(ptr[2] == 'l' /*108*/ || ptr[2] == 'm'/*109*/) | 1009 | if (ptr[2] == 'l' /*108*/ || ptr[2] == 'm'/*109*/) |
1032 | mode = ptr[2] - 107; /* 1 or 2 */ | 1010 | mode = ptr[2] - 107; /* 1 or 2 */ |
1033 | if(ptr[2] == 'a') | 1011 | if (ptr[2] == 'a') |
1034 | mode = 3; | 1012 | mode = 3; |
1035 | sprintf (compat_buf, fmt [i], host, bus, target, lun, mode, rewind_); | 1013 | sprintf(compat_buf, fmt [i], host, bus, target, lun, mode, rewind_); |
1036 | } | 1014 | } |
1037 | 1015 | ||
1038 | /* 9 == ide/host/mt */ | 1016 | /* 9 == ide/host/mt */ |
1039 | if( i == 9 ) | 1017 | if (i == 9) |
1040 | snprintf (compat_buf, sizeof (compat_buf), fmt[i], host, bus, target, lun, ptr + 2); | 1018 | snprintf(compat_buf, sizeof(compat_buf), fmt[i], host, bus, target, lun, ptr + 2); |
1041 | /* esac */ | 1019 | /* esac */ |
1042 | } /* switch (action) */ | 1020 | } /* switch (action) */ |
1043 | 1021 | ||
1044 | if(compat_name == NULL ) | 1022 | if (compat_name == NULL) |
1045 | return; | 1023 | return; |
1046 | 1024 | ||
1047 | debug_msg_logger( LOG_INFO, "%s: %s", __FUNCTION__, compat_name); | 1025 | debug_msg_logger(LOG_INFO, "%s: %s", __FUNCTION__, compat_name); |
1048 | 1026 | ||
1049 | /* Now decide what to do with it */ | 1027 | /* Now decide what to do with it */ |
1050 | switch (action) | 1028 | switch (action) { |
1051 | { | ||
1052 | case AC_MKOLDCOMPAT: | 1029 | case AC_MKOLDCOMPAT: |
1053 | case AC_MKNEWCOMPAT: | 1030 | case AC_MKNEWCOMPAT: |
1054 | mksymlink (dest_name, compat_name); | 1031 | mksymlink(dest_name, compat_name); |
1055 | break; | 1032 | break; |
1056 | case AC_RMOLDCOMPAT: | 1033 | case AC_RMOLDCOMPAT: |
1057 | case AC_RMNEWCOMPAT: | 1034 | case AC_RMNEWCOMPAT: |
1058 | ret = unlink (compat_name); | 1035 | ret = unlink(compat_name); |
1059 | if (ENABLE_DEBUG && ret) | 1036 | if (ENABLE_DEBUG && ret) |
1060 | debug_msg_logger(LOG_ERR, "unlink: %s: %m", compat_name); | 1037 | debug_msg_logger(LOG_ERR, "unlink: %s: %m", compat_name); |
1061 | break; | 1038 | break; |
@@ -1071,18 +1048,18 @@ static void restore(char *spath, struct stat source_stat, int rootlen) | |||
1071 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1048 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1072 | 1049 | ||
1073 | dest_stat.st_mode = 0; | 1050 | dest_stat.st_mode = 0; |
1074 | snprintf (dpath, sizeof dpath, "%s%s", mount_point, spath + rootlen); | 1051 | snprintf(dpath, sizeof dpath, "%s%s", mount_point, spath + rootlen); |
1075 | lstat (dpath, &dest_stat); | 1052 | lstat(dpath, &dest_stat); |
1076 | 1053 | ||
1077 | if ( S_ISLNK (source_stat.st_mode) || (source_stat.st_mode & S_ISVTX) ) | 1054 | if (S_ISLNK(source_stat.st_mode) ||(source_stat.st_mode & S_ISVTX)) |
1078 | copy_inode (dpath, &dest_stat, (source_stat.st_mode & ~S_ISVTX) , spath, &source_stat); | 1055 | copy_inode(dpath, &dest_stat,(source_stat.st_mode & ~S_ISVTX) , spath, &source_stat); |
1079 | 1056 | ||
1080 | if ( S_ISDIR (source_stat.st_mode) ) | 1057 | if (S_ISDIR(source_stat.st_mode)) |
1081 | dir_operation(RESTORE, spath, rootlen,NULL); | 1058 | dir_operation(RESTORE, spath, rootlen,NULL); |
1082 | } | 1059 | } |
1083 | 1060 | ||
1084 | 1061 | ||
1085 | static int copy_inode (const char *destpath, const struct stat *dest_stat, | 1062 | static int copy_inode(const char *destpath, const struct stat *dest_stat, |
1086 | mode_t new_mode, | 1063 | mode_t new_mode, |
1087 | const char *sourcepath, const struct stat *source_stat) | 1064 | const char *sourcepath, const struct stat *source_stat) |
1088 | /* [SUMMARY] Copy an inode. | 1065 | /* [SUMMARY] Copy an inode. |
@@ -1102,73 +1079,70 @@ static int copy_inode (const char *destpath, const struct stat *dest_stat, | |||
1102 | 1079 | ||
1103 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1080 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1104 | 1081 | ||
1105 | if ( (source_stat->st_mode & S_IFMT) == (dest_stat->st_mode & S_IFMT) ) | 1082 | if ((source_stat->st_mode & S_IFMT) ==(dest_stat->st_mode & S_IFMT)) { |
1106 | { | ||
1107 | /* Same type */ | 1083 | /* Same type */ |
1108 | if ( S_ISLNK (source_stat->st_mode) ) | 1084 | if (S_ISLNK(source_stat->st_mode)) { |
1109 | { | 1085 | if ((source_len = readlink(sourcepath, source_link, STRING_LENGTH - 1)) < 0 |
1110 | if (( source_len = readlink (sourcepath, source_link, STRING_LENGTH - 1) ) < 0 || | 1086 | || (dest_len = readlink(destpath , dest_link , STRING_LENGTH - 1)) < 0 |
1111 | ( dest_len = readlink (destpath , dest_link , STRING_LENGTH - 1) ) < 0 ) | 1087 | ) |
1112 | return FALSE; | 1088 | return FALSE; |
1113 | source_link[source_len] = '\0'; | 1089 | source_link[source_len] = '\0'; |
1114 | dest_link[dest_len] = '\0'; | 1090 | dest_link[dest_len] = '\0'; |
1115 | if ( (source_len != dest_len) || (strcmp (source_link, dest_link) != 0) ) | 1091 | if ((source_len != dest_len) || (strcmp(source_link, dest_link) != 0)) { |
1116 | { | 1092 | unlink(destpath); |
1117 | unlink (destpath); | 1093 | symlink(source_link, destpath); |
1118 | symlink (source_link, destpath); | ||
1119 | } | 1094 | } |
1120 | return TRUE; | 1095 | return TRUE; |
1121 | } /* Else not a symlink */ | 1096 | } /* Else not a symlink */ |
1122 | chmod (destpath, new_mode & ~S_IFMT); | 1097 | chmod(destpath, new_mode & ~S_IFMT); |
1123 | chown (destpath, source_stat->st_uid, source_stat->st_gid); | 1098 | chown(destpath, source_stat->st_uid, source_stat->st_gid); |
1124 | return TRUE; | 1099 | return TRUE; |
1125 | } | 1100 | } |
1126 | /* Different types: unlink and create */ | 1101 | /* Different types: unlink and create */ |
1127 | unlink (destpath); | 1102 | unlink(destpath); |
1128 | switch (source_stat->st_mode & S_IFMT) | 1103 | switch (source_stat->st_mode & S_IFMT) { |
1129 | { | ||
1130 | case S_IFSOCK: | 1104 | case S_IFSOCK: |
1131 | if ( ( fd = socket (AF_UNIX, SOCK_STREAM, 0) ) < 0 ) | 1105 | if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) |
1132 | break; | 1106 | break; |
1133 | un_addr.sun_family = AF_UNIX; | 1107 | un_addr.sun_family = AF_UNIX; |
1134 | snprintf (un_addr.sun_path, sizeof (un_addr.sun_path), "%s", destpath); | 1108 | snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), "%s", destpath); |
1135 | val = bind (fd, (struct sockaddr *) &un_addr, (int) sizeof un_addr); | 1109 | val = bind(fd,(struct sockaddr *) &un_addr,(int) sizeof un_addr); |
1136 | close (fd); | 1110 | close(fd); |
1137 | if (val != 0 || chmod (destpath, new_mode & ~S_IFMT) != 0) | 1111 | if (val != 0 || chmod(destpath, new_mode & ~S_IFMT) != 0) |
1138 | break; | 1112 | break; |
1139 | goto do_chown; | 1113 | goto do_chown; |
1140 | case S_IFLNK: | 1114 | case S_IFLNK: |
1141 | if ( ( val = readlink (sourcepath, symlink_val, STRING_LENGTH - 1) ) < 0 ) | 1115 | if ((val = readlink(sourcepath, symlink_val, STRING_LENGTH - 1)) < 0) |
1142 | break; | 1116 | break; |
1143 | symlink_val[val] = '\0'; | 1117 | symlink_val[val] = '\0'; |
1144 | if (symlink (symlink_val, destpath) == 0) | 1118 | if (symlink(symlink_val, destpath) == 0) |
1145 | return TRUE; | 1119 | return TRUE; |
1146 | break; | 1120 | break; |
1147 | case S_IFREG: | 1121 | case S_IFREG: |
1148 | if ( ( fd = open (destpath, O_RDONLY | O_CREAT, new_mode & ~S_IFMT) ) < 0 ) | 1122 | if ((fd = open(destpath, O_RDONLY | O_CREAT, new_mode & ~S_IFMT)) < 0) |
1149 | break; | 1123 | break; |
1150 | close (fd); | 1124 | close(fd); |
1151 | if (chmod (destpath, new_mode & ~S_IFMT) != 0) | 1125 | if (chmod(destpath, new_mode & ~S_IFMT) != 0) |
1152 | break; | 1126 | break; |
1153 | goto do_chown; | 1127 | goto do_chown; |
1154 | case S_IFBLK: | 1128 | case S_IFBLK: |
1155 | case S_IFCHR: | 1129 | case S_IFCHR: |
1156 | case S_IFIFO: | 1130 | case S_IFIFO: |
1157 | if (mknod (destpath, new_mode, source_stat->st_rdev) != 0) | 1131 | if (mknod(destpath, new_mode, source_stat->st_rdev) != 0) |
1158 | break; | 1132 | break; |
1159 | goto do_chown; | 1133 | goto do_chown; |
1160 | case S_IFDIR: | 1134 | case S_IFDIR: |
1161 | if (mkdir (destpath, new_mode & ~S_IFMT) != 0) | 1135 | if (mkdir(destpath, new_mode & ~S_IFMT) != 0) |
1162 | break; | 1136 | break; |
1163 | do_chown: | 1137 | do_chown: |
1164 | if (chown (destpath, source_stat->st_uid, source_stat->st_gid) == 0) | 1138 | if (chown(destpath, source_stat->st_uid, source_stat->st_gid) == 0) |
1165 | return TRUE; | 1139 | return TRUE; |
1166 | /*break;*/ | 1140 | /*break;*/ |
1167 | } | 1141 | } |
1168 | return FALSE; | 1142 | return FALSE; |
1169 | } /* End Function copy_inode */ | 1143 | } /* End Function copy_inode */ |
1170 | 1144 | ||
1171 | static void free_config (void) | 1145 | static void free_config(void) |
1172 | /* [SUMMARY] Free the configuration information. | 1146 | /* [SUMMARY] Free the configuration information. |
1173 | [RETURNS] Nothing. | 1147 | [RETURNS] Nothing. |
1174 | */ | 1148 | */ |
@@ -1178,28 +1152,25 @@ static void free_config (void) | |||
1178 | 1152 | ||
1179 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1153 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1180 | 1154 | ||
1181 | for (c_entry = first_config; c_entry != NULL; c_entry = next) | 1155 | for (c_entry = first_config; c_entry != NULL; c_entry = next) { |
1182 | { | ||
1183 | unsigned int count; | 1156 | unsigned int count; |
1184 | 1157 | ||
1185 | next = c_entry->next; | 1158 | next = c_entry->next; |
1186 | regfree (&c_entry->preg); | 1159 | regfree(&c_entry->preg); |
1187 | if (c_entry->action.what == AC_EXECUTE) | 1160 | if (c_entry->action.what == AC_EXECUTE) { |
1188 | { | 1161 | for (count = 0; count < MAX_ARGS; ++count) { |
1189 | for (count = 0; count < MAX_ARGS; ++count) | ||
1190 | { | ||
1191 | if (c_entry->u.execute.argv[count] == NULL) | 1162 | if (c_entry->u.execute.argv[count] == NULL) |
1192 | break; | 1163 | break; |
1193 | free (c_entry->u.execute.argv[count]); | 1164 | free(c_entry->u.execute.argv[count]); |
1194 | } | 1165 | } |
1195 | } | 1166 | } |
1196 | free (c_entry); | 1167 | free(c_entry); |
1197 | } | 1168 | } |
1198 | first_config = NULL; | 1169 | first_config = NULL; |
1199 | last_config = NULL; | 1170 | last_config = NULL; |
1200 | } /* End Function free_config */ | 1171 | } /* End Function free_config */ |
1201 | 1172 | ||
1202 | static int get_uid_gid (int flag, const char *string) | 1173 | static int get_uid_gid(int flag, const char *string) |
1203 | /* [SUMMARY] Convert a string to a UID or GID value. | 1174 | /* [SUMMARY] Convert a string to a UID or GID value. |
1204 | <flag> "UID" or "GID". | 1175 | <flag> "UID" or "GID". |
1205 | <string> The string. | 1176 | <string> The string. |
@@ -1211,30 +1182,30 @@ static int get_uid_gid (int flag, const char *string) | |||
1211 | static const char *msg; | 1182 | static const char *msg; |
1212 | 1183 | ||
1213 | if (ENABLE_DEVFSD_VERBOSE) | 1184 | if (ENABLE_DEVFSD_VERBOSE) |
1214 | msg="user"; | 1185 | msg = "user"; |
1215 | 1186 | ||
1216 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1187 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1217 | 1188 | ||
1218 | if(ENABLE_DEBUG && flag != UID && flag != GID) | 1189 | if (ENABLE_DEBUG && flag != UID && flag != GID) |
1219 | msg_logger_and_die(LOG_ERR,"%s: flag != UID && flag != GID", __FUNCTION__); | 1190 | msg_logger_and_die(LOG_ERR,"%s: flag != UID && flag != GID", __FUNCTION__); |
1220 | 1191 | ||
1221 | if ( isdigit (string[0]) || ( (string[0] == '-') && isdigit (string[1]) ) ) | 1192 | if (isdigit(string[0]) ||((string[0] == '-') && isdigit(string[1]))) |
1222 | return atoi(string); | 1193 | return atoi(string); |
1223 | 1194 | ||
1224 | if ( flag == UID && ( pw_ent = getpwnam (string) ) != NULL ) | 1195 | if (flag == UID && (pw_ent = getpwnam(string)) != NULL) |
1225 | return pw_ent->pw_uid; | 1196 | return pw_ent->pw_uid; |
1226 | 1197 | ||
1227 | if ( flag == GID && ( grp_ent = getgrnam (string) ) != NULL ) | 1198 | if (flag == GID && (grp_ent = getgrnam(string)) != NULL) |
1228 | return grp_ent->gr_gid; | 1199 | return grp_ent->gr_gid; |
1229 | else if(ENABLE_DEVFSD_VERBOSE) | 1200 | else if (ENABLE_DEVFSD_VERBOSE) |
1230 | msg="group"; | 1201 | msg = "group"; |
1231 | 1202 | ||
1232 | if(ENABLE_DEVFSD_VERBOSE) | 1203 | if (ENABLE_DEVFSD_VERBOSE) |
1233 | msg_logger(LOG_ERR,"unknown %s: %s, defaulting to %cid=0", msg, string, msg[0]); | 1204 | msg_logger(LOG_ERR,"unknown %s: %s, defaulting to %cid=0", msg, string, msg[0]); |
1234 | return 0; | 1205 | return 0; |
1235 | }/* End Function get_uid_gid */ | 1206 | }/* End Function get_uid_gid */ |
1236 | 1207 | ||
1237 | static mode_t get_mode (const char *string) | 1208 | static mode_t get_mode(const char *string) |
1238 | /* [SUMMARY] Convert a string to a mode value. | 1209 | /* [SUMMARY] Convert a string to a mode value. |
1239 | <string> The string. | 1210 | <string> The string. |
1240 | [RETURNS] The mode value. | 1211 | [RETURNS] The mode value. |
@@ -1245,24 +1216,23 @@ static mode_t get_mode (const char *string) | |||
1245 | 1216 | ||
1246 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1217 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1247 | 1218 | ||
1248 | if ( isdigit (string[0]) ) | 1219 | if (isdigit(string[0])) |
1249 | return strtoul(string, NULL, 8); | 1220 | return strtoul(string, NULL, 8); |
1250 | if (strlen (string) != 9) | 1221 | if (strlen(string) != 9) |
1251 | msg_logger_and_die(LOG_ERR, "bad mode: %s", string); | 1222 | msg_logger_and_die(LOG_ERR, "bad mode: %s", string); |
1252 | 1223 | ||
1253 | mode = 0; | 1224 | mode = 0; |
1254 | i= S_IRUSR; | 1225 | i = S_IRUSR; |
1255 | while (i>0) | 1226 | while (i > 0) { |
1256 | { | 1227 | if (string[0] == 'r' || string[0] == 'w' || string[0] == 'x') |
1257 | if(string[0]=='r'||string[0]=='w'||string[0]=='x') | 1228 | mode += i; |
1258 | mode+=i; | 1229 | i = i/2; |
1259 | i=i/2; | ||
1260 | string++; | 1230 | string++; |
1261 | } | 1231 | } |
1262 | return mode; | 1232 | return mode; |
1263 | } /* End Function get_mode */ | 1233 | } /* End Function get_mode */ |
1264 | 1234 | ||
1265 | static void signal_handler (int sig) | 1235 | static void signal_handler(int sig) |
1266 | { | 1236 | { |
1267 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1237 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1268 | 1238 | ||
@@ -1273,7 +1243,7 @@ static void signal_handler (int sig) | |||
1273 | msg_logger(LOG_INFO, "Caught signal %d", sig); | 1243 | msg_logger(LOG_INFO, "Caught signal %d", sig); |
1274 | } /* End Function signal_handler */ | 1244 | } /* End Function signal_handler */ |
1275 | 1245 | ||
1276 | static const char *get_variable (const char *variable, void *info) | 1246 | static const char *get_variable(const char *variable, void *info) |
1277 | { | 1247 | { |
1278 | struct get_variable_info *gv_info = info; | 1248 | struct get_variable_info *gv_info = info; |
1279 | static char hostname[STRING_LENGTH], sbuf[STRING_LENGTH]; | 1249 | static char hostname[STRING_LENGTH], sbuf[STRING_LENGTH]; |
@@ -1284,29 +1254,28 @@ static const char *get_variable (const char *variable, void *info) | |||
1284 | 1254 | ||
1285 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1255 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1286 | 1256 | ||
1287 | if (gethostname (hostname, STRING_LENGTH - 1) != 0) | 1257 | if (gethostname(hostname, STRING_LENGTH - 1) != 0) |
1288 | msg_logger_and_die(LOG_ERR, "gethostname: %m"); | 1258 | msg_logger_and_die(LOG_ERR, "gethostname: %m"); |
1289 | 1259 | ||
1290 | /* Here on error we should do exit(RV_SYS_ERROR), instead we do exit(EXIT_FAILURE) */ | 1260 | /* Here on error we should do exit(RV_SYS_ERROR), instead we do exit(EXIT_FAILURE) */ |
1291 | hostname[STRING_LENGTH - 1] = '\0'; | 1261 | hostname[STRING_LENGTH - 1] = '\0'; |
1292 | 1262 | ||
1293 | /* index_in_str_array returns i>=0 */ | 1263 | /* index_in_str_array returns i>=0 */ |
1294 | i=index_in_str_array(field_names, variable); | 1264 | i = index_in_str_array(field_names, variable); |
1295 | 1265 | ||
1296 | if ( i > 6 || i < 0 || (i > 1 && gv_info == NULL)) | 1266 | if (i > 6 || i < 0 || (i > 1 && gv_info == NULL)) |
1297 | return NULL; | 1267 | return NULL; |
1298 | if( i >= 0 && i <= 3) | 1268 | if (i >= 0 && i <= 3) { |
1299 | { | 1269 | debug_msg_logger(LOG_INFO, "%s: i=%d %s", __FUNCTION__, i, field_names[i + 7]); |
1300 | debug_msg_logger(LOG_INFO, "%s: i=%d %s", __FUNCTION__, i ,field_names[i+7]); | 1270 | return field_names[i + 7]; |
1301 | return field_names[i+7]; | ||
1302 | } | 1271 | } |
1303 | 1272 | ||
1304 | if(i == 4 ) | 1273 | if (i == 4) |
1305 | sprintf (sbuf, "%u", gv_info->info->uid); | 1274 | sprintf(sbuf, "%u", gv_info->info->uid); |
1306 | else if(i == 5) | 1275 | else if (i == 5) |
1307 | sprintf (sbuf, "%u", gv_info->info->gid); | 1276 | sprintf(sbuf, "%u", gv_info->info->gid); |
1308 | else if(i == 6) | 1277 | else if (i == 6) |
1309 | sprintf (sbuf, "%o", gv_info->info->mode); | 1278 | sprintf(sbuf, "%o", gv_info->info->mode); |
1310 | 1279 | ||
1311 | debug_msg_logger(LOG_INFO, "%s: %s", __FUNCTION__, sbuf); | 1280 | debug_msg_logger(LOG_INFO, "%s: %s", __FUNCTION__, sbuf); |
1312 | 1281 | ||
@@ -1319,18 +1288,18 @@ static void service(struct stat statbuf, char *path) | |||
1319 | 1288 | ||
1320 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1289 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1321 | 1290 | ||
1322 | memset (&info, 0, sizeof info); | 1291 | memset(&info, 0, sizeof info); |
1323 | info.type = DEVFSD_NOTIFY_REGISTERED; | 1292 | info.type = DEVFSD_NOTIFY_REGISTERED; |
1324 | info.mode = statbuf.st_mode; | 1293 | info.mode = statbuf.st_mode; |
1325 | info.major = major (statbuf.st_rdev); | 1294 | info.major = major(statbuf.st_rdev); |
1326 | info.minor = minor (statbuf.st_rdev); | 1295 | info.minor = minor(statbuf.st_rdev); |
1327 | info.uid = statbuf.st_uid; | 1296 | info.uid = statbuf.st_uid; |
1328 | info.gid = statbuf.st_gid; | 1297 | info.gid = statbuf.st_gid; |
1329 | snprintf (info.devname, sizeof (info.devname), "%s", path + strlen (mount_point) + 1); | 1298 | snprintf(info.devname, sizeof(info.devname), "%s", path + strlen(mount_point) + 1); |
1330 | info.namelen = strlen (info.devname); | 1299 | info.namelen = strlen(info.devname); |
1331 | service_name (&info); | 1300 | service_name(&info); |
1332 | if ( S_ISDIR (statbuf.st_mode) ) | 1301 | if (S_ISDIR(statbuf.st_mode)) |
1333 | dir_operation(SERVICE,path,0,NULL); | 1302 | dir_operation(SERVICE, path, 0, NULL); |
1334 | } | 1303 | } |
1335 | 1304 | ||
1336 | static void dir_operation(int type, const char * dir_name, int var, unsigned long *event_mask) | 1305 | static void dir_operation(int type, const char * dir_name, int var, unsigned long *event_mask) |
@@ -1349,42 +1318,38 @@ static void dir_operation(int type, const char * dir_name, int var, unsigned lon | |||
1349 | 1318 | ||
1350 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1319 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1351 | 1320 | ||
1352 | if((dp = opendir( dir_name))==NULL) | 1321 | if ((dp = opendir(dir_name))==NULL) { |
1353 | { | ||
1354 | debug_msg_logger(LOG_ERR, "opendir: %s: %m", dir_name); | 1322 | debug_msg_logger(LOG_ERR, "opendir: %s: %m", dir_name); |
1355 | return; | 1323 | return; |
1356 | } | 1324 | } |
1357 | 1325 | ||
1358 | while ( (de = readdir (dp) ) != NULL ) | 1326 | while ((de = readdir(dp)) != NULL) { |
1359 | { | ||
1360 | 1327 | ||
1361 | if(de->d_name && DOT_OR_DOTDOT(de->d_name)) | 1328 | if (de->d_name && DOT_OR_DOTDOT(de->d_name)) |
1362 | continue; | 1329 | continue; |
1363 | snprintf (path, sizeof (path), "%s/%s", dir_name, de->d_name); | 1330 | snprintf(path, sizeof(path), "%s/%s", dir_name, de->d_name); |
1364 | debug_msg_logger(LOG_ERR, "%s: %s", __FUNCTION__, path); | 1331 | debug_msg_logger(LOG_ERR, "%s: %s", __FUNCTION__, path); |
1365 | 1332 | ||
1366 | if (lstat (path, &statbuf) != 0) | 1333 | if (lstat(path, &statbuf) != 0) { |
1367 | { | ||
1368 | debug_msg_logger(LOG_ERR, "%s: %s: %m", __FUNCTION__, path); | 1334 | debug_msg_logger(LOG_ERR, "%s: %s: %m", __FUNCTION__, path); |
1369 | continue; | 1335 | continue; |
1370 | } | 1336 | } |
1371 | switch (type) | 1337 | switch (type) { |
1372 | { | ||
1373 | case SERVICE: | 1338 | case SERVICE: |
1374 | service(statbuf,path); | 1339 | service(statbuf, path); |
1375 | break; | 1340 | break; |
1376 | case RESTORE: | 1341 | case RESTORE: |
1377 | restore(path, statbuf, var); | 1342 | restore(path, statbuf, var); |
1378 | break; | 1343 | break; |
1379 | case READ_CONFIG: | 1344 | case READ_CONFIG: |
1380 | read_config_file (path, var, event_mask); | 1345 | read_config_file(path, var, event_mask); |
1381 | break; | 1346 | break; |
1382 | } | 1347 | } |
1383 | } | 1348 | } |
1384 | closedir (dp); | 1349 | closedir(dp); |
1385 | } /* End Function do_scan_and_service */ | 1350 | } /* End Function do_scan_and_service */ |
1386 | 1351 | ||
1387 | static int mksymlink (const char *oldpath, const char *newpath) | 1352 | static int mksymlink(const char *oldpath, const char *newpath) |
1388 | /* [SUMMARY] Create a symlink, creating intervening directories as required. | 1353 | /* [SUMMARY] Create a symlink, creating intervening directories as required. |
1389 | <oldpath> The string contained in the symlink. | 1354 | <oldpath> The string contained in the symlink. |
1390 | <newpath> The name of the new symlink. | 1355 | <newpath> The name of the new symlink. |
@@ -1393,10 +1358,10 @@ static int mksymlink (const char *oldpath, const char *newpath) | |||
1393 | { | 1358 | { |
1394 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1359 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1395 | 1360 | ||
1396 | if ( !make_dir_tree (newpath) ) | 1361 | if (!make_dir_tree(newpath)) |
1397 | return -1; | 1362 | return -1; |
1398 | 1363 | ||
1399 | if (symlink (oldpath, newpath) != 0) { | 1364 | if (symlink(oldpath, newpath) != 0) { |
1400 | if (errno != EEXIST) { | 1365 | if (errno != EEXIST) { |
1401 | debug_msg_logger(LOG_ERR, "%s: %s to %s: %m", __FUNCTION__, oldpath, newpath); | 1366 | debug_msg_logger(LOG_ERR, "%s: %s to %s: %m", __FUNCTION__, oldpath, newpath); |
1402 | return -1; | 1367 | return -1; |
@@ -1406,16 +1371,15 @@ static int mksymlink (const char *oldpath, const char *newpath) | |||
1406 | } /* End Function mksymlink */ | 1371 | } /* End Function mksymlink */ |
1407 | 1372 | ||
1408 | 1373 | ||
1409 | static int make_dir_tree (const char *path) | 1374 | static int make_dir_tree(const char *path) |
1410 | /* [SUMMARY] Creating intervening directories for a path as required. | 1375 | /* [SUMMARY] Creating intervening directories for a path as required. |
1411 | <path> The full pathname (including the leaf node). | 1376 | <path> The full pathname(including the leaf node). |
1412 | [RETURNS] TRUE on success, else FALSE. | 1377 | [RETURNS] TRUE on success, else FALSE. |
1413 | */ | 1378 | */ |
1414 | { | 1379 | { |
1415 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1380 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1416 | 1381 | ||
1417 | if (bb_make_directory( dirname((char *)path), -1, FILEUTILS_RECUR )==-1) | 1382 | if (bb_make_directory(dirname((char *)path), -1, FILEUTILS_RECUR) == -1) { |
1418 | { | ||
1419 | debug_msg_logger(LOG_ERR, "%s: %s: %m",__FUNCTION__, path); | 1383 | debug_msg_logger(LOG_ERR, "%s: %s: %m",__FUNCTION__, path); |
1420 | return FALSE; | 1384 | return FALSE; |
1421 | } | 1385 | } |
@@ -1447,15 +1411,15 @@ static int expand_expression(char *output, unsigned int outsize, | |||
1447 | 1411 | ||
1448 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1412 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1449 | 1413 | ||
1450 | if ( !st_expr_expand (temp, STRING_LENGTH, input, get_variable_func, info) ) | 1414 | if (!st_expr_expand(temp, STRING_LENGTH, input, get_variable_func, info)) |
1451 | return FALSE; | 1415 | return FALSE; |
1452 | expand_regexp (output, outsize, temp, devname, ex, numexp); | 1416 | expand_regexp(output, outsize, temp, devname, ex, numexp); |
1453 | return TRUE; | 1417 | return TRUE; |
1454 | } /* End Function expand_expression */ | 1418 | } /* End Function expand_expression */ |
1455 | 1419 | ||
1456 | static void expand_regexp (char *output, size_t outsize, const char *input, | 1420 | static void expand_regexp(char *output, size_t outsize, const char *input, |
1457 | const char *devname, | 1421 | const char *devname, |
1458 | const regmatch_t *ex, unsigned int numex ) | 1422 | const regmatch_t *ex, unsigned int numex) |
1459 | /* [SUMMARY] Expand all occurrences of the regular subexpressions \0 to \9. | 1423 | /* [SUMMARY] Expand all occurrences of the regular subexpressions \0 to \9. |
1460 | <output> The output expanded expression is written here. | 1424 | <output> The output expanded expression is written here. |
1461 | <outsize> The size of the output buffer. | 1425 | <outsize> The size of the output buffer. |
@@ -1483,25 +1447,21 @@ static void expand_regexp (char *output, size_t outsize, const char *input, | |||
1483 | /* Copy the input string into the output buffer, replacing '\\' with '\' | 1447 | /* Copy the input string into the output buffer, replacing '\\' with '\' |
1484 | and '\0' .. '\9' with subexpressions 0 .. 9, if they exist. Other \x | 1448 | and '\0' .. '\9' with subexpressions 0 .. 9, if they exist. Other \x |
1485 | codes are deleted */ | 1449 | codes are deleted */ |
1486 | while ( (c != '\0') && (outsize != 0) ) | 1450 | while ((c != '\0') && (outsize != 0)) { |
1487 | { | ||
1488 | c = *input; | 1451 | c = *input; |
1489 | ++input; | 1452 | ++input; |
1490 | if (c == '\\') | 1453 | if (c == '\\') { |
1491 | { | ||
1492 | c = *input; | 1454 | c = *input; |
1493 | ++input; | 1455 | ++input; |
1494 | if (c != '\\') | 1456 | if (c != '\\') { |
1495 | { | 1457 | if ((c >= '0') && (c <= last_exp)) { |
1496 | if ((c >= '0') && (c <= last_exp)) | ||
1497 | { | ||
1498 | const regmatch_t *subexp = ex + (c - '0'); | 1458 | const regmatch_t *subexp = ex + (c - '0'); |
1499 | unsigned int sublen = subexp->rm_eo - subexp->rm_so; | 1459 | unsigned int sublen = subexp->rm_eo - subexp->rm_so; |
1500 | 1460 | ||
1501 | /* Range checking */ | 1461 | /* Range checking */ |
1502 | if (sublen > outsize) | 1462 | if (sublen > outsize) |
1503 | sublen = outsize; | 1463 | sublen = outsize; |
1504 | strncpy (output, devname + subexp->rm_so, sublen); | 1464 | strncpy(output, devname + subexp->rm_so, sublen); |
1505 | output += sublen; | 1465 | output += sublen; |
1506 | outsize -= sublen; | 1466 | outsize -= sublen; |
1507 | } | 1467 | } |
@@ -1519,9 +1479,9 @@ static void expand_regexp (char *output, size_t outsize, const char *input, | |||
1519 | 1479 | ||
1520 | struct translate_struct | 1480 | struct translate_struct |
1521 | { | 1481 | { |
1522 | const char *match; /* The string to match to (up to length) */ | 1482 | const char *match; /* The string to match to(up to length) */ |
1523 | const char *format; /* Format of output, "%s" takes data past match string, | 1483 | const char *format; /* Format of output, "%s" takes data past match string, |
1524 | NULL is effectively "%s" (just more efficient) */ | 1484 | NULL is effectively "%s"(just more efficient) */ |
1525 | }; | 1485 | }; |
1526 | 1486 | ||
1527 | static struct translate_struct translate_table[] = | 1487 | static struct translate_struct translate_table[] = |
@@ -1557,7 +1517,7 @@ static struct translate_struct translate_table[] = | |||
1557 | {NULL, NULL} | 1517 | {NULL, NULL} |
1558 | }; | 1518 | }; |
1559 | 1519 | ||
1560 | const char *get_old_name (const char *devname, unsigned int namelen, | 1520 | const char *get_old_name(const char *devname, unsigned int namelen, |
1561 | char *buffer, unsigned int major, unsigned int minor) | 1521 | char *buffer, unsigned int major, unsigned int minor) |
1562 | /* [SUMMARY] Translate a kernel-supplied name into an old name. | 1522 | /* [SUMMARY] Translate a kernel-supplied name into an old name. |
1563 | <devname> The device name provided by the kernel. | 1523 | <devname> The device name provided by the kernel. |
@@ -1597,23 +1557,21 @@ const char *get_old_name (const char *devname, unsigned int namelen, | |||
1597 | 1557 | ||
1598 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1558 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1599 | 1559 | ||
1600 | for (trans = translate_table; trans->match != NULL; ++trans) | 1560 | for (trans = translate_table; trans->match != NULL; ++trans) { |
1601 | { | 1561 | len = strlen(trans->match); |
1602 | len = strlen (trans->match); | ||
1603 | 1562 | ||
1604 | if (strncmp (devname, trans->match, len) == 0) | 1563 | if (strncmp(devname, trans->match, len) == 0) { |
1605 | { | ||
1606 | if (trans->format == NULL) | 1564 | if (trans->format == NULL) |
1607 | return devname + len; | 1565 | return devname + len; |
1608 | sprintf (buffer, trans->format, devname + len); | 1566 | sprintf(buffer, trans->format, devname + len); |
1609 | return buffer; | 1567 | return buffer; |
1610 | } | 1568 | } |
1611 | } | 1569 | } |
1612 | 1570 | ||
1613 | ptr = (strrchr (devname, '/') + 1); | 1571 | ptr = (strrchr(devname, '/') + 1); |
1614 | i = scan_dev_name(devname, namelen, ptr); | 1572 | i = scan_dev_name(devname, namelen, ptr); |
1615 | 1573 | ||
1616 | if( i > 0 && i < 13) | 1574 | if (i > 0 && i < 13) |
1617 | compat_name = buffer; | 1575 | compat_name = buffer; |
1618 | else | 1576 | else |
1619 | return NULL; | 1577 | return NULL; |
@@ -1621,90 +1579,86 @@ const char *get_old_name (const char *devname, unsigned int namelen, | |||
1621 | debug_msg_logger(LOG_INFO, "%s: scan_dev_name = %d", __FUNCTION__, i); | 1579 | debug_msg_logger(LOG_INFO, "%s: scan_dev_name = %d", __FUNCTION__, i); |
1622 | 1580 | ||
1623 | /* 1 == scsi/generic, 3 == scsi/cd, 10 == sbp/ */ | 1581 | /* 1 == scsi/generic, 3 == scsi/cd, 10 == sbp/ */ |
1624 | if( i == 1 || i == 3 || i == 10 ) | 1582 | if (i == 1 || i == 3 || i == 10) |
1625 | sprintf (buffer, fmt[i], minor); | 1583 | sprintf(buffer, fmt[i], minor); |
1626 | 1584 | ||
1627 | /* 2 ==scsi/disc, 4 == scsi/part */ | 1585 | /* 2 ==scsi/disc, 4 == scsi/part */ |
1628 | if( i == 2 || i == 4) | 1586 | if (i == 2 || i == 4) |
1629 | compat_name = write_old_sd_name (buffer, major, minor,((i == 2)?"":(ptr + 4))); | 1587 | compat_name = write_old_sd_name(buffer, major, minor,((i == 2)?"":(ptr + 4))); |
1630 | 1588 | ||
1631 | /* 5 == scsi/mt */ | 1589 | /* 5 == scsi/mt */ |
1632 | if( i == 5) | 1590 | if (i == 5) { |
1633 | { | ||
1634 | mode = ptr[2]; | 1591 | mode = ptr[2]; |
1635 | if (mode == 'n') | 1592 | if (mode == 'n') |
1636 | mode = '\0'; | 1593 | mode = '\0'; |
1637 | sprintf (buffer, fmt[i], minor & 0x1f, mode); | 1594 | sprintf(buffer, fmt[i], minor & 0x1f, mode); |
1638 | if (devname[namelen - 1] != 'n') | 1595 | if (devname[namelen - 1] != 'n') |
1639 | ++compat_name; | 1596 | ++compat_name; |
1640 | } | 1597 | } |
1641 | /* 6 == ide/host/disc, 7 == ide/host/cd, 8 == ide/host/part */ | 1598 | /* 6 == ide/host/disc, 7 == ide/host/cd, 8 == ide/host/part */ |
1642 | if( i == 6 || i == 7 || i == 8 ) | 1599 | if (i == 6 || i == 7 || i == 8) |
1643 | /* last arg should be ignored for i == 6 or i== 7 */ | 1600 | /* last arg should be ignored for i == 6 or i== 7 */ |
1644 | sprintf (buffer, fmt[i] , get_old_ide_name (major, minor), ptr + 4); | 1601 | sprintf(buffer, fmt[i] , get_old_ide_name(major, minor), ptr + 4); |
1645 | 1602 | ||
1646 | /* 9 == ide/host/mt */ | 1603 | /* 9 == ide/host/mt */ |
1647 | if( i == 9 ) | 1604 | if (i == 9) |
1648 | sprintf (buffer, fmt[i], ptr + 2, minor & 0x7f); | 1605 | sprintf(buffer, fmt[i], ptr + 2, minor & 0x7f); |
1649 | 1606 | ||
1650 | /* 11 == vcc/ */ | 1607 | /* 11 == vcc/ */ |
1651 | if( i == 11 ) | 1608 | if (i == 11) { |
1652 | { | 1609 | sprintf(buffer, fmt[i], devname + 4); |
1653 | sprintf (buffer, fmt[i], devname + 4); | ||
1654 | if (buffer[3] == '0') | 1610 | if (buffer[3] == '0') |
1655 | buffer[3] = '\0'; | 1611 | buffer[3] = '\0'; |
1656 | } | 1612 | } |
1657 | /* 12 == pty/ */ | 1613 | /* 12 == pty/ */ |
1658 | if( i == 12 ) | 1614 | if (i == 12) { |
1659 | { | ||
1660 | pty1 = "pqrstuvwxyzabcde"; | 1615 | pty1 = "pqrstuvwxyzabcde"; |
1661 | pty2 = "0123456789abcdef"; | 1616 | pty2 = "0123456789abcdef"; |
1662 | indexx = atoi (devname + 5); | 1617 | indexx = atoi(devname + 5); |
1663 | sprintf (buffer, fmt[i], (devname[4] == 'm') ? 'p' : 't', pty1[indexx >> 4], pty2[indexx & 0x0f]); | 1618 | sprintf(buffer, fmt[i], (devname[4] == 'm') ? 'p' : 't', pty1[indexx >> 4], pty2[indexx & 0x0f]); |
1664 | } | 1619 | } |
1665 | 1620 | ||
1666 | if(ENABLE_DEBUG && compat_name!=NULL) | 1621 | if (ENABLE_DEBUG && compat_name != NULL) |
1667 | msg_logger(LOG_INFO, "%s: compat_name %s", __FUNCTION__, compat_name); | 1622 | msg_logger(LOG_INFO, "%s: compat_name %s", __FUNCTION__, compat_name); |
1668 | 1623 | ||
1669 | return compat_name; | 1624 | return compat_name; |
1670 | } /* End Function get_old_name */ | 1625 | } /* End Function get_old_name */ |
1671 | 1626 | ||
1672 | static char get_old_ide_name (unsigned int major, unsigned int minor) | 1627 | static char get_old_ide_name(unsigned int major, unsigned int minor) |
1673 | /* [SUMMARY] Get the old IDE name for a device. | 1628 | /* [SUMMARY] Get the old IDE name for a device. |
1674 | <major> The major number for the device. | 1629 | <major> The major number for the device. |
1675 | <minor> The minor number for the device. | 1630 | <minor> The minor number for the device. |
1676 | [RETURNS] The drive letter. | 1631 | [RETURNS] The drive letter. |
1677 | */ | 1632 | */ |
1678 | { | 1633 | { |
1679 | char letter='y'; /* 121 */ | 1634 | char letter = 'y'; /* 121 */ |
1680 | char c='a'; /* 97 */ | 1635 | char c = 'a'; /* 97 */ |
1681 | int i=IDE0_MAJOR; | 1636 | int i = IDE0_MAJOR; |
1682 | 1637 | ||
1683 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1638 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1684 | 1639 | ||
1685 | /* I hope it works like the previous code as it saves a few bytes. Tito ;P */ | 1640 | /* I hope it works like the previous code as it saves a few bytes. Tito ;P */ |
1686 | do { | 1641 | do { |
1687 | if( i==IDE0_MAJOR || i==IDE1_MAJOR || i==IDE2_MAJOR || | 1642 | if (i == IDE0_MAJOR || i == IDE1_MAJOR || i == IDE2_MAJOR |
1688 | i==IDE3_MAJOR || i==IDE4_MAJOR || i==IDE5_MAJOR || | 1643 | || i == IDE3_MAJOR || i == IDE4_MAJOR || i == IDE5_MAJOR |
1689 | i==IDE6_MAJOR || i==IDE7_MAJOR || i==IDE8_MAJOR || | 1644 | || i == IDE6_MAJOR || i == IDE7_MAJOR || i == IDE8_MAJOR |
1690 | i==IDE9_MAJOR ) | 1645 | || i == IDE9_MAJOR |
1691 | { | 1646 | ) { |
1692 | if((unsigned int)i==major) | 1647 | if ((unsigned int)i == major) { |
1693 | { | 1648 | letter = c; |
1694 | letter=c; | ||
1695 | break; | 1649 | break; |
1696 | } | 1650 | } |
1697 | c+=2; | 1651 | c += 2; |
1698 | } | 1652 | } |
1699 | i++; | 1653 | i++; |
1700 | } while (i<=IDE9_MAJOR); | 1654 | } while (i <= IDE9_MAJOR); |
1701 | 1655 | ||
1702 | if (minor > 63) | 1656 | if (minor > 63) |
1703 | ++letter; | 1657 | ++letter; |
1704 | return letter; | 1658 | return letter; |
1705 | } /* End Function get_old_ide_name */ | 1659 | } /* End Function get_old_ide_name */ |
1706 | 1660 | ||
1707 | static char *write_old_sd_name (char *buffer, | 1661 | static char *write_old_sd_name(char *buffer, |
1708 | unsigned int major, unsigned int minor, | 1662 | unsigned int major, unsigned int minor, |
1709 | const char *part) | 1663 | const char *part) |
1710 | /* [SUMMARY] Write the old SCSI disc name to a buffer. | 1664 | /* [SUMMARY] Write the old SCSI disc name to a buffer. |
@@ -1719,18 +1673,16 @@ static char *write_old_sd_name (char *buffer, | |||
1719 | 1673 | ||
1720 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1674 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1721 | 1675 | ||
1722 | if (major == 8) | 1676 | if (major == 8) { |
1723 | { | 1677 | sprintf(buffer, "sd%c%s", 'a' + (minor >> 4), part); |
1724 | sprintf (buffer, "sd%c%s", 'a' + (minor >> 4), part); | ||
1725 | return buffer; | 1678 | return buffer; |
1726 | } | 1679 | } |
1727 | if ( (major > 64) && (major < 72) ) | 1680 | if ((major > 64) && (major < 72)) { |
1728 | { | 1681 | disc_index = ((major - 64) << 4) +(minor >> 4); |
1729 | disc_index = ( (major - 64) << 4 ) + (minor >> 4); | ||
1730 | if (disc_index < 26) | 1682 | if (disc_index < 26) |
1731 | sprintf (buffer, "sd%c%s", 'a' + disc_index, part); | 1683 | sprintf(buffer, "sd%c%s", 'a' + disc_index, part); |
1732 | else | 1684 | else |
1733 | sprintf (buffer, "sd%c%c%s", 'a' + (disc_index / 26) - 1, 'a' + disc_index % 26,part); | 1685 | sprintf(buffer, "sd%c%c%s", 'a' +(disc_index / 26) - 1, 'a' + disc_index % 26, part); |
1734 | return buffer; | 1686 | return buffer; |
1735 | } | 1687 | } |
1736 | return NULL; | 1688 | return NULL; |
@@ -1741,8 +1693,8 @@ static char *write_old_sd_name (char *buffer, | |||
1741 | 1693 | ||
1742 | /*EXPERIMENTAL_FUNCTION*/ | 1694 | /*EXPERIMENTAL_FUNCTION*/ |
1743 | 1695 | ||
1744 | int st_expr_expand (char *output, unsigned int length, const char *input, | 1696 | int st_expr_expand(char *output, unsigned int length, const char *input, |
1745 | const char *(*get_variable_func) (const char *variable, | 1697 | const char *(*get_variable_func)(const char *variable, |
1746 | void *info), | 1698 | void *info), |
1747 | void *info) | 1699 | void *info) |
1748 | /* [SUMMARY] Expand an expression using Borne Shell-like unquoted rules. | 1700 | /* [SUMMARY] Expand an expression using Borne Shell-like unquoted rules. |
@@ -1768,51 +1720,46 @@ int st_expr_expand (char *output, unsigned int length, const char *input, | |||
1768 | 1720 | ||
1769 | if (length > BUFFER_SIZE) | 1721 | if (length > BUFFER_SIZE) |
1770 | length = BUFFER_SIZE; | 1722 | length = BUFFER_SIZE; |
1771 | for (; TRUE; ++input) | 1723 | for (; TRUE; ++input) { |
1772 | { | 1724 | switch (ch = *input) { |
1773 | switch (ch = *input) | ||
1774 | { | ||
1775 | case '$': | 1725 | case '$': |
1776 | /* Variable expansion */ | 1726 | /* Variable expansion */ |
1777 | input = expand_variable (buffer, length, &out_pos, ++input, get_variable_func, info); | 1727 | input = expand_variable(buffer, length, &out_pos, ++input, get_variable_func, info); |
1778 | if (input == NULL) | 1728 | if (input == NULL) |
1779 | return FALSE; | 1729 | return FALSE; |
1780 | break; | 1730 | break; |
1781 | case '~': | 1731 | case '~': |
1782 | /* Home directory expansion */ | 1732 | /* Home directory expansion */ |
1783 | ch = input[1]; | 1733 | ch = input[1]; |
1784 | if ( isspace (ch) || (ch == '/') || (ch == '\0') ) | 1734 | if (isspace(ch) ||(ch == '/') ||(ch == '\0')) { |
1785 | { | ||
1786 | /* User's own home directory: leave separator for next time */ | 1735 | /* User's own home directory: leave separator for next time */ |
1787 | if ( ( env = getenv ("HOME") ) == NULL ) | 1736 | if ((env = getenv("HOME")) == NULL) { |
1788 | { | ||
1789 | msg_logger(LOG_INFO, bb_msg_variable_not_found, "HOME"); | 1737 | msg_logger(LOG_INFO, bb_msg_variable_not_found, "HOME"); |
1790 | return FALSE; | 1738 | return FALSE; |
1791 | } | 1739 | } |
1792 | len = strlen (env); | 1740 | len = strlen(env); |
1793 | if (len + out_pos >= length) | 1741 | if (len + out_pos >= length) |
1794 | goto st_expr_expand_out; | 1742 | goto st_expr_expand_out; |
1795 | memcpy (buffer + out_pos, env, len + 1); | 1743 | memcpy(buffer + out_pos, env, len + 1); |
1796 | out_pos += len; | 1744 | out_pos += len; |
1797 | continue; | 1745 | continue; |
1798 | } | 1746 | } |
1799 | /* Someone else's home directory */ | 1747 | /* Someone else's home directory */ |
1800 | for (ptr = ++input; !isspace (ch) && (ch != '/') && (ch != '\0'); ch = *++ptr) | 1748 | for (ptr = ++input; !isspace(ch) && (ch != '/') && (ch != '\0'); ch = *++ptr) |
1801 | /* VOID */ ; | 1749 | /* VOID */ ; |
1802 | len = ptr - input; | 1750 | len = ptr - input; |
1803 | if (len >= sizeof tmp) | 1751 | if (len >= sizeof tmp) |
1804 | goto st_expr_expand_out; | 1752 | goto st_expr_expand_out; |
1805 | safe_memcpy (tmp, input, len); | 1753 | safe_memcpy(tmp, input, len); |
1806 | input = ptr - 1; | 1754 | input = ptr - 1; |
1807 | if ( ( pwent = getpwnam (tmp) ) == NULL ) | 1755 | if ((pwent = getpwnam(tmp)) == NULL) { |
1808 | { | ||
1809 | msg_logger(LOG_INFO, "no pwent for: %s", tmp); | 1756 | msg_logger(LOG_INFO, "no pwent for: %s", tmp); |
1810 | return FALSE; | 1757 | return FALSE; |
1811 | } | 1758 | } |
1812 | len = strlen (pwent->pw_dir); | 1759 | len = strlen(pwent->pw_dir); |
1813 | if (len + out_pos >= length) | 1760 | if (len + out_pos >= length) |
1814 | goto st_expr_expand_out; | 1761 | goto st_expr_expand_out; |
1815 | memcpy (buffer + out_pos, pwent->pw_dir, len + 1); | 1762 | memcpy(buffer + out_pos, pwent->pw_dir, len + 1); |
1816 | out_pos += len; | 1763 | out_pos += len; |
1817 | break; | 1764 | break; |
1818 | case '\0': | 1765 | case '\0': |
@@ -1821,9 +1768,8 @@ int st_expr_expand (char *output, unsigned int length, const char *input, | |||
1821 | if (out_pos >= length) | 1768 | if (out_pos >= length) |
1822 | goto st_expr_expand_out; | 1769 | goto st_expr_expand_out; |
1823 | buffer[out_pos++] = ch; | 1770 | buffer[out_pos++] = ch; |
1824 | if (ch == '\0') | 1771 | if (ch == '\0') { |
1825 | { | 1772 | memcpy(output, buffer, out_pos); |
1826 | memcpy (output, buffer, out_pos); | ||
1827 | return TRUE; | 1773 | return TRUE; |
1828 | } | 1774 | } |
1829 | break; | 1775 | break; |
@@ -1839,9 +1785,9 @@ st_expr_expand_out: | |||
1839 | 1785 | ||
1840 | /* Private functions follow */ | 1786 | /* Private functions follow */ |
1841 | 1787 | ||
1842 | static const char *expand_variable (char *buffer, unsigned int length, | 1788 | static const char *expand_variable(char *buffer, unsigned int length, |
1843 | unsigned int *out_pos, const char *input, | 1789 | unsigned int *out_pos, const char *input, |
1844 | const char *(*func) (const char *variable, | 1790 | const char *(*func)(const char *variable, |
1845 | void *info), | 1791 | void *info), |
1846 | void *info) | 1792 | void *info) |
1847 | /* [SUMMARY] Expand a variable. | 1793 | /* [SUMMARY] Expand a variable. |
@@ -1866,62 +1812,57 @@ static const char *expand_variable (char *buffer, unsigned int length, | |||
1866 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1812 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
1867 | 1813 | ||
1868 | ch = input[0]; | 1814 | ch = input[0]; |
1869 | if (ch == '$') | 1815 | if (ch == '$') { |
1870 | { | ||
1871 | /* Special case for "$$": PID */ | 1816 | /* Special case for "$$": PID */ |
1872 | sprintf ( tmp, "%d", (int) getpid () ); | 1817 | sprintf(tmp, "%d",(int) getpid()); |
1873 | len = strlen (tmp); | 1818 | len = strlen(tmp); |
1874 | if (len + *out_pos >= length) | 1819 | if (len + *out_pos >= length) |
1875 | goto expand_variable_out; | 1820 | goto expand_variable_out; |
1876 | 1821 | ||
1877 | memcpy (buffer + *out_pos, tmp, len + 1); | 1822 | memcpy(buffer + *out_pos, tmp, len + 1); |
1878 | out_pos += len; | 1823 | out_pos += len; |
1879 | return input; | 1824 | return input; |
1880 | } | 1825 | } |
1881 | /* Ordinary variable expansion, possibly in braces */ | 1826 | /* Ordinary variable expansion, possibly in braces */ |
1882 | if (ch != '{') | 1827 | if (ch != '{') { |
1883 | { | ||
1884 | /* Simple variable expansion */ | 1828 | /* Simple variable expansion */ |
1885 | for (ptr = input; isalnum (ch) || (ch == '_') || (ch == ':');ch = *++ptr) | 1829 | for (ptr = input; isalnum(ch) || (ch == '_') || (ch == ':'); ch = *++ptr) |
1886 | /* VOID */ ; | 1830 | /* VOID */ ; |
1887 | len = ptr - input; | 1831 | len = ptr - input; |
1888 | if ((size_t)len >= sizeof tmp) | 1832 | if ((size_t)len >= sizeof tmp) |
1889 | goto expand_variable_out; | 1833 | goto expand_variable_out; |
1890 | 1834 | ||
1891 | safe_memcpy (tmp, input, len); | 1835 | safe_memcpy(tmp, input, len); |
1892 | input = ptr - 1; | 1836 | input = ptr - 1; |
1893 | if ( ( env = get_variable_v2 (tmp, func, info) ) == NULL ) | 1837 | if ((env = get_variable_v2(tmp, func, info)) == NULL) { |
1894 | { | ||
1895 | msg_logger(LOG_INFO, bb_msg_variable_not_found, tmp); | 1838 | msg_logger(LOG_INFO, bb_msg_variable_not_found, tmp); |
1896 | return NULL; | 1839 | return NULL; |
1897 | } | 1840 | } |
1898 | len = strlen (env); | 1841 | len = strlen(env); |
1899 | if (len + *out_pos >= length) | 1842 | if (len + *out_pos >= length) |
1900 | goto expand_variable_out; | 1843 | goto expand_variable_out; |
1901 | 1844 | ||
1902 | memcpy (buffer + *out_pos, env, len + 1); | 1845 | memcpy(buffer + *out_pos, env, len + 1); |
1903 | *out_pos += len; | 1846 | *out_pos += len; |
1904 | return input; | 1847 | return input; |
1905 | } | 1848 | } |
1906 | /* Variable in braces: check for ':' tricks */ | 1849 | /* Variable in braces: check for ':' tricks */ |
1907 | ch = *++input; | 1850 | ch = *++input; |
1908 | for (ptr = input; isalnum (ch) || (ch == '_'); ch = *++ptr) | 1851 | for (ptr = input; isalnum(ch) || (ch == '_'); ch = *++ptr) |
1909 | /* VOID */; | 1852 | /* VOID */; |
1910 | if (ch == '}') | 1853 | if (ch == '}') { |
1911 | { | ||
1912 | /* Must be simple variable expansion with "${var}" */ | 1854 | /* Must be simple variable expansion with "${var}" */ |
1913 | len = ptr - input; | 1855 | len = ptr - input; |
1914 | if ((size_t)len >= sizeof tmp) | 1856 | if ((size_t)len >= sizeof tmp) |
1915 | goto expand_variable_out; | 1857 | goto expand_variable_out; |
1916 | 1858 | ||
1917 | safe_memcpy (tmp, input, len); | 1859 | safe_memcpy(tmp, input, len); |
1918 | ptr = expand_variable (buffer, length, out_pos, tmp, func, info ); | 1860 | ptr = expand_variable(buffer, length, out_pos, tmp, func, info); |
1919 | if (ptr == NULL) | 1861 | if (ptr == NULL) |
1920 | return NULL; | 1862 | return NULL; |
1921 | return input + len; | 1863 | return input + len; |
1922 | } | 1864 | } |
1923 | if (ch != ':' || ptr[1] != '-' ) | 1865 | if (ch != ':' || ptr[1] != '-') { |
1924 | { | ||
1925 | msg_logger(LOG_INFO, "illegal char in var name"); | 1866 | msg_logger(LOG_INFO, "illegal char in var name"); |
1926 | return NULL; | 1867 | return NULL; |
1927 | } | 1868 | } |
@@ -1930,16 +1871,14 @@ static const char *expand_variable (char *buffer, unsigned int length, | |||
1930 | if ((size_t)len >= sizeof tmp) | 1871 | if ((size_t)len >= sizeof tmp) |
1931 | goto expand_variable_out; | 1872 | goto expand_variable_out; |
1932 | 1873 | ||
1933 | safe_memcpy (tmp, input, len); | 1874 | safe_memcpy(tmp, input, len); |
1934 | /* Move input pointer to ':' */ | 1875 | /* Move input pointer to ':' */ |
1935 | input = ptr; | 1876 | input = ptr; |
1936 | /* First skip to closing brace, taking note of nested expressions */ | 1877 | /* First skip to closing brace, taking note of nested expressions */ |
1937 | ptr += 2; | 1878 | ptr += 2; |
1938 | ch = ptr[0]; | 1879 | ch = ptr[0]; |
1939 | for (open_braces = 1; open_braces > 0; ch = *++ptr) | 1880 | for (open_braces = 1; open_braces > 0; ch = *++ptr) { |
1940 | { | 1881 | switch (ch) { |
1941 | switch (ch) | ||
1942 | { | ||
1943 | case '{': | 1882 | case '{': |
1944 | ++open_braces; | 1883 | ++open_braces; |
1945 | break; | 1884 | break; |
@@ -1955,16 +1894,15 @@ static const char *expand_variable (char *buffer, unsigned int length, | |||
1955 | } | 1894 | } |
1956 | --ptr; | 1895 | --ptr; |
1957 | /* At this point ptr should point to closing brace of "${var:-word}" */ | 1896 | /* At this point ptr should point to closing brace of "${var:-word}" */ |
1958 | if ( ( env = get_variable_v2 (tmp, func, info) ) != NULL ) | 1897 | if ((env = get_variable_v2(tmp, func, info)) != NULL) { |
1959 | { | ||
1960 | /* Found environment variable, so skip the input to the closing brace | 1898 | /* Found environment variable, so skip the input to the closing brace |
1961 | and return the variable */ | 1899 | and return the variable */ |
1962 | input = ptr; | 1900 | input = ptr; |
1963 | len = strlen (env); | 1901 | len = strlen(env); |
1964 | if (len + *out_pos >= length) | 1902 | if (len + *out_pos >= length) |
1965 | goto expand_variable_out; | 1903 | goto expand_variable_out; |
1966 | 1904 | ||
1967 | memcpy (buffer + *out_pos, env, len + 1); | 1905 | memcpy(buffer + *out_pos, env, len + 1); |
1968 | *out_pos += len; | 1906 | *out_pos += len; |
1969 | return input; | 1907 | return input; |
1970 | } | 1908 | } |
@@ -1975,15 +1913,15 @@ static const char *expand_variable (char *buffer, unsigned int length, | |||
1975 | if ((size_t)len >= sizeof tmp) | 1913 | if ((size_t)len >= sizeof tmp) |
1976 | goto expand_variable_out; | 1914 | goto expand_variable_out; |
1977 | 1915 | ||
1978 | safe_memcpy (tmp, input, len); | 1916 | safe_memcpy(tmp, input, len); |
1979 | input = ptr; | 1917 | input = ptr; |
1980 | if ( !st_expr_expand (tmp, STRING_LENGTH, tmp, func, info ) ) | 1918 | if (!st_expr_expand(tmp, STRING_LENGTH, tmp, func, info)) |
1981 | return NULL; | 1919 | return NULL; |
1982 | len = strlen (tmp); | 1920 | len = strlen(tmp); |
1983 | if (len + *out_pos >= length) | 1921 | if (len + *out_pos >= length) |
1984 | goto expand_variable_out; | 1922 | goto expand_variable_out; |
1985 | 1923 | ||
1986 | memcpy (buffer + *out_pos, tmp, len + 1); | 1924 | memcpy(buffer + *out_pos, tmp, len + 1); |
1987 | *out_pos += len; | 1925 | *out_pos += len; |
1988 | return input; | 1926 | return input; |
1989 | expand_variable_out: | 1927 | expand_variable_out: |
@@ -1992,8 +1930,8 @@ expand_variable_out: | |||
1992 | } /* End Function expand_variable */ | 1930 | } /* End Function expand_variable */ |
1993 | 1931 | ||
1994 | 1932 | ||
1995 | static const char *get_variable_v2 (const char *variable, | 1933 | static const char *get_variable_v2(const char *variable, |
1996 | const char *(*func) (const char *variable, void *info), | 1934 | const char *(*func)(const char *variable, void *info), |
1997 | void *info) | 1935 | void *info) |
1998 | /* [SUMMARY] Get a variable from the environment or . | 1936 | /* [SUMMARY] Get a variable from the environment or . |
1999 | <variable> The variable name. | 1937 | <variable> The variable name. |
@@ -2007,9 +1945,8 @@ static const char *get_variable_v2 (const char *variable, | |||
2007 | 1945 | ||
2008 | debug_msg_logger(LOG_INFO, __FUNCTION__); | 1946 | debug_msg_logger(LOG_INFO, __FUNCTION__); |
2009 | 1947 | ||
2010 | if (func != NULL) | 1948 | if (func != NULL) { |
2011 | { | 1949 | value = (*func)(variable, info); |
2012 | value = (*func) (variable, info); | ||
2013 | if (value != NULL) | 1950 | if (value != NULL) |
2014 | return value; | 1951 | return value; |
2015 | } | 1952 | } |
diff --git a/shell/ash.c b/shell/ash.c index d9fe64121..f33ff4d8e 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -6986,7 +6986,7 @@ typecmd(int argc, char **argv) | |||
6986 | int verbose = 1; | 6986 | int verbose = 1; |
6987 | 6987 | ||
6988 | /* type -p ... ? (we don't bother checking for 'p') */ | 6988 | /* type -p ... ? (we don't bother checking for 'p') */ |
6989 | if (argv[1][0] == '-') { | 6989 | if (argv[1] && argv[1][0] == '-') { |
6990 | i++; | 6990 | i++; |
6991 | verbose = 0; | 6991 | verbose = 0; |
6992 | } | 6992 | } |