aboutsummaryrefslogtreecommitdiff
path: root/applets
diff options
context:
space:
mode:
Diffstat (limited to 'applets')
-rw-r--r--applets/applets.c67
1 files changed, 28 insertions, 39 deletions
diff --git a/applets/applets.c b/applets/applets.c
index 3441a7886..2f677372d 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -403,44 +403,32 @@ static void check_suid(const struct bb_applet *applet)
403 403
404static const char *unpack_usage_messages(void) 404static const char *unpack_usage_messages(void)
405{ 405{
406 int input[2], output[2], pid; 406 char *outbuf = NULL;
407 char *buf; 407 bunzip_data *bd;
408 408 int i;
409 if (pipe(input) < 0 || pipe(output) < 0)
410 exit(1);
411
412//TODO: not NOMMU friendly!
413 pid = fork();
414 switch (pid) {
415 case -1: /* error */
416 exit(1);
417 case 0: /* child */
418 close(input[1]);
419 close(output[0]);
420 uncompressStream(input[0], output[1]);
421 exit(0);
422 }
423 /* parent */
424
425 close(input[0]);
426 close(output[1]);
427 pid = fork();
428 switch (pid) {
429 case -1: /* error */
430 exit(1);
431 case 0: /* child */
432 full_write(input[1], packed_usage, sizeof(packed_usage));
433 exit(0);
434 }
435 /* parent */
436 close(input[1]);
437 409
438 buf = xmalloc(SIZEOF_usage_messages); 410 i = start_bunzip(&bd,
439 full_read(output[0], buf, SIZEOF_usage_messages); 411 /* src_fd: */ -1,
440 return buf; 412 /* inbuf: */ packed_usage,
413 /* len: */ sizeof(packed_usage));
414 /* read_bunzip can longjmp to start_bunzip, and ultimately
415 * end up here with i != 0 on read data errors! Not trivial */
416 if (!i) {
417 /* Cannot use xmalloc: will leak bd in NOFORK case! */
418 outbuf = malloc_or_warn(SIZEOF_usage_messages);
419 if (outbuf)
420 read_bunzip(bd, outbuf, SIZEOF_usage_messages);
421 }
422 dealloc_bunzip(bd);
423 return outbuf;
441} 424}
425#define dealloc_usage_messages(s) free(s)
426
442#else 427#else
428
443#define unpack_usage_messages() usage_messages 429#define unpack_usage_messages() usage_messages
430#define dealloc_usage_messages(s) ((void)(s))
431
444#endif /* FEATURE_COMPRESS_USAGE */ 432#endif /* FEATURE_COMPRESS_USAGE */
445 433
446 434
@@ -448,22 +436,23 @@ void bb_show_usage(void)
448{ 436{
449 if (ENABLE_SHOW_USAGE) { 437 if (ENABLE_SHOW_USAGE) {
450 const char *format_string; 438 const char *format_string;
451 const char *usage_string = unpack_usage_messages(); 439 const char *p;
440 const char *usage_string = p = unpack_usage_messages();
452 int i; 441 int i;
453 442
454 i = current_applet - applets; 443 i = current_applet - applets;
455 while (i) { 444 while (i) {
456 while (*usage_string++) continue; 445 while (*p++) continue;
457 i--; 446 i--;
458 } 447 }
459 448
460 format_string = "%s\n\nUsage: %s %s\n\n"; 449 format_string = "%s\n\nUsage: %s %s\n\n";
461 if (*usage_string == '\b') 450 if (*p == '\b')
462 format_string = "%s\n\nNo help available.\n\n"; 451 format_string = "%s\n\nNo help available.\n\n";
463 fprintf(stderr, format_string, bb_msg_full_version, 452 fprintf(stderr, format_string, bb_msg_full_version,
464 applet_name, usage_string); 453 applet_name, p);
454 dealloc_usage_messages((char*)usage_string);
465 } 455 }
466
467 xfunc_die(); 456 xfunc_die();
468} 457}
469 458