diff --git a/sched/file_upload_handler.cpp b/sched/file_upload_handler.cpp index 7cb4f2e3ea..d92066e850 100644 --- a/sched/file_upload_handler.cpp +++ b/sched/file_upload_handler.cpp @@ -677,7 +677,9 @@ int main(int argc, char *argv[]) { installer(); - get_log_path(log_path, "file_upload_handler.log"); + if (get_log_path(log_path, "file_upload_handler.log") == ERR_MKDIR) { + fprintf(stderr, "Can't create log directory '%s' (errno: %d)\n", log_path, errno); + } #ifndef _USING_FCGI_ if (!freopen(log_path, "a", stderr)) { fprintf(stderr, "Can't open log file '%s' (errno: %d)\n", diff --git a/sched/sched_main.cpp b/sched/sched_main.cpp index 0f8f8af664..fb1c5fee53 100644 --- a/sched/sched_main.cpp +++ b/sched/sched_main.cpp @@ -429,7 +429,9 @@ int main(int argc, char** argv) { } } else { char *stderr_buffer; - get_log_path(path, "scheduler.log"); + if (get_log_path(path, "scheduler.log") == ERR_MKDIR) { + fprintf(stderr, "Can't create log directory '%s' (errno: %d)\n", path, errno); + } #ifndef _USING_FCGI_ char buf[256]; if (!freopen(path, "a", stderr)) { diff --git a/sched/sched_util_basic.cpp b/sched/sched_util_basic.cpp index 6396b15fcb..b85bf8074b 100644 --- a/sched/sched_util_basic.cpp +++ b/sched/sched_util_basic.cpp @@ -143,7 +143,7 @@ int try_fopen(const char* path, FCGI_FILE*& f, const char *mode) { return 0; } -void get_log_path(char* p, const char* filename) { +int get_log_path(char* p, const char* filename) { char host[256]; const char *dir; @@ -153,10 +153,13 @@ void get_log_path(char* p, const char* filename) { dir = config.project_path("log_%s", host); sprintf(p, "%s/%s", dir, filename); mode_t old_mask = umask(0); - mkdir(dir, 01770); - // make log_x directory sticky and group-rwx - // so that whatever apache puts there will be owned by us + // make log_x directory sticky and group-rwx + // so that whatever apache puts there will be owned by us + int retval = mkdir(dir, 01770); umask(old_mask); + if (retval && errno != EEXIST) return ERR_MKDIR; + + return 0; } static void filename_hash(const char* filename, int fanout, char* dir) { diff --git a/sched/sched_util_basic.h b/sched/sched_util_basic.h index d71f27dbb3..ce30eb736a 100644 --- a/sched/sched_util_basic.h +++ b/sched/sched_util_basic.h @@ -38,7 +38,7 @@ extern void daemon_sleep(int); extern bool check_stop_sched(); extern void install_stop_signal_handler(); extern int try_fopen(const char* path, FILE*& f, const char* mode); -extern void get_log_path(char*, const char*); +extern int get_log_path(char*, const char*); // convert filename to path in a hierarchical directory system //