Diff for /embedaddon/miniupnpd/daemonize.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2012/05/29 12:55:57 version 1.1.1.3, 2013/07/22 00:32:35
Line 1 Line 1
 /* $Id$ */  /* $Id$ */
 /* MiniUPnP project  /* MiniUPnP project
  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/   * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
 * (c) 2006 Thomas Bernard  * (c) 2006 Thomas Bernard
  * This software is subject to the conditions detailed   * This software is subject to the conditions detailed
  * in the LICENCE file provided within the distribution */   * in the LICENCE file provided within the distribution */
   
Line 31  daemonize(void) Line 31  daemonize(void)
         case -1:          case -1:
                 perror("fork()");                  perror("fork()");
                 exit(1);                  exit(1);
        
         /* child process */          /* child process */
         case 0:          case 0:
                 /* obtain a new process group */                  /* obtain a new process group */
Line 42  daemonize(void) Line 42  daemonize(void)
                 }                  }
   
                 /* close all descriptors */                  /* close all descriptors */
                for (i=getdtablesize();i>=0;--i) close(i);                              for (i=getdtablesize();i>=0;--i) close(i);
   
                 i = open("/dev/null", O_RDWR); /* open stdin */                  i = open("/dev/null", O_RDWR); /* open stdin */
                 dup(i); /* stdout */                  dup(i); /* stdout */
                 dup(i); /* stderr */                  dup(i); /* stderr */
   
                 umask(027);                  umask(027);
                chdir("/"); /* chdir to /tmp ? */                                       chdir("/"); /* chdir to /tmp ? */
   
                 return pid;                  return pid;
   
Line 69  writepidfile(const char * fname, int pid) Line 69  writepidfile(const char * fname, int pid)
   
         if(!fname || (strlen(fname) == 0))          if(!fname || (strlen(fname) == 0))
                 return -1;                  return -1;
        
         if( (pidfile = open(fname, O_WRONLY|O_CREAT, 0644)) < 0)          if( (pidfile = open(fname, O_WRONLY|O_CREAT, 0644)) < 0)
         {          {
                 syslog(LOG_ERR, "Unable to open pidfile for writing %s: %m", fname);                  syslog(LOG_ERR, "Unable to open pidfile for writing %s: %m", fname);
Line 79  writepidfile(const char * fname, int pid) Line 79  writepidfile(const char * fname, int pid)
         pidstringlen = snprintf(pidstring, sizeof(pidstring), "%d\n", pid);          pidstringlen = snprintf(pidstring, sizeof(pidstring), "%d\n", pid);
         if(pidstringlen <= 0)          if(pidstringlen <= 0)
         {          {
                syslog(LOG_ERR,                 syslog(LOG_ERR,
                         "Unable to write to pidfile %s: snprintf(): FAILED", fname);                          "Unable to write to pidfile %s: snprintf(): FAILED", fname);
                 close(pidfile);                  close(pidfile);
                 return -1;                  return -1;
Line 107  checkforrunning(const char * fname) Line 107  checkforrunning(const char * fname)
   
         if( (pidfile = open(fname, O_RDONLY)) < 0)          if( (pidfile = open(fname, O_RDONLY)) < 0)
                 return 0;                  return 0;
        
         memset(buffer, 0, 64);          memset(buffer, 0, 64);
        
         if(read(pidfile, buffer, 63))          if(read(pidfile, buffer, 63))
         {          {
                 if( (pid = atol(buffer)) > 0)                  if( (pid = atol(buffer)) > 0)
Line 121  checkforrunning(const char * fname) Line 121  checkforrunning(const char * fname)
                         }                          }
                 }                  }
         }          }
        
         close(pidfile);          close(pidfile);
        
         return 0;          return 0;
 }  }
   

Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>