From 907f222729ece1ad553db57f1b721bd6eea8ca12 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Fri, 9 Oct 2015 08:39:10 +0200 Subject: [PATCH] mxqd: fail with diagnostic if unable to write to log directory Failures of cronolog are not detected by the current code, because cronologs own stderr goes to /dev/null. While there are many reasons, why cronolog mail fail, not being able to write to the log directory altogether is a very prominent one which is easy to detect beforehand. This may become even more relevant when we start to support mxqd being run as non-root. --- mxqd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mxqd.c b/mxqd.c index 7cccd05..5239c27 100644 --- a/mxqd.c +++ b/mxqd.c @@ -404,6 +404,10 @@ int server_init(struct mxq_server *server, int argc, char *argv[]) setup_stdin("/dev/null"); if (!arg_nolog) { + if (access("/var/log",R_OK|W_OK|X_OK)) { + mx_log_err("MAIN: cant write to /var/log: %m"); + exit(EX_IOERR); + } res = setup_cronolog("/usr/sbin/cronolog", "/var/log/mxqd_log", "/var/log/%Y/mxqd_log-%Y-%m"); if (!res) { mx_log_err("MAIN: cronolog setup failed. exiting.");