aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-12-11 16:48:50 +0000
committerEric Andersen <andersen@codepoet.org>2000-12-11 16:48:50 +0000
commit394cf226682925384f24c6d0814df80f0be82bd0 (patch)
tree2644b0068e7355558bfc1f38f445d2a3cadb4292
parentcf7982e908f98e1ab7e90ffb039ed5968589ae24 (diff)
downloadbusybox-w32-394cf226682925384f24c6d0814df80f0be82bd0.tar.gz
busybox-w32-394cf226682925384f24c6d0814df80f0be82bd0.tar.bz2
busybox-w32-394cf226682925384f24c6d0814df80f0be82bd0.zip
Fix the option parsing to use getopt, which seems to fix bug #1050
-rw-r--r--sysklogd/syslogd.c44
-rw-r--r--syslogd.c44
2 files changed, 26 insertions, 62 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 9e174e6e8..2d5e52f25 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -478,25 +478,19 @@ static void daemon_init (char **argv, char *dz, void fn (void))
478 478
479extern int syslogd_main(int argc, char **argv) 479extern int syslogd_main(int argc, char **argv)
480{ 480{
481 int pid, klogd_pid; 481 int opt, pid, klogd_pid;
482 int doFork = TRUE; 482 int doFork = TRUE;
483 483
484#ifdef BB_FEATURE_KLOGD 484#ifdef BB_FEATURE_KLOGD
485 int startKlogd = TRUE; 485 int startKlogd = TRUE;
486#endif 486#endif
487 int stopDoingThat = FALSE;
488 char *p; 487 char *p;
489 char **argv1 = argv;
490 488
491 while (--argc > 0 && **(++argv1) == '-') { 489 /* do normal option parsing */
492 stopDoingThat = FALSE; 490 while ((opt = getopt(argc, argv, "m:nKO:R:L")) > 0) {
493 while (stopDoingThat == FALSE && *(++(*argv1))) { 491 switch (opt) {
494 switch (**argv1) {
495 case 'm': 492 case 'm':
496 if (--argc == 0) { 493 MarkInterval = atoi(optarg) * 60;
497 usage(syslogd_usage);
498 }
499 MarkInterval = atoi(*(++argv1)) * 60;
500 break; 494 break;
501 case 'n': 495 case 'n':
502 doFork = FALSE; 496 doFork = FALSE;
@@ -507,38 +501,26 @@ extern int syslogd_main(int argc, char **argv)
507 break; 501 break;
508#endif 502#endif
509 case 'O': 503 case 'O':
510 if (--argc == 0) { 504 logFilePath = strdup(optarg);
511 usage(syslogd_usage);
512 }
513 logFilePath = *(++argv1);
514 stopDoingThat = TRUE;
515 break; 505 break;
516#ifdef BB_FEATURE_REMOTE_LOG 506#ifdef BB_FEATURE_REMOTE_LOG
517 case 'R': 507 case 'R':
518 if (--argc == 0) { 508 RemoteHost = strdup(optarg);
519 usage(syslogd_usage); 509 if ( (p = strchr(RemoteHost, ':'))){
520 } 510 RemotePort = atoi(p+1);
521 RemoteHost = *(++argv1); 511 *p = '\0';
522 if ( (p = strchr(RemoteHost, ':'))){ 512 }
523 RemotePort = atoi(p+1); 513 doRemoteLog = TRUE;
524 *p = '\0'; 514 break;
525 }
526 doRemoteLog = TRUE;
527 stopDoingThat = TRUE;
528 break;
529 case 'L': 515 case 'L':
530 local_logging = TRUE; 516 local_logging = TRUE;
531 break; 517 break;
532#endif 518#endif
533 default: 519 default:
534 usage(syslogd_usage); 520 usage(syslogd_usage);
535 }
536 } 521 }
537 } 522 }
538 523
539 if (argc > 0)
540 usage(syslogd_usage);
541
542 /* Store away localhost's name before the fork */ 524 /* Store away localhost's name before the fork */
543 gethostname(LocalHostName, sizeof(LocalHostName)); 525 gethostname(LocalHostName, sizeof(LocalHostName));
544 if ((p = strchr(LocalHostName, '.'))) { 526 if ((p = strchr(LocalHostName, '.'))) {
diff --git a/syslogd.c b/syslogd.c
index 9e174e6e8..2d5e52f25 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -478,25 +478,19 @@ static void daemon_init (char **argv, char *dz, void fn (void))
478 478
479extern int syslogd_main(int argc, char **argv) 479extern int syslogd_main(int argc, char **argv)
480{ 480{
481 int pid, klogd_pid; 481 int opt, pid, klogd_pid;
482 int doFork = TRUE; 482 int doFork = TRUE;
483 483
484#ifdef BB_FEATURE_KLOGD 484#ifdef BB_FEATURE_KLOGD
485 int startKlogd = TRUE; 485 int startKlogd = TRUE;
486#endif 486#endif
487 int stopDoingThat = FALSE;
488 char *p; 487 char *p;
489 char **argv1 = argv;
490 488
491 while (--argc > 0 && **(++argv1) == '-') { 489 /* do normal option parsing */
492 stopDoingThat = FALSE; 490 while ((opt = getopt(argc, argv, "m:nKO:R:L")) > 0) {
493 while (stopDoingThat == FALSE && *(++(*argv1))) { 491 switch (opt) {
494 switch (**argv1) {
495 case 'm': 492 case 'm':
496 if (--argc == 0) { 493 MarkInterval = atoi(optarg) * 60;
497 usage(syslogd_usage);
498 }
499 MarkInterval = atoi(*(++argv1)) * 60;
500 break; 494 break;
501 case 'n': 495 case 'n':
502 doFork = FALSE; 496 doFork = FALSE;
@@ -507,38 +501,26 @@ extern int syslogd_main(int argc, char **argv)
507 break; 501 break;
508#endif 502#endif
509 case 'O': 503 case 'O':
510 if (--argc == 0) { 504 logFilePath = strdup(optarg);
511 usage(syslogd_usage);
512 }
513 logFilePath = *(++argv1);
514 stopDoingThat = TRUE;
515 break; 505 break;
516#ifdef BB_FEATURE_REMOTE_LOG 506#ifdef BB_FEATURE_REMOTE_LOG
517 case 'R': 507 case 'R':
518 if (--argc == 0) { 508 RemoteHost = strdup(optarg);
519 usage(syslogd_usage); 509 if ( (p = strchr(RemoteHost, ':'))){
520 } 510 RemotePort = atoi(p+1);
521 RemoteHost = *(++argv1); 511 *p = '\0';
522 if ( (p = strchr(RemoteHost, ':'))){ 512 }
523 RemotePort = atoi(p+1); 513 doRemoteLog = TRUE;
524 *p = '\0'; 514 break;
525 }
526 doRemoteLog = TRUE;
527 stopDoingThat = TRUE;
528 break;
529 case 'L': 515 case 'L':
530 local_logging = TRUE; 516 local_logging = TRUE;
531 break; 517 break;
532#endif 518#endif
533 default: 519 default:
534 usage(syslogd_usage); 520 usage(syslogd_usage);
535 }
536 } 521 }
537 } 522 }
538 523
539 if (argc > 0)
540 usage(syslogd_usage);
541
542 /* Store away localhost's name before the fork */ 524 /* Store away localhost's name before the fork */
543 gethostname(LocalHostName, sizeof(LocalHostName)); 525 gethostname(LocalHostName, sizeof(LocalHostName));
544 if ((p = strchr(LocalHostName, '.'))) { 526 if ((p = strchr(LocalHostName, '.'))) {