]> git.kaiwu.me - nginx.git/commitdiff
nginx-0.0.3-2004-04-12-10:10:53 import
authorIgor Sysoev <igor@sysoev.ru>
Mon, 12 Apr 2004 06:10:53 +0000 (06:10 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 12 Apr 2004 06:10:53 +0000 (06:10 +0000)
src/core/nginx.c
src/core/nginx.h
src/core/ngx_cycle.c
src/event/ngx_event_acceptex.c
src/os/unix/ngx_process_cycle.c

index 3e3a07271e05b91347db1217c0a360c8781e0431..a401ef04623a7bdbd1e22ee286e18f4da7694e3d 100644 (file)
@@ -176,17 +176,17 @@ int main(int argc, char *const *argv)
     if (ccf->pid.len == 0) {
         ccf->pid.len = sizeof(NGINX_PID) - 1;
         ccf->pid.data = NGINX_PID;
-        ccf->newpid.len = sizeof(NGINX_NEW_PID) - 1;
-        ccf->newpid.data = NGINX_NEW_PID;
+        ccf->newpid.len = sizeof(NGINX_NEWPID) - 1;
+        ccf->newpid.data = NGINX_NEWPID;
 
     } else {
-        ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEW_PID_EXT);
+        ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT);
         if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) {
             return 1;
         }
 
         ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
-                   NGINX_NEW_PID_EXT, sizeof(NGINX_NEW_PID_EXT));
+                   NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT));
     }
 
     len = ngx_snprintf((char *) pid, /* STUB */ 10, PID_T_FMT, ngx_getpid());
index 61a6f50e0711688309cdc745520fba9edfa4b4e3..7d755374736c13d99907bd79530ef49ba823a884 100644 (file)
@@ -5,8 +5,8 @@
 #define NGINX_VER          "nginx/0.0.3"
 #define NGINX_CONF         (u_char *) "nginx.conf"
 #define NGINX_PID          "nginx.pid"
-#define NGINX_NEW_PID_EXT  ".newbin"
-#define NGINX_NEW_PID      NGINX_PID NGINX_NEW_PID_EXT
+#define NGINX_NEWPID_EXT   ".newbin"
+#define NGINX_NEWPID       NGINX_PID NGINX_NEWPID_EXT
 
 #define NGINX_VAR          "NGINX"
 
index be0d8f13b8d2de46a67b49285af4a60b893ea3ee..d57041ecf40c1a9a2f6f76141ad943236918b9e3 100644 (file)
@@ -30,6 +30,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
     ngx_cycle_t      *cycle, **old;
     ngx_socket_t      fd;
     ngx_open_file_t  *file;
+    ngx_core_conf_t  *ccf;
     ngx_listening_t  *ls, *nls;
 
     log = old_cycle->log;
@@ -126,6 +127,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
 
     failed = 0;
 
+
+
     file = cycle->open_files.elts;
     for (i = 0; i < cycle->open_files.nelts; i++) {
         if (file[i].name.data == NULL) {
@@ -371,6 +374,91 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
 }
 
 
+static ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
+{
+    size_t             len;
+    u_char             pid[NGX_INT64_LEN + 1];
+    ngx_str_t          name;
+    ngx_core_conf_t   *ccf;
+
+    ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
+
+    if (ctx->pid.len) {
+        if (ccf->pid.len == 0) {
+            return NGX_OK;
+        }
+
+        if (ctx->pid.len == ccf->pid.len
+            && ngx_strcmp(ctx->pid.data, ccf->pid.data) == 0)
+        {
+            return NGX_OK;
+        }
+    }
+    
+    if (ccf->pid.len == 0) {
+        ccf->pid.len = sizeof(NGINX_PID) - 1;
+        ccf->pid.data = NGINX_PID;
+        ccf->newpid.len = sizeof(NGINX_NEWPID) - 1;
+        ccf->newpid.data = NGINX_NEWPID;
+
+    } else {
+        ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT);
+        if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) {
+            return NGX_ERROR;
+        }
+
+        ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
+                   NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT));
+    }
+
+    len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid);
+    ngx_memzero(&ctx->pid, sizeof(ngx_file_t));
+    ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid;
+    ctx->name = ccf->pid.data;
+
+    ctx->pid.fd = ngx_open_file(ctx->pid.name.data, NGX_FILE_RDWR,
+                                NGX_FILE_CREATE_OR_OPEN);
+
+    if (ctx->pid.fd == NGX_INVALID_FILE) {
+        ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+                      ngx_open_file_n " \"%s\" failed", ctx->pid.name.data);
+        return NGX_ERROR;
+    }
+
+    if (ngx_write_file(&ctx->pid, pid, len, 0) == NGX_ERROR) {
+        return NGX_ERROR;
+    }
+
+    if (ngx_close_file(ctx->pid.fd) == NGX_FILE_ERROR) {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                      ngx_close_file_n " \"%s\" failed", ctx->pid.name.data);
+    }
+
+    return NGX_OK;
+}
+
+
+static void ngx_delete_pidfile(ngx_cycle_t *cycle)
+{   
+    u_char           *name;
+    ngx_core_conf_t  *ccf;
+
+    ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
+
+    if (ngx_inherited && getppid() > 1) {
+        name = ccf->newpid.data;
+
+    } else { 
+        name = ccf->pid.data;
+    }
+
+    if (ngx_delete_file(name) == NGX_FILE_ERROR) {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                      ngx_delete_file_n " \"%s\" failed", name);
+    }
+}
+
+
 void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
 {
     ngx_fd_t          fd;
index 7923a022b23c3d6b512caa9b8c00d8fe3bf7cd5b..7efa5c80dc8a1220d2c1dc719426bff5c4e71467 100644 (file)
@@ -46,8 +46,7 @@ void ngx_event_acceptex(ngx_event_t *rev)
 
     ngx_event_post_acceptex(c->listening, 1);
 
-    /* TODO: MT */
-    c->number = ngx_connection_counter++;
+    c->number = ngx_atomic_inc(ngx_connection_counter);
 
     c->listening->handler(c);
 
index 2797670df99d6165528c6577c09d5ef1338fcf28..1b10cfc72c49b2e567abb59933a15a7a44917950 100644 (file)
@@ -12,6 +12,8 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
 static int ngx_worker_thread_cycle(void *data);
 #endif
 
+static void ngx_delete_pidfile(ngx_cycle_t *cycle);
+
 
 ngx_int_t     ngx_process;
 ngx_pid_t     ngx_pid;
@@ -336,21 +338,10 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
 
 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
 {
-    u_char  *name;
-
-    if (ngx_inherited && getppid() > 1) {
-        name = ctx->pid.name.data;
-
-    } else {
-        name = ctx->name;
-    }
-
-    if (ngx_delete_file(name) == NGX_FILE_ERROR) {
-        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
-                      ngx_delete_file_n " \"%s\" failed", name);
-    }
+    ngx_delete_pidfile(cycle);
 
     ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exit");
+
     exit(0);
 }
 
@@ -535,31 +526,44 @@ int ngx_worker_thread_cycle(void *data)
 #endif
 
 
-static ngx_int_t ngx_create_pid_file(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
+static ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
 {
     size_t             len;
     u_char             pid[NGX_INT64_LEN + 1];
+    ngx_str_t          name;
     ngx_core_conf_t   *ccf;
 
     ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
 
+    if (ctx->pid.len) {
+        if (ccf->pid.len == 0) {
+            return NGX_OK;
+        }
+
+        if (ctx->pid.len == ccf->pid.len
+            && ngx_strcmp(ctx->pid.data, ccf->pid.data) == 0)
+        {
+            return NGX_OK;
+        }
+    }
+
     if (ccf->pid.len == 0) {
         ccf->pid.len = sizeof(NGINX_PID) - 1;
         ccf->pid.data = NGINX_PID;
-        ccf->newpid.len = sizeof(NGINX_NEW_PID) - 1;
-        ccf->newpid.data = NGINX_NEW_PID;
+        ccf->newpid.len = sizeof(NGINX_NEWPID) - 1;
+        ccf->newpid.data = NGINX_NEWPID;
 
     } else {
-        ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEW_PID_EXT);
+        ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT);
         if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) {
             return NGX_ERROR;
         }
 
         ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
-                   NGINX_NEW_PID_EXT, sizeof(NGINX_NEW_PID_EXT));
+                   NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT));
     }
 
-    len = ngx_snprintf((char *) pid, /* STUB */ 10, PID_T_FMT, ngx_getpid());
+    len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid);
     ngx_memzero(&ctx->pid, sizeof(ngx_file_t));
     ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid;
     ctx->name = ccf->pid.data;
@@ -584,3 +588,24 @@ static ngx_int_t ngx_create_pid_file(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
 
     return NGX_OK;
 }
+
+
+static void ngx_delete_pidfile(ngx_cycle_t *cycle)
+{
+    u_char           *name;
+    ngx_core_conf_t  *ccf;
+
+    ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
+
+    if (ngx_inherited && getppid() > 1) {
+        name = ccf->newpid.data;
+
+    } else {
+        name = ccf->pid.data;
+    }
+
+    if (ngx_delete_file(name) == NGX_FILE_ERROR) {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                      ngx_delete_file_n " \"%s\" failed", name);
+    }
+}