[Pkg-cron-devel] [SCM] Git repository for pkg-cron branch, sf3, updated. debian/3.0pl1-109-20-gde88d23
Christian Kastner
debian at kvr.at
Sat Sep 24 22:26:49 UTC 2011
The following commit has been merged in the sf3 branch:
commit d6d5ab2d9205f672e15d90e37ff58508387fb877
Author: Christian Kastner <debian at kvr.at>
Date: Sun Sep 25 00:07:59 2011 +0200
Selective logging for jobs
Enhance job output logging though fine-grained output controls.
diff --git a/debian/patches/features/mailcmd-dont-timeout b/debian/patches/features/mailcmd-dont-timeout
index 924f702..1ed7d71 100644
--- a/debian/patches/features/mailcmd-dont-timeout
+++ b/debian/patches/features/mailcmd-dont-timeout
@@ -11,10 +11,10 @@ Bug-Debian: http://bugs.debian.org/433615
Bug-Debian: http://bugs.debian.org/580938
Bug-Debian: http://bugs.debian.org/581612
Bug-Debian: http://bugs.debian.org/604181
-Index: orig/do_command.c
+Index: sf3/do_command.c
===================================================================
---- orig.orig/do_command.c 2011-01-07 17:32:20.619639235 +0100
-+++ orig/do_command.c 2011-01-07 17:34:35.087659172 +0100
+--- sf3.orig/do_command.c 2011-09-24 23:10:01.904004765 +0200
++++ sf3/do_command.c 2011-09-24 23:14:18.544004819 +0200
@@ -111,12 +111,21 @@
}
@@ -106,7 +106,7 @@ Index: orig/do_command.c
/* translation:
* \% -> %
* % -> \n
-@@ -447,167 +453,12 @@
+@@ -447,160 +453,12 @@
* when the grandchild exits, we'll get EOF.
*/
@@ -255,13 +255,6 @@ Index: orig/do_command.c
-
- } /*if data from grandchild*/
-
-- if (log_level >= 2) {
-- char *x = mkprints((u_char *)e->cmd, strlen(e->cmd));
--
-- log_it(usernm, getpid(), "END", x);
-- free(x);
-- }
--
- Debug(DPROC, ("[%d] got EOF from grandchild\n", getpid()))
-
- fclose(in); /* also closes stdout_pipe[READ_PIPE] */
@@ -276,7 +269,7 @@ Index: orig/do_command.c
WAIT_T waiter;
PID_T pid;
-@@ -615,16 +466,157 @@
+@@ -608,16 +466,151 @@
getpid(), children))
pid = wait(&waiter);
if (pid < OK) {
@@ -304,7 +297,7 @@ Index: orig/do_command.c
+ WCOREDUMP(waiter) ? ", dumped core" : "");
+ log_it("CRON", getpid(), "error", msg);
+ }
-+ }
+ }
+
+// Finally, send any output of the command to the mailer; also, alert
+// the user if their job failed. Avoid popening the mailcmd until now
@@ -371,7 +364,7 @@ Index: orig/do_command.c
+ && (nl < (content_type+ctlen))
+ ) *nl = ' ';
+ fprintf(mail,"Content-Type: %s\n", content_type);
- }
++ }
+ if ( content_transfer_encoding != 0L ) {
+ char *nl=content_transfer_encoding;
+ size_t ctlen = strlen(content_transfer_encoding);
@@ -431,12 +424,6 @@ Index: orig/do_command.c
+mail_finished:
+ fclose(tmpout);
+
-+ if (log_level >= 2) {
-+ char *x = mkprints((u_char *)e->cmd, strlen(e->cmd));
-+ log_it(usernm, getpid(), "END", x);
-+ free(x);
-+ }
-+
#if defined(USE_PAM)
pam_setcred(pamh, PAM_DELETE_CRED | PAM_SILENT);
retcode = pam_close_session(pamh, PAM_SILENT);
diff --git a/debian/patches/features/option-log-completed-jobs b/debian/patches/features/option-log-completed-jobs
deleted file mode 100644
index 5247361..0000000
--- a/debian/patches/features/option-log-completed-jobs
+++ /dev/null
@@ -1,77 +0,0 @@
-Subject: Option to log completed jobs
-Last-Update: 2010-04-11
-
-Provide an option to log completed jobs if requested so.
-
-Acked-by: Christian Kastner <debian at kvr.at>
-Index: orig/cron.h
-===================================================================
---- orig.orig/cron.h 2011-01-07 17:23:08.175640762 +0100
-+++ orig/cron.h 2011-01-07 17:23:15.435639512 +0100
-@@ -292,7 +292,7 @@
-
- int stay_foreground;
- int lsbsysinit_mode;
--
-+int log_level = 1;
- char cron_default_mail_charset[MAX_ENVSTR] = "";
-
- # if DEBUGGING
-@@ -308,6 +308,7 @@
- *DowNames[],
- *ProgramName;
- extern int lsbsysinit_mode;
-+extern int log_level;
- extern int LineNumber;
- extern time_t StartTime;
- extern time_min timeRunning;
-Index: orig/cron.c
-===================================================================
---- orig.orig/cron.c 2011-01-07 17:23:08.171640883 +0100
-+++ orig/cron.c 2011-01-07 17:23:15.435639512 +0100
-@@ -468,7 +468,7 @@
- stay_foreground = 0;
- lsbsysinit_mode = 0;
-
-- while (EOF != (argch = getopt(argc, argv, "lfx:"))) {
-+ while (EOF != (argch = getopt(argc, argv, "lfx:L:"))) {
- switch (argch) {
- default:
- usage();
-@@ -482,6 +482,9 @@
- case 'l':
- lsbsysinit_mode = 1;
- break;
-+ case 'L':
-+ log_level = atoi(optarg);
-+ break;
- }
- }
- }
-Index: orig/do_command.c
-===================================================================
---- orig.orig/do_command.c 2011-01-07 17:22:13.423636871 +0100
-+++ orig/do_command.c 2011-01-07 17:23:15.435639512 +0100
-@@ -248,7 +248,7 @@
- * the actual user command shell was going to get and the
- * PID is part of the log message.
- */
-- /*local*/{
-+ if (log_level >= 1) {
- char *x = mkprints((u_char *)e->cmd, strlen(e->cmd));
-
- log_it(usernm, getpid(), "CMD", x);
-@@ -592,6 +592,13 @@
-
- } /*if data from grandchild*/
-
-+ if (log_level >= 2) {
-+ char *x = mkprints((u_char *)e->cmd, strlen(e->cmd));
-+
-+ log_it(usernm, getpid(), "END", x);
-+ free(x);
-+ }
-+
- Debug(DPROC, ("[%d] got EOF from grandchild\n", getpid()))
-
- fclose(in); /* also closes stdout_pipe[READ_PIPE] */
diff --git a/debian/patches/features/selective-logging b/debian/patches/features/selective-logging
new file mode 100644
index 0000000..211fe40
--- /dev/null
+++ b/debian/patches/features/selective-logging
@@ -0,0 +1,169 @@
+Subject: selective logging
+Author: Steve Fosdick <dbugs at pelvoux.nildram.co.uk>
+Author: Christian Kastner <debian at kvr.at>
+Author: Javier Fernández-Sanguino Peña <jfs at debian.org>
+
+Provides fine-grained control over what the cron daemon logs when it executes
+jobs. This is driven via the '-L' command line option, which accepts a bitmask
+of values for logging the start, end, failure and PID of jobs.
+
+Bug-Debian: http://bugs.debian.org/271747
+Bug-Debian: http://bugs.debian.org/318247
+Last-Update: 2011-09-24
+
+Index: sf3/cron.c
+===================================================================
+--- sf3.orig/cron.c 2011-09-24 23:10:01.000000000 +0200
++++ sf3/cron.c 2011-09-24 23:15:22.328004759 +0200
+@@ -465,6 +465,7 @@
+ {
+ int argch;
+
++ log_level = 1;
+ stay_foreground = 0;
+ lsbsysinit_mode = 0;
+
+Index: sf3/cron.h
+===================================================================
+--- sf3.orig/cron.h 2011-09-24 23:10:01.000000000 +0200
++++ sf3/cron.h 2011-09-24 23:15:22.328004759 +0200
+@@ -134,6 +134,12 @@
+
+ typedef int time_min;
+
++/* Log levels */
++#define CRON_LOG_JOBSTART 0x01
++#define CRON_LOG_JOBEND 0x02
++#define CRON_LOG_JOBFAILED 0x04
++#define CRON_LOG_JOBPID 0x08
++
+ #define SECONDS_PER_MINUTE 60
+
+ #define FIRST_MINUTE 0
+@@ -208,6 +214,12 @@
+ #endif
+ } cron_db;
+
++typedef struct _orphan {
++ struct _orphan *next; /* link */
++ char *uname;
++ char *fname;
++ char *tabname;
++} orphan;
+
+ void set_cron_uid __P((void)),
+ set_cron_cwd __P((void)),
+Index: sf3/do_command.c
+===================================================================
+--- sf3.orig/do_command.c 2011-09-24 23:14:37.000000000 +0200
++++ sf3/do_command.c 2011-09-24 23:16:17.980004844 +0200
+@@ -131,6 +131,7 @@
+ register char *input_data;
+ char *usernm, *mailto;
+ int children = 0;
++ pid_t job_pid;
+
+ #if defined(USE_PAM)
+ int retcode = 0;
+@@ -249,7 +250,7 @@
+
+ /* fork again, this time so we can exec the user's command.
+ */
+- switch (fork()) {
++ switch (job_pid = fork()) {
+ case -1:
+ log_it("CRON",getpid(),"error","can't fork");
+ exit(ERROR_EXIT);
+@@ -258,19 +259,17 @@
+ Debug(DPROC, ("[%d] grandchild process fork()'ed\n",
+ getpid()))
+
+- /* write a log message. we've waited this long to do it
++ /* write a log message . we've waited this long to do it
+ * because it was not until now that we knew the PID that
+ * the actual user command shell was going to get and the
+ * PID is part of the log message.
+ */
+- /*local*/{
++ if ( (log_level & CRON_LOG_JOBSTART) && ! (log_level & CRON_LOG_JOBPID)) {
+ char *x = mkprints((u_char *)e->cmd, strlen(e->cmd));
+-
+ log_it(usernm, getpid(), "CMD", x);
+ free(x);
+ }
+-
+- /* that's the last thing we'll log. close the log files.
++ /* nothing to log from now on. close the log files.
+ */
+ log_close();
+
+@@ -373,6 +372,16 @@
+ break;
+ default:
+ /* parent process */
++ /* write a log message if we want the parent and child
++ * PID values
++ */
++ if ( (log_level & CRON_LOG_JOBSTART) && (log_level & CRON_LOG_JOBPID)) {
++ char logcmd[MAX_COMMAND + 8];
++ snprintf(logcmd, sizeof(logcmd), "[%d] %s", (int) job_pid, e->cmd);
++ char *x = mkprints((u_char *)logcmd, strlen(logcmd));
++ log_it(usernm, getpid(), "CMD", x);
++ free(x);
++ }
+ break;
+ }
+
+@@ -474,18 +483,20 @@
+ Debug(DPROC, ("[%d] grandchild #%d finished, status=%04x\n",
+ getpid(), pid, WEXITSTATUS(waiter)))
+
+- 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);
+- } else if (WIFSIGNALED(waiter)) {
+- status = waiter;
+- snprintf(msg, 256, "grandchild #%d terminated by signal"
+- " %d%s", pid, WTERMSIG(waiter),
+- WCOREDUMP(waiter) ? ", dumped core" : "");
+- log_it("CRON", getpid(), "error", msg);
+- }
++ if (log_level & CRON_LOG_JOBFAILED) {
++ 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);
++ } else if (WIFSIGNALED(waiter)) {
++ status = waiter;
++ snprintf(msg, 256, "grandchild #%d terminated by signal"
++ " %d%s", pid, WTERMSIG(waiter),
++ WCOREDUMP(waiter) ? ", dumped core" : "");
++ log_it("CRON", getpid(), "error", msg);
++ }
++ }
+ }
+
+ // Finally, send any output of the command to the mailer; also, alert
+@@ -626,6 +637,19 @@
+ mail_finished:
+ fclose(tmpout);
+
++ if (log_level & CRON_LOG_JOBEND) {
++ char *x;
++ if (log_level & CRON_LOG_JOBPID) {
++ char logcmd[MAX_COMMAND + 8];
++ snprintf(logcmd, sizeof(logcmd), "[%d] %s", (int) job_pid, e->cmd);
++ x = mkprints((u_char *)logcmd, strlen(logcmd));
++ } else {
++ x = mkprints((u_char *)e->cmd, strlen(e->cmd));
++ }
++ log_it(usernm, job_pid, "END", x);
++ free(x);
++ }
++
+ #if defined(USE_PAM)
+ pam_setcred(pamh, PAM_DELETE_CRED | PAM_SILENT);
+ retcode = pam_close_session(pamh, PAM_SILENT);
diff --git a/debian/patches/series b/debian/patches/series
index 49e5316..81b0a4f 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -48,13 +48,13 @@ features/allow-running-cron-in-foreground
features/control-header-output
features/confirm-crontab-deletion
features/add-helpmsg-to-new-crontab
-features/option-log-completed-jobs
features/mailcmd-dont-timeout
features/dont-fail-on-missing-MTA
features/no-argument-is-stdin
features/dont-die-on-missing-dirs
features/crontab-refuse-eof-without-nl
features/recover-from-errors
+features/selective-logging
features/backport-envparser
other/changes-to-upstream-README
other/changes-to-cron-8
--
Git repository for pkg-cron
More information about the Pkg-cron-devel
mailing list