Fix the option parsing to use getopt, which seems to fix bug #1050
This commit is contained in:
parent
cf7982e908
commit
394cf22668
@ -478,25 +478,19 @@ static void daemon_init (char **argv, char *dz, void fn (void))
|
|||||||
|
|
||||||
extern int syslogd_main(int argc, char **argv)
|
extern int syslogd_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int pid, klogd_pid;
|
int opt, pid, klogd_pid;
|
||||||
int doFork = TRUE;
|
int doFork = TRUE;
|
||||||
|
|
||||||
#ifdef BB_FEATURE_KLOGD
|
#ifdef BB_FEATURE_KLOGD
|
||||||
int startKlogd = TRUE;
|
int startKlogd = TRUE;
|
||||||
#endif
|
#endif
|
||||||
int stopDoingThat = FALSE;
|
|
||||||
char *p;
|
char *p;
|
||||||
char **argv1 = argv;
|
|
||||||
|
|
||||||
while (--argc > 0 && **(++argv1) == '-') {
|
/* do normal option parsing */
|
||||||
stopDoingThat = FALSE;
|
while ((opt = getopt(argc, argv, "m:nKO:R:L")) > 0) {
|
||||||
while (stopDoingThat == FALSE && *(++(*argv1))) {
|
switch (opt) {
|
||||||
switch (**argv1) {
|
|
||||||
case 'm':
|
case 'm':
|
||||||
if (--argc == 0) {
|
MarkInterval = atoi(optarg) * 60;
|
||||||
usage(syslogd_usage);
|
|
||||||
}
|
|
||||||
MarkInterval = atoi(*(++argv1)) * 60;
|
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
doFork = FALSE;
|
doFork = FALSE;
|
||||||
@ -507,24 +501,16 @@ extern int syslogd_main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'O':
|
case 'O':
|
||||||
if (--argc == 0) {
|
logFilePath = strdup(optarg);
|
||||||
usage(syslogd_usage);
|
|
||||||
}
|
|
||||||
logFilePath = *(++argv1);
|
|
||||||
stopDoingThat = TRUE;
|
|
||||||
break;
|
break;
|
||||||
#ifdef BB_FEATURE_REMOTE_LOG
|
#ifdef BB_FEATURE_REMOTE_LOG
|
||||||
case 'R':
|
case 'R':
|
||||||
if (--argc == 0) {
|
RemoteHost = strdup(optarg);
|
||||||
usage(syslogd_usage);
|
|
||||||
}
|
|
||||||
RemoteHost = *(++argv1);
|
|
||||||
if ( (p = strchr(RemoteHost, ':'))){
|
if ( (p = strchr(RemoteHost, ':'))){
|
||||||
RemotePort = atoi(p+1);
|
RemotePort = atoi(p+1);
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
}
|
}
|
||||||
doRemoteLog = TRUE;
|
doRemoteLog = TRUE;
|
||||||
stopDoingThat = TRUE;
|
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
local_logging = TRUE;
|
local_logging = TRUE;
|
||||||
@ -534,10 +520,6 @@ extern int syslogd_main(int argc, char **argv)
|
|||||||
usage(syslogd_usage);
|
usage(syslogd_usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (argc > 0)
|
|
||||||
usage(syslogd_usage);
|
|
||||||
|
|
||||||
/* Store away localhost's name before the fork */
|
/* Store away localhost's name before the fork */
|
||||||
gethostname(LocalHostName, sizeof(LocalHostName));
|
gethostname(LocalHostName, sizeof(LocalHostName));
|
||||||
|
32
syslogd.c
32
syslogd.c
@ -478,25 +478,19 @@ static void daemon_init (char **argv, char *dz, void fn (void))
|
|||||||
|
|
||||||
extern int syslogd_main(int argc, char **argv)
|
extern int syslogd_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int pid, klogd_pid;
|
int opt, pid, klogd_pid;
|
||||||
int doFork = TRUE;
|
int doFork = TRUE;
|
||||||
|
|
||||||
#ifdef BB_FEATURE_KLOGD
|
#ifdef BB_FEATURE_KLOGD
|
||||||
int startKlogd = TRUE;
|
int startKlogd = TRUE;
|
||||||
#endif
|
#endif
|
||||||
int stopDoingThat = FALSE;
|
|
||||||
char *p;
|
char *p;
|
||||||
char **argv1 = argv;
|
|
||||||
|
|
||||||
while (--argc > 0 && **(++argv1) == '-') {
|
/* do normal option parsing */
|
||||||
stopDoingThat = FALSE;
|
while ((opt = getopt(argc, argv, "m:nKO:R:L")) > 0) {
|
||||||
while (stopDoingThat == FALSE && *(++(*argv1))) {
|
switch (opt) {
|
||||||
switch (**argv1) {
|
|
||||||
case 'm':
|
case 'm':
|
||||||
if (--argc == 0) {
|
MarkInterval = atoi(optarg) * 60;
|
||||||
usage(syslogd_usage);
|
|
||||||
}
|
|
||||||
MarkInterval = atoi(*(++argv1)) * 60;
|
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
doFork = FALSE;
|
doFork = FALSE;
|
||||||
@ -507,24 +501,16 @@ extern int syslogd_main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'O':
|
case 'O':
|
||||||
if (--argc == 0) {
|
logFilePath = strdup(optarg);
|
||||||
usage(syslogd_usage);
|
|
||||||
}
|
|
||||||
logFilePath = *(++argv1);
|
|
||||||
stopDoingThat = TRUE;
|
|
||||||
break;
|
break;
|
||||||
#ifdef BB_FEATURE_REMOTE_LOG
|
#ifdef BB_FEATURE_REMOTE_LOG
|
||||||
case 'R':
|
case 'R':
|
||||||
if (--argc == 0) {
|
RemoteHost = strdup(optarg);
|
||||||
usage(syslogd_usage);
|
|
||||||
}
|
|
||||||
RemoteHost = *(++argv1);
|
|
||||||
if ( (p = strchr(RemoteHost, ':'))){
|
if ( (p = strchr(RemoteHost, ':'))){
|
||||||
RemotePort = atoi(p+1);
|
RemotePort = atoi(p+1);
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
}
|
}
|
||||||
doRemoteLog = TRUE;
|
doRemoteLog = TRUE;
|
||||||
stopDoingThat = TRUE;
|
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
local_logging = TRUE;
|
local_logging = TRUE;
|
||||||
@ -534,10 +520,6 @@ extern int syslogd_main(int argc, char **argv)
|
|||||||
usage(syslogd_usage);
|
usage(syslogd_usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (argc > 0)
|
|
||||||
usage(syslogd_usage);
|
|
||||||
|
|
||||||
/* Store away localhost's name before the fork */
|
/* Store away localhost's name before the fork */
|
||||||
gethostname(LocalHostName, sizeof(LocalHostName));
|
gethostname(LocalHostName, sizeof(LocalHostName));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user