1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
From: Christian Kastner <ckk@kvr.at>
Date: Sat, 9 Jan 2016 19:37:40 +0100
Subject: Logging enhancements
Minor enhancements to logging, namely:
* Log to syslog exclusively
* Log the location of the PID file
* Log broken system crontabs (user crontabs are checked by crontab(1))
Contributed by Steve Greenland <stevegr@debian.org>.
Bug-Debian: https://bugs.debian.org/76625
Forwarded: no
Last-Update: 2016-01-09
---
misc.c | 3 ++-
pathnames.h | 2 +-
user.c | 30 +++++++++++++++++++++++++++++-
3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/misc.c b/misc.c
index b04d792..ac0cfb8 100644
--- a/misc.c
+++ b/misc.c
@@ -288,7 +288,8 @@ acquire_daemonlock(closeflag)
log_it("CRON", getpid(), "DEATH", buf);
exit(ERROR_EXIT);
}
-
+ snprintf(buf, MAX_TEMPSTR, "pidfile fd = %d", fd);
+ log_it("CRON", getpid(), "INFO", buf);
(void) fcntl(fd, F_SETFD, 1);
}
diff --git a/pathnames.h b/pathnames.h
index 0f5c1b9..5170e99 100644
--- a/pathnames.h
+++ b/pathnames.h
@@ -49,7 +49,7 @@
*/
#define ALLOW_FILE "/etc/cron.allow" /*-*/
#define DENY_FILE "/etc/cron.deny" /*-*/
-#define LOG_FILE "log" /*-*/
+/* #define LOG_FILE "log" /*-*/
/* where should the daemon stick its PID?
*/
diff --git a/user.c b/user.c
index 6a96bc5..f701927 100644
--- a/user.c
+++ b/user.c
@@ -23,8 +23,11 @@ static char rcsid[] = "$Id: user.c,v 2.8 1994/01/15 20:43:43 vixie Exp $";
*/
+#include <syslog.h>
+#include <string.h>
#include "cron.h"
+
#ifdef WITH_SELINUX
#include <selinux/context.h>
#include <selinux/selinux.h>
@@ -153,6 +156,29 @@ static int get_security_context(char *name, int crontab_fd, security_context_t
#endif
+/* Function used to log errors in crontabs from cron daemon. (User
+ crontabs are checked before they're accepted, but system crontabs
+ are not. */
+static char *err_user = NULL;
+
+void
+crontab_error(msg)
+ char *msg;
+{
+ const char *fn;
+ /* Figure out the file name from the username */
+ if (0 == strcmp(err_user, "*system*")) {
+ syslog(LOG_ERR|LOG_CRON, "Error: %s; while reading %s", msg, SYSCRONTAB);
+ } else if (0 == strncmp(err_user,"*system*",8)) {
+ fn = err_user+8;
+ syslog(LOG_ERR|LOG_CRON, "Error: %s; while reading %s/%s", msg,
+ SYSCRONDIR,fn);
+ } else {
+ syslog(LOG_ERR|LOG_CRON, "Error: %s; while reading crontab for user %s",
+ msg, err_user);
+ }
+}
+
void
free_user(u)
user *u;
@@ -256,7 +282,9 @@ load_user(crontab_fd, pw, uname, fname, tabname)
}
goto done;
case FALSE:
- e = load_entry(file, NULL, pw, envp);
+ err_user = fname;
+ e = load_entry(file, crontab_error, pw, envp);
+ err_user = NULL;
if (e) {
e->next = u->crontab;
u->crontab = e;
|