/[monit]/monit/daemonize.c
ViewVC logotype

Diff of /monit/daemonize.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by martinp, Mon Dec 30 15:25:30 2002 UTC revision 1.11 by martinp, Tue Feb 11 20:30:45 2003 UTC
# Line 70  Line 70 
70  void  daemonize() {  void  daemonize() {
71    
72    pid_t pid;    pid_t pid;
   void *hup_handler= NULL;  
73        
74    /*    /*
75     * Clear file creation mask     * Clear file creation mask
# Line 94  void  daemonize() { Line 93  void  daemonize() {
93        
94    setsid();    setsid();
95    
   /*  
    * Don't let future opens allocate controlling terminals  
    */  
   hup_handler= signal(SIGHUP, SIG_IGN);  
   
96    if((pid= fork ()) < 0) {    if((pid= fork ()) < 0) {
97            
98      log("Cannot fork of a new process\n");        log("Cannot fork of a new process\n");  
# Line 129  void  daemonize() { Line 123  void  daemonize() {
123     */     */
124    redirect_stdfd();    redirect_stdfd();
125    
   /*  
    * Reset the SIGHUP handler  
    */  
   if(hup_handler)  
       signal(SIGHUP, hup_handler);  
   
126  }  }
127    
128    
129  /**  /**
130   * Kill a daemon process   * Send signal to a daemon process
131   * @return TRUE if the daemon was killed, otherwise FALSE   * @param sig Signal to send daemon to
132     * @return TRUE if signal was send, otherwise FALSE
133   */   */
134  int kill_daemon() {  int kill_daemon(int sig) {
135        
136    pid_t pid;    pid_t pid;
137    
138    if ( (pid= exist_daemon()) > 0 ) {    if ( (pid= exist_daemon()) > 0 ) {
139            
140      if ( kill(pid, SIGTERM) < 0 ) {      if ( kill(pid, sig) < 0 ) {
141                
142        error("%s: Cannot kill daemon process -- %s\n",prog, STRERROR);        error("%s: Cannot send signal to daemon process -- %s\n",prog, STRERROR);
143        return FALSE;        return FALSE;
144                
145      }      }
# Line 162  int kill_daemon() { Line 151  int kill_daemon() {
151            
152    }    }
153        
154    fprintf(stdout, "%s daemon with pid [%d] killed\n", prog, (int)pid);    if(sig == SIGTERM) {
155    fflush(stdout);            
156        fprintf(stdout, "%s daemon with pid [%d] killed\n", prog, (int)pid);
157        fflush(stdout);
158    
159      }
160        
161    return TRUE;    return TRUE;
162        

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26