monit-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Monit doesn't detach from the tty


From: Rory Toma
Subject: Re: Monit doesn't detach from the tty
Date: 07 Aug 2002 18:41:06 -0700

Oops. Made a small mistake. Here's a patch for the patch...

On Wed, 2002-08-07 at 18:20, Rory Toma wrote:
> On Wed, 2002-08-07 at 17:51, Mark Ferlatte wrote:
> > On Wed, Aug 07, 2002 at 05:40:39PM -0700, Rory Toma wrote (0.15):
> > > 1) why use _exit(0) instead of exit(0)?
> > 
> > monit registers an atexit() handler in log.c, and calling exit() would
> > trigger it, which would be incorrect.  _exit() doesn't run atexit()
> > handlers, which is correct in daemonize().
> 
> I missed that.
> 
> I checked into CVS a fix that makes it properly detach from the tty (at
> least it does on my Linux and Solaris 8 box) and also dup2's 0,1 and 2
> and closes them off. I suspect the comment in env.c about weird things
> happening if you close them is because with no 0,1 or 2 present, future
> fd's will happily re-use them otherwise, and yes, weird things can
> happen.
> 
> Attatched is a patch...
> 
> 
> 
> -- 
> Rory Toma             address@hidden
> VP of Run Level 5     http://www.trs80.net
> Digeo Digital         http://www.digeo.com
> ----
> 

> ==== //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 <address@hidden>
>    * 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 <stdlib.h>
>   #include <errno.h>
>   #include <signal.h>
> + #include <fcntl.h>
>   #include <sys/types.h>
>   #include <sys/stat.h>
>   #include <unistd.h>
> ***************
> *** 36,42 ****
>    *
>    *  @author Jan-Henrik Haukeland, <address@hidden>
>    *
> !  *  @version \$Id: daemonize.c,v 1.19 2002/06/22 13:15:43 hauk Exp $
>    *
>    *  @file
>    */
> --- 37,43 ----
>    *
>    *  @author Jan-Henrik Haukeland, <address@hidden>
>    *
> !  *  @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);
>   } 
>   
>   
-- 
Rory Toma               address@hidden
VP of Run Level 5       http://www.trs80.net
Digeo Digital           http://www.digeo.com

Attachment: patch
Description: Text document

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]