Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Daemonize after last printf for less stdout confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
lutoma committed Jun 9, 2012
1 parent d4f50be commit fbcb469
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit fbcb469

Please sign in to comment.