Changeset 6157

Show
Ignore:
Timestamp:
09/25/08 15:33:11 (4 months ago)
Author:
morris
Message:

Prepare for launchd

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/P7/wired/wired/main.c

    r6150 r6157  
    8989        wi_array_t                      *arguments; 
    9090        wi_pool_t                       *pool; 
    91         wi_string_t                     *string, *root_path
     91        wi_string_t                     *string, *root_path, *user, *group
    9292        const char                      **xargv; 
    9393        uint32_t                        uid, gid; 
    9494        int                                     ch, facility; 
    95         wi_boolean_t            test_config, daemonize
     95        wi_boolean_t            test_config, daemonize, change_directory, switch_user
    9696 
    9797        wi_initialize(); 
     
    111111        test_config                             = false; 
    112112        daemonize                               = true; 
     113        change_directory                = true; 
     114        switch_user                             = true; 
    113115        wi_settings_config_path = wi_string_init_with_cstring(wi_string_alloc(), WD_CONFIG_PATH); 
    114116        wd_config_path                  = wi_string_init_with_cstring(wi_string_alloc(), WD_CONFIG_PATH); 
     
    116118        root_path                               = WI_STR(WD_ROOT); 
    117119 
    118         while((ch = getopt(argc, (char * const *) argv, "46Dd:f:hi:L:ls:tuVvX")) != -1) { 
     120        while((ch = getopt(argc, (char * const *) argv, "46Dd:f:hi:L:ls:tuVvXx")) != -1) { 
    119121                switch(ch) { 
    120122                        case '4': 
     
    186188                                daemonize = false; 
    187189                                break; 
    188  
     190                         
     191                        case 'x': 
     192                                daemonize = false; 
     193                                change_directory = false; 
     194                                switch_user = false; 
     195                                break; 
     196                         
    189197                        case '?': 
    190198                        case 'h': 
     
    224232        wi_release(arguments); 
    225233         
    226         if(!wi_chdir(root_path)) 
    227                 wi_log_err(WI_STR("Could not change directory to %@: %m"), root_path); 
     234        if(change_directory) { 
     235                if(!wi_fs_change_directory(root_path)) 
     236                        wi_log_err(WI_STR("Could not change directory to %@: %m"), root_path); 
     237        } 
    228238         
    229239        wi_log_open(); 
     
    257267        wi_log_info(WI_STR("Starting Wired version %s (%u)"), WD_VERSION, WI_REVISION); 
    258268         
    259         uid = wi_config_uid_for_name(wd_config, WI_STR("user")); 
    260         gid = wi_config_uid_for_name(wd_config, WI_STR("group")); 
    261          
    262         wi_switch_user(uid, gid); 
     269        if(switch_user) { 
     270                uid = wi_config_uid_for_name(wd_config, WI_STR("user")); 
     271                gid = wi_config_uid_for_name(wd_config, WI_STR("group")); 
     272         
     273                wi_switch_user(uid, gid); 
     274        } 
     275         
     276        user = wi_user_name(); 
     277        group = wi_group_name(); 
     278         
     279        if(user && group) { 
     280                wi_log_info(WI_STR("Operating as user %@ (%d), group %@ (%d)"), 
     281                        user, wi_user_id(), group, wi_group_id()); 
     282        } else { 
     283                wi_log_info(WI_STR("Operating as user %d, group %d"), 
     284                        wi_user_id(), wi_group_id()); 
     285        } 
     286 
    263287        wd_signals_init(); 
    264288        wd_block_signals();