← Back to team overview

touch-packages team mailing list archive

[Bug 1490005] [NEW] cron logging level 4 not clear for understanding

 

Public bug reported:

I turned on logging level 4 for cron(logging failed jobs). I think it's
not clear for understanding which job has been failed:

Aug 28 21:58:22 x05 CRON[14697]: (CRON) error (grandchild #14709 failed with exit status 1)
Aug 28 22:03:30 x05 CRON[17572]: (CRON) error (grandchild #17599 failed with exit status 255)
Aug 28 22:06:52 x05 CRON[17560]: (CRON) error (grandchild #17579 failed with exit status 1)
Aug 28 22:09:33 x05 CRON[17575]: (CRON) error (grandchild #17595 failed with exit status 1)

This format will be much better:

Aug 28 22:16:01 x05 CRON[22722]: (root) ERR ([22726]    ls /nowhere is failed withstatus 2)
Aug 28 22:17:01 x05 CRON[23005]: (root) ERR ([23009]    ls /nowhere is failed withstatus 2)
Aug 28 22:18:01 x05 CRON[23165]: (root) ERR ([23169]    ls /nowhere is failed withstatus 2)
Aug 28 22:19:01 x05 CRON[23313]: (root) ERR ([23317]    ls /nowhere is failed withstatus 2)

My small patch to fix this:

--- cron-3.0pl1.orig/do_command.c	2015-08-28 22:35:08.036188131 +0300
+++ cron-3.0pl1.orig-new/do_command.c	2015-08-28 22:03:22.305031093 +0300
@@ -491,18 +491,24 @@ child_process(e, u)
 			getpid(), pid, WEXITSTATUS(waiter)))

 		if (log_level & CRON_LOG_JOBFAILED) {
+            char *x;
+            char logcmd[MAX_COMMAND + 8];
+			snprintf(logcmd, sizeof(logcmd), "[%d] %s", (int) job_pid, e->cmd);
+			x = mkprints((u_char *)logcmd, strlen(logcmd));
+
 			if (WIFEXITED(waiter) && WEXITSTATUS(waiter)) {
 				status = waiter;
-				snprintf(msg, 256, "grandchild #%d failed with exit "
-					"status %d", pid, WEXITSTATUS(waiter));
-				log_it("CRON", getpid(), "error", msg);
+				snprintf(msg, 256, "%s is failed with"
+					"status %d", x, WEXITSTATUS(waiter));
+				log_it(usernm, getpid(), "ERR", msg);
 			} else if (WIFSIGNALED(waiter)) {
 				status = waiter;
-				snprintf(msg, 256, "grandchild #%d terminated by signal"
-					" %d%s", pid, WTERMSIG(waiter),
+				snprintf(msg, 256, "%s terminated by signal"
+					" %d%s", x, WTERMSIG(waiter),
 					WCOREDUMP(waiter) ? ", dumped core" : "");
-				log_it("CRON", getpid(), "error", msg);
+				log_it(usernm, getpid(), "ERR", msg);
 			}
+            free(x);
 		}
 	}

** Affects: cron (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Touch seeded packages, which is subscribed to cron in Ubuntu.
https://bugs.launchpad.net/bugs/1490005

Title:
  cron logging level 4 not clear for understanding

Status in cron package in Ubuntu:
  New

Bug description:
  I turned on logging level 4 for cron(logging failed jobs). I think
  it's not clear for understanding which job has been failed:

  Aug 28 21:58:22 x05 CRON[14697]: (CRON) error (grandchild #14709 failed with exit status 1)
  Aug 28 22:03:30 x05 CRON[17572]: (CRON) error (grandchild #17599 failed with exit status 255)
  Aug 28 22:06:52 x05 CRON[17560]: (CRON) error (grandchild #17579 failed with exit status 1)
  Aug 28 22:09:33 x05 CRON[17575]: (CRON) error (grandchild #17595 failed with exit status 1)

  This format will be much better:

  Aug 28 22:16:01 x05 CRON[22722]: (root) ERR ([22726]    ls /nowhere is failed withstatus 2)
  Aug 28 22:17:01 x05 CRON[23005]: (root) ERR ([23009]    ls /nowhere is failed withstatus 2)
  Aug 28 22:18:01 x05 CRON[23165]: (root) ERR ([23169]    ls /nowhere is failed withstatus 2)
  Aug 28 22:19:01 x05 CRON[23313]: (root) ERR ([23317]    ls /nowhere is failed withstatus 2)

  My small patch to fix this:

  --- cron-3.0pl1.orig/do_command.c	2015-08-28 22:35:08.036188131 +0300
  +++ cron-3.0pl1.orig-new/do_command.c	2015-08-28 22:03:22.305031093 +0300
  @@ -491,18 +491,24 @@ child_process(e, u)
   			getpid(), pid, WEXITSTATUS(waiter)))

   		if (log_level & CRON_LOG_JOBFAILED) {
  +            char *x;
  +            char logcmd[MAX_COMMAND + 8];
  +			snprintf(logcmd, sizeof(logcmd), "[%d] %s", (int) job_pid, e->cmd);
  +			x = mkprints((u_char *)logcmd, strlen(logcmd));
  +
   			if (WIFEXITED(waiter) && WEXITSTATUS(waiter)) {
   				status = waiter;
  -				snprintf(msg, 256, "grandchild #%d failed with exit "
  -					"status %d", pid, WEXITSTATUS(waiter));
  -				log_it("CRON", getpid(), "error", msg);
  +				snprintf(msg, 256, "%s is failed with"
  +					"status %d", x, WEXITSTATUS(waiter));
  +				log_it(usernm, getpid(), "ERR", msg);
   			} else if (WIFSIGNALED(waiter)) {
   				status = waiter;
  -				snprintf(msg, 256, "grandchild #%d terminated by signal"
  -					" %d%s", pid, WTERMSIG(waiter),
  +				snprintf(msg, 256, "%s terminated by signal"
  +					" %d%s", x, WTERMSIG(waiter),
   					WCOREDUMP(waiter) ? ", dumped core" : "");
  -				log_it("CRON", getpid(), "error", msg);
  +				log_it(usernm, getpid(), "ERR", msg);
   			}
  +            free(x);
   		}
   	}

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/cron/+bug/1490005/+subscriptions