Changeset 5265

Show
Ignore:
Timestamp:
02/14/08 06:05:54 (8 months ago)
Author:
morris
Message:

Change the way the root path is set up

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libwired/trunk/libwired/base/wi-base.c

    r4700 r5265  
    186186#pragma mark - 
    187187 
    188 wi_string_t * wi_full_path(wi_string_t *path) { 
    189         if(!path) 
    190                 return NULL; 
    191         else if(!wi_root_path) 
    192                 return path; 
    193         else if(wi_string_has_prefix(path, WI_STR("/"))) 
    194                 return path; 
    195         else if(wi_chrooted) 
    196                 return wi_string_with_format(WI_STR("/%@"), path); 
    197         else 
    198                 return wi_string_with_format(WI_STR("%@/%@"), wi_root_path, path); 
    199 } 
    200  
    201  
    202  
    203 #pragma mark - 
    204  
    205188wi_hash_code_t wi_hash_cstring(const char *s, wi_uinteger_t length) { 
    206189        wi_hash_code_t  hash = length; 
  • libwired/trunk/libwired/base/wi-base.h

    r4645 r5265  
    206206WI_EXPORT void                                          wi_crash(void); 
    207207 
    208  
    209 WI_EXPORT wi_string_t                           *wi_root_path; 
    210  
    211208#endif /* WI_BASE_H */ 
  • libwired/trunk/libwired/base/wi-private.h

    r4774 r5265  
    170170WI_EXPORT void *                                wi_thread_poolstack(wi_thread_t *); 
    171171 
    172  
    173 WI_EXPORT wi_boolean_t                  wi_chrooted; 
    174  
    175172#endif /* WI_PRIVATE_H */ 
  • libwired/trunk/libwired/misc/wi-settings.c

    r4853 r5265  
    4747#include <wired/wi-settings.h> 
    4848#include <wired/wi-string.h> 
     49#include <wired/wi-system.h> 
    4950#include <wired/wi-regexp.h> 
    5051#include <wired/wi-runtime.h> 
     
    145146        wi_file_t               *file; 
    146147        wi_string_t             *path, *string; 
    147         wi_boolean_t    result = true; 
    148          
    149         path = wi_full_path(wi_settings_config_path); 
     148         
     149        path = wi_path_relative_to_root(wi_settings_config_path); 
    150150        file = wi_file_for_reading(path); 
    151151         
     
    167167                settings->line++; 
    168168 
    169                 if(wi_string_length(string) > 0 && !wi_string_has_prefix(string, WI_STR("#"))) { 
    170                         if(!_wi_settings_parse_setting(settings, string)) 
    171                                 result = false; 
    172                 } 
     169                if(wi_string_length(string) > 0 && !wi_string_has_prefix(string, WI_STR("#"))) 
     170                        _wi_settings_parse_setting(settings, string); 
    173171        } 
    174172 
    175173        settings->file = NULL; 
    176174 
    177         return result
     175        return true
    178176} 
    179177 
     
    348346                wi_release(*string); 
    349347 
    350         if(wi_string_has_prefix(value, WI_STR("/"))) 
    351                 *string = wi_retain(value); 
    352         else if(settings->chroot) 
    353                 *string = wi_string_init_with_format(wi_string_alloc(), WI_STR("/%@"), value); 
    354         else 
    355                 *string = wi_string_init_with_format(wi_string_alloc(), WI_STR("%@/%@"), wi_root_path, value); 
    356  
    357         wi_string_normalize_path(*string); 
     348        *string = wi_retain(wi_path_relative_to_root(value)); 
    358349         
    359350        return true; 
  • libwired/trunk/libwired/system/wi-log.c

    r5148 r5265  
    5252#include <wired/wi-private.h> 
    5353#include <wired/wi-string.h> 
     54#include <wired/wi-system.h> 
    5455 
    5556#define _WI_LOG_DATE_SIZE               32 
     
    189190 
    190191                if(wi_log_file && wi_log_path) { 
    191                         path = wi_string_cstring(wi_full_path(wi_log_path)); 
     192                        path = wi_string_cstring(wi_path_relative_to_root(wi_log_path)); 
    192193 
    193194                        fp = fopen(path, "a"); 
  • libwired/trunk/libwired/system/wi-system.c

    r5004 r5265  
    5656#include <wired/wi-system.h> 
    5757 
    58 wi_boolean_t wi_change_root(void) { 
     58static wi_string_t                                      *wi_root_path; 
     59static wi_boolean_t                                     wi_chrooted = false; 
     60 
     61 
     62void wi_set_root_path(wi_string_t *path) { 
     63        wi_retain(path); 
     64        wi_release(wi_root_path); 
     65         
     66        wi_root_path = path; 
     67
     68 
     69 
     70 
     71wi_boolean_t wi_chroot_to_root_path(void) { 
    5972        tzset(); 
    6073         
     
    7588 
    7689 
     90 
     91wi_string_t * wi_path_relative_to_root(wi_string_t *path) { 
     92        if(path && wi_root_path && !wi_string_has_prefix(path, WI_STR("/"))) { 
     93                if(wi_chrooted) 
     94                        path = wi_string_with_format(WI_STR("/%@"), path); 
     95                else 
     96                        path = wi_string_with_format(WI_STR("%@/%@"), wi_root_path, path); 
     97        } 
     98         
     99        return wi_string_by_normalizing_path(path); 
     100} 
     101 
     102 
     103 
     104#pragma mark - 
    77105 
    78106void wi_switch_user(uid_t uid, gid_t gid) { 
     
    83111        gid_t                   egid; 
    84112         
    85         path = wi_full_path(wi_log_path); 
     113        path = wi_path_relative_to_root(wi_log_path); 
    86114 
    87115        if(path) { 
  • libwired/trunk/libwired/system/wi-system.h

    r5006 r5265  
    3636#include <wired/wi-base.h> 
    3737 
    38 WI_EXPORT wi_boolean_t                  wi_change_root(void); 
     38WI_EXPORT void                                  wi_set_root_path(wi_string_t *); 
     39WI_EXPORT wi_boolean_t                  wi_chroot_to_root_path(void); 
     40WI_EXPORT wi_string_t *                 wi_path_relative_to_root(wi_string_t *); 
    3941 
    4042WI_EXPORT void                                  wi_switch_user(uid_t, gid_t);