From fbcb4698538efe72efe6ac67d9250d6b05daf127 Mon Sep 17 00:00:00 2001 From: Lukas Martini Date: Sat, 9 Jun 2012 06:59:45 +0200 Subject: [PATCH] Daemonize after last printf for less stdout confusion --- main.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/main.c b/main.c index 6e662b2..54c767a 100644 --- a/main.c +++ b/main.c @@ -130,20 +130,13 @@ int main(int argc, char* argv[], char* envp[]) MagickWandGenesis(); atexit(MagickWandTerminus); - /* Fork a new master process to daemonize and exit the old one. We use - * _Exit here to not trigger the atexit that terminates ImageMagick. - */ - if(fork()) - _Exit(EXIT_SUCCESS); - - - syslog(LOG_INFO, "Forking workers\n"); - // Fork worker processes + syslog(LOG_INFO, "Forking workers\n"); + worker_pids = calloc(num_workers, sizeof(pid_t)); if(!worker_pids) error_errno("worker_pids: Could not allocate", 1); - + for(worker_id = 0; worker_id <= num_workers; worker_id++) { worker_pids[worker_id] = fork(); @@ -160,6 +153,12 @@ int main(int argc, char* argv[], char* envp[]) { printf("Successfull startup, see syslog for details\n"); + /* Fork a new master process to daemonize and exit the old one. We use + * _Exit here to not trigger the atexit that terminates ImageMagick. + */ + if(fork()) + _Exit(EXIT_SUCCESS); + syslog(LOG_INFO, "master (PID %d): Sleeping until I receive a signal.\n", getpid()); /* Sleep a little until we get a SIG{TERM,HUP,INT} or one of our