From 8f7c9752c79b86be43f08b74cb2b938a86134ba4 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Tue, 21 Jun 2011 12:00:28 +0200 Subject: [PATCH] Unify logging in case of SyslogOutput with the rest of crond. --- src/do_command.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/do_command.c b/src/do_command.c index e1f5401..44510d5 100644 --- a/src/do_command.c +++ b/src/do_command.c @@ -70,7 +70,6 @@ static int child_process(entry * e, user * u, char **jobenv) { char *input_data, *usernm, *mailto, *mailfrom; int children = 0; pid_t pid = getpid(); - pid_t jobpid; struct sigaction sa; /* Ignore SIGPIPE as we will be writing to pipes and do not want to terminate @@ -158,7 +157,7 @@ static int child_process(entry * e, user * u, char **jobenv) { /* fork again, this time so we can exec the user's command. */ - switch ((jobpid = fork())) { + switch (fork()) { case -1: log_it("CRON", pid, "CAN'T FORK", "child_process", errno); return ERROR_EXIT; @@ -346,14 +345,9 @@ static int child_process(entry * e, user * u, char **jobenv) { int bytes = 1; int status = 0; #if defined(SYSLOG) - char jobtag[64], logbuf[1024]; + char logbuf[1024]; int bufidx = 0; - /* according to the NOTES section of openlog(3), jobtag will be - * used (implicitly) by future calls to syslog(). That's why it - * was defined outside of the if block here. */ if (SyslogOutput) { - snprintf(jobtag, sizeof(jobtag), "CROND[%d]", jobpid); - openlog(jobtag, 0, LOG_CRON); if (ch != '\n') logbuf[bufidx++] = ch; } @@ -489,7 +483,7 @@ static int child_process(entry * e, user * u, char **jobenv) { logbuf[bufidx-1] = '\0'; else logbuf[bufidx] = '\0'; - syslog(LOG_INFO, "%s", logbuf); + log_it(usernm, getpid(), "CMDOUT", logbuf, 0); bufidx = 0; } } @@ -513,9 +507,8 @@ static int child_process(entry * e, user * u, char **jobenv) { if (SyslogOutput) { if (bufidx) { logbuf[bufidx] = '\0'; - syslog(LOG_INFO, "%s", logbuf); + log_it(usernm, getpid(), "CMDOUT", logbuf, 0); } - closelog(); } #endif -- 2.40.0