Changeset 513 for trunk/src/ocat.c


Ignore:
Timestamp:
09/17/09 14:55:32 (3 years ago)
Author:
eagle
Message:

OC should now detach properly from console

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ocat.c

    r511 r513  
    126126      case 0: 
    127127         log_msg(LOG_INFO, "process backgrounded by parent %d, new pid = %d", ppid, getpid()); 
     128         (void) umask(0); 
     129         if (setsid() == -1) 
     130            log_msg(LOG_ERR, "could not set process group ID: \"%s\"", strerror(errno)); 
     131         if (chdir("/") == -1) 
     132            log_msg(LOG_ERR, "could not change directory to /: \"%s\"", strerror(errno)); 
     133         // redirect standard files to /dev/null 
     134         if (!freopen( "/dev/null", "r", stdin)) 
     135            log_msg(LOG_ERR, "could not reconnect stdin to /dev/null: \"%s\"", strerror(errno)); 
     136         if (!freopen( "/dev/null", "w", stdout)) 
     137            log_msg(LOG_ERR, "could not reconnect stdout to /dev/null: \"%s\"", strerror(errno)); 
     138         if (!freopen( "/dev/null", "w", stderr)) 
     139            log_msg(LOG_ERR, "could not reconnect stderr to /dev/null: \"%s\"", strerror(errno)); 
    128140         return; 
    129141 
     
    224236   struct passwd *pwd, pwdm; 
    225237   int urlconv = 0; 
    226    int nullfd; 
    227238 
    228239   snprintf(def, 100, "127.0.0.1:%d", OCAT_LISTEN_PORT); 
     
    467478      open_connect_log(pwd->pw_dir); 
    468479 
    469    // reconnect stdio if logfile ok and daemonized 
    470    if (CNF(daemon)) 
    471    { 
    472       if ((nullfd = open("/dev/null", O_RDWR)) != -1) 
    473       { 
    474          oe_close(0); 
    475          dup(nullfd); 
    476          oe_close(1); 
    477          dup(nullfd); 
    478          oe_close(2); 
    479          dup(nullfd); 
    480       } 
    481       else 
    482          log_msg(LOG_ERR, "could not reconnect stdio to /dev/null: \"%s\"", strerror(errno)); 
    483    } 
    484  
    485480   // create socks connector thread and communication queue 
    486481   if (pipe(CNF(socksfd)) == -1) 
Note: See TracChangeset for help on using the changeset viewer.