Changeset 5007

Show
Ignore:
Timestamp:
10/24/07 16:44:00 (1 year ago)
Author:
morris
Message:

Sync with wired's new fork behaviour

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trackerd/trunk/trackerd/main.c

    r4570 r5007  
    7474 
    7575int main(int argc, const char **argv) { 
     76        wi_array_t                      *arguments; 
    7677        wi_pool_t                       *pool; 
    7778        wi_string_t                     *string; 
     79        const char                      **xargv; 
    7880        int                                     ch, facility; 
    79         wi_boolean_t            no_chroot, test_config
     81        wi_boolean_t            no_chroot, test_config, daemonize
    8082 
    8183        /* init libwired */ 
     
    98100        no_chroot                               = false; 
    99101        test_config                             = false; 
     102        daemonize                               = true; 
     103 
     104        /* init reexec argument list */ 
     105        arguments                               = wi_array_init(wi_array_alloc()); 
    100106 
    101107        /* parse command line switches */ 
    102         while((ch = getopt(argc, (char * const *) argv, "46Dd:f:hi:L:ls:tuVv")) != -1) { 
     108        while((ch = getopt(argc, (char * const *) argv, "46Dd:f:hi:L:ls:tuVvX")) != -1) { 
    103109                switch(ch) { 
    104110                        case '4': 
     
    165171                                wt_version(); 
    166172                                break; 
    167  
     173                                 
     174                        case 'X': 
     175                                daemonize = false; 
     176                                break; 
     177                                 
    168178                        case '?': 
    169179                        case 'h': 
     
    172182                                break; 
    173183                } 
    174         } 
     184                 
     185                wi_array_add_data(arguments, wi_string_with_format(WI_STR("-%c"), ch)); 
     186                 
     187                if(optarg) 
     188                        wi_array_add_data(arguments, wi_string_with_cstring(optarg)); 
     189        } 
     190         
     191        /* detach */ 
     192        if(daemonize) { 
     193                wi_array_insert_data_at_index(arguments, WI_STR("-X"), 0); 
     194                wi_array_insert_data_at_index(arguments, wi_string_with_cstring(argv[0]), 0); 
     195                 
     196                switch(fork()) { 
     197                        case -1: 
     198                                wi_log_err(WI_STR("Could not fork: %m")); 
     199                                break; 
     200                                 
     201                        case 0: 
     202                                xargv = wi_array_argv(arguments); 
     203                                 
     204                                if(execv(argv[0], (char * const *) xargv) < 0) 
     205                                        wi_log_err(WI_STR("Could not execute %s: %m"), argv[0]); 
     206                                break; 
     207                                 
     208                                default: 
     209                                _exit(0); 
     210                                break; 
     211                } 
     212        } 
     213         
     214        wi_release(arguments); 
    175215         
    176216        /* open log */ 
     
    212252        wi_log_info(WI_STR("Starting Wired Tracker version %@"), wt_version_string); 
    213253        wt_tracker_init(); 
    214  
    215         /* detach (don't chdir, don't close i/o channels) */ 
    216         if(wt_daemonize) { 
    217                 if(!wi_daemon()) 
    218                         wi_log_err(WI_STR("Could not become a daemon: %m")); 
    219         } 
    220254 
    221255        /* switch user/group */