diff src/core/nginx.c @ 440:f390d1775430

nginx-0.1.0-2004-09-27-20:03:21 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 27 Sep 2004 16:03:21 +0000
parents 8ac40cae79f0
children da8c5707af39
line wrap: on
line diff
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -128,10 +128,6 @@ int main(int argc, char *const *argv)
     ctx.argc = argc;
     ctx.argv = argv;
 
-    if (ngx_getopt(&ctx, &init_cycle) == NGX_ERROR) {
-        return 1;
-    }
-
     if (ngx_os_init(log) == NGX_ERROR) {
         return 1;
     }
@@ -140,6 +136,10 @@ int main(int argc, char *const *argv)
         return 1;
     }
 
+    if (ngx_getopt(&ctx, &init_cycle) == NGX_ERROR) {
+        return 1;
+    }
+
     if (ngx_add_inherited_sockets(&init_cycle) == NGX_ERROR) {
         return 1;
     }
@@ -338,6 +338,10 @@ static ngx_int_t ngx_getopt(ngx_master_c
         cycle->conf_file.data = (u_char *) NGX_CONF_PATH;
     }
 
+    if (ngx_conf_full_name(cycle, &cycle->conf_file) == NGX_ERROR) {
+        return NGX_ERROR;
+    }
+
     return NGX_OK;
 }
 
@@ -372,6 +376,11 @@ static char *ngx_core_module_init_conf(n
 {
     ngx_core_conf_t  *ccf = conf;
 
+#if !(WIN32)
+    struct passwd    *pwd;
+    struct group     *grp;
+#endif
+
     ngx_conf_init_value(ccf->daemon, 1);
     ngx_conf_init_value(ccf->master, 1);
     ngx_conf_init_value(ccf->worker_processes, 1);
@@ -384,24 +393,45 @@ static char *ngx_core_module_init_conf(n
 
 #if !(WIN32)
 
-    /* TODO: default "nobody" user */
+    if (ccf->user == (uid_t) NGX_CONF_UNSET) {
+
+        pwd = getpwnam("nobody");
+        if (pwd == NULL) {
+            ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+                          "getpwnam(\"nobody\") failed");
+            return NGX_CONF_ERROR;
+        }
+
+        ccf->user = pwd->pw_uid;
+
+        grp = getgrnam("nobody");
+        if (grp == NULL) {
+            ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+                          "getgrnam(\"nobody\") failed");
+            return NGX_CONF_ERROR;
+        }
+
+        ccf->group = grp->gr_gid;
+    }
 
     if (ccf->pid.len == 0) {
         ccf->pid.len = sizeof(NGX_PID_PATH) - 1;
         ccf->pid.data = NGX_PID_PATH;
-        ccf->newpid.len = sizeof(NGX_PID_PATH NGX_NEWPID_EXT) - 1;
-        ccf->newpid.data = NGX_PID_PATH NGX_NEWPID_EXT;
+    }
 
-    } else {
-        ccf->newpid.len = ccf->pid.len + sizeof(NGX_NEWPID_EXT);
+    if (ngx_conf_full_name(cycle, &ccf->pid) == NGX_ERROR) {
+        return NGX_CONF_ERROR;
+    }
+
+    ccf->newpid.len = ccf->pid.len + sizeof(NGX_NEWPID_EXT);
 
-        if (!(ccf->newpid.data = ngx_palloc(cycle->pool, ccf->newpid.len))) {
-            return NGX_CONF_ERROR;
-        }
+    if (!(ccf->newpid.data = ngx_palloc(cycle->pool, ccf->newpid.len))) {
+        return NGX_CONF_ERROR;
+    }
 
-        ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
-                   NGX_NEWPID_EXT, sizeof(NGX_NEWPID_EXT));
-    }
+    ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
+               NGX_NEWPID_EXT, sizeof(NGX_NEWPID_EXT));
+
 #endif
 
     return NGX_CONF_OK;