==== //internal/software/pkgs/monit/env.c#4 - /export/rory/perforce/intreon/software/pkgs/monit/env.c ==== *** /tmp/tmp.23714.0 Wed Aug 7 18:14:44 2002 --- /export/rory/perforce/intreon/software/pkgs/monit/env.c Wed Aug 7 18:13:02 2002 *************** *** 119,125 **** * Require that file descriptors 0,1,2 are open. Mysterious things * can happen if that is not the case. */ ! for (i= 0; i < 3; i++) { if (fstat(i, &st) == -1 && open("/dev/null", O_RDWR) != i) { --- 119,125 ---- * Require that file descriptors 0,1,2 are open. Mysterious things * can happen if that is not the case. */ ! /* for (i= 0; i < 3; i++) { if (fstat(i, &st) == -1 && open("/dev/null", O_RDWR) != i) { *************** *** 129,134 **** --- 129,135 ---- } } + */ /* * Require that the other file descriptios are closed. Should we use ==== //internal/software/pkgs/monit/daemonize.c#4 - /export/rory/perforce/intreon/software/pkgs/monit/daemonize.c ==== *** /tmp/tmp.23718.0 Wed Aug 7 18:14:58 2002 --- /export/rory/perforce/intreon/software/pkgs/monit/daemonize.c Wed Aug 7 18:11:27 2002 *************** *** 1,5 **** /* ! * Copyright 2000-2002 by Jan-Henrik Haukeland * All Rights Reserved. * * This program is free software; you can redistribute it and/or --- 1,5 ---- /* ! * Copyright (C), 2000-2002 by Jan-Henrik Haukeland et al. * All Rights Reserved. * * This program is free software; you can redistribute it and/or *************** *** 23,28 **** --- 23,29 ---- #include #include #include + #include #include #include #include *************** *** 36,42 **** * * @author Jan-Henrik Haukeland, * ! * @version \$Id: daemonize.c,v 1.19 2002/06/22 13:15:43 hauk Exp $ * * @file */ --- 37,43 ---- * * @author Jan-Henrik Haukeland, * ! * @version \$Id: daemonize.c,v 1.3 2002/08/08 01:11:27 rory Exp $ * * @file */ *************** *** 52,57 **** --- 53,59 ---- void daemonize() { pid_t pid; + int nullfd; /* * Clear file creation mask *************** *** 61,95 **** /* * Become a session leader to lose our controlling terminal */ - if ((pid= fork ()) < 0) { - - log("Cannot fork of a new process\n"); - exit (1); - - } - else if ( pid != 0 ) { - - _exit(0); - - } ! setsid(); ! /* ! * Don't let future opens allocate controlling terminals ! */ ! signal(SIGHUP, SIG_IGN); ! if ((pid= fork ()) < 0) { ! ! log("Cannot fork of a new process\n"); ! exit (1); ! ! } ! else if ( pid != 0 ) { ! _exit(0); - } /* --- 63,88 ---- /* * Become a session leader to lose our controlling terminal */ ! nullfd = open("/dev/null", O_RDWR); ! if (nullfd < 0) { ! log("cannot open /dev/null"); ! goto bail; ! } ! pid = fork(); ! if (pid < 0) { ! log("cannot fork"); ! goto bail; ! } else if (pid == 0) { ! dup2(nullfd, 0); ! dup2(nullfd, 1); ! dup2(nullfd, 2); ! close(nullfd); ! setsid(); ! } else { _exit(0); } /* *************** *** 105,111 **** /* Other daemon init stuff, like fd closing is already taken care of in env.c */ ! } --- 98,106 ---- /* Other daemon init stuff, like fd closing is already taken care of in env.c */ ! ! bail: ! exit(1); }