Commit b6f42390 authored by David Johnson's avatar David Johnson

Give MUL apps a way to redirect stdout/stderr to the logfile.

(Instead of completely dropping it!)
parent d96f0dd7
Pipeline #1070 passed with stage
......@@ -59,6 +59,7 @@ struct clog
priority of the message? */
int syslog_options; /* 2nd arg to openlog */
int timestamp_precision; /* # of digits of subsecond precision */
int redirect_stdio;
};
/* Message structure. */
......@@ -117,6 +118,7 @@ extern void clog_set_name (struct clog *zl, clog_proto_t protocol, char *name);
/* Set logging to the given filename at the specified level. */
extern int clog_set_file (struct clog *zl, const char *filename, int log_level);
extern int clog_set_redirect_stdio (struct clog *zl, int redirect);
/* Disable file logging. */
extern int clog_reset_file (struct clog *zl);
......
......@@ -724,6 +724,23 @@ clog_set_file (struct clog *zl, const char *filename, int log_level)
zl->fp = fp;
logfile_fd = fileno(fp);
if (zl->redirect_stdio) {
dup2(logfile_fd,1);
dup2(logfile_fd,2);
}
return 1;
}
int
clog_set_redirect_stdio (struct clog *zl, int redirect)
{
/* Set default zl. */
if (zl == NULL)
zl = clog_default;
zl->redirect_stdio = redirect;
return 1;
}
......@@ -780,6 +797,11 @@ clog_rotate (struct clog *zl)
}
logfile_fd = fileno(zl->fp);
zl->maxlvl[CLOG_DEST_FILE] = level;
if (zl->redirect_stdio) {
dup2(logfile_fd,1);
dup2(logfile_fd,2);
}
}
return 1;
......
......@@ -54,6 +54,7 @@ static void c_app_event_notifier(void *h_arg, void *pkt_arg);
#define MUL_OPT_PIDFILE 0x11000
#define MUL_OPT_LOGFILE 0x11001
#define MUL_OPT_REDIRECT 0x11002
static const char *opts = "dhs:V:H:f:NnD:";
static struct option longopts[] =
......@@ -66,6 +67,7 @@ static struct option longopts[] =
{ "no-init-conf", required_argument, NULL, 'N'},
{ "pidfile", required_argument, NULL, MUL_OPT_PIDFILE},
{ "logfile", required_argument, NULL, MUL_OPT_LOGFILE},
{ "redirect-stdio", no_argument, NULL, MUL_OPT_REDIRECT},
};
#ifdef MUL_APP_V2_MLAPI
......@@ -802,6 +804,7 @@ __main(int argc, char **argv)
int extra_usage_len = 0;
char *extra_usage;
char *log_file = NULL, *pid_file = NULL;
int redirect_stdio = 0;
/* Set umask before anything for security */
umask (0027);
......@@ -930,6 +933,9 @@ __main(int argc, char **argv)
case MUL_OPT_LOGFILE:
log_file = strdup(optarg);
break;
case MUL_OPT_REDIRECT:
redirect_stdio = 1;
break;
default:
if (&__start_modopthelper_sec != &__stop_modopthelper_sec) {
hrc = -1;
......@@ -981,6 +987,7 @@ __main(int argc, char **argv)
LOG_CONS|LOG_NDELAY, LOG_DAEMON);
clog_set_level(NULL, CLOG_DEST_SYSLOG, LOG_ERR);
clog_set_level(NULL, CLOG_DEST_STDOUT, LOG_DEBUG);
clog_set_redirect_stdio(NULL,redirect_stdio);
clog_set_file(NULL, log_fname, LOG_DEBUG);
clog_set_name(NULL, CLOG_MUL, c_app_main_hdl.progname);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment