nginx-0.0.1-2003-12-14-23:10:27 import
diff --git a/src/core/nginx.c b/src/core/nginx.c
index e02866e..36a8b4b 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -16,7 +16,8 @@
typedef struct {
- int daemon;
+ int daemon;
+ ngx_str_t pid;
} ngx_core_conf_t;
@@ -61,6 +62,7 @@
u_int ngx_connection_counter;
+int done;
int restart;
int rotate;
@@ -73,6 +75,9 @@
ngx_cycle_t *cycle;
ngx_open_file_t *file;
#if !(WIN32)
+ size_t len;
+ char pid[/* STUB */ 10];
+ ngx_file_t pidfile;
ngx_core_conf_t *ccf;
#endif
@@ -119,6 +124,33 @@
return 1;
}
+ if (ccf->pid.len == 0) {
+ ccf->pid.len = sizeof(NGINX_PID) - 1;
+ ccf->pid.data = NGINX_PID;
+ }
+
+ len = ngx_snprintf(pid, /* STUB */ 10, PID_T_FMT, ngx_getpid());
+ ngx_memzero(&pidfile, sizeof(ngx_file_t));
+ pidfile.name = ccf->pid;
+
+ pidfile.fd = ngx_open_file(pidfile.name.data, NGX_FILE_RDWR,
+ NGX_FILE_CREATE_OR_OPEN);
+
+ if (pidfile.fd == NGX_INVALID_FILE) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ ngx_open_file_n " \"%s\" failed", pidfile.name.data);
+ return 1;
+ }
+
+ if (ngx_write_file(&pidfile, pid, len, 0) == NGX_ERROR) {
+ return 1;
+ }
+
+ if (ngx_close_file(pidfile.fd) == NGX_FILE_ERROR) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ ngx_close_file_n " \"%s\" failed", pidfile.name.data);
+ }
+
#endif
/* life cycle */
@@ -162,8 +194,20 @@
ngx_process_events(cycle->log);
+ if (done) {
+ if (ngx_delete_file(pidfile.name.data) == NGX_FILE_ERROR) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ ngx_delete_file_n " \"%s\" failed",
+ pidfile.name.data);
+ }
+
+ ngx_log_error(NGX_LOG_INFO,
+ cycle->log, 0, "exiting");
+ exit(0);
+ }
+
if (rotate) {
- ngx_log_debug(cycle->log, "rotate");
+ ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "rotating logs");
file = cycle->open_files.elts;
for (i = 0; i < cycle->open_files.nelts; i++) {
@@ -313,6 +357,10 @@
ngx_destroy_pool(pool);
return NULL;
}
+ /* set by pcalloc()
+ *
+ * ccf->pid = NULL;
+ */
ccf->daemon = -1;
((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf;
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 6a9fd49..38942aa 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -4,6 +4,7 @@
#define NGINX_VER "nginx/0.0.1"
#define NGINX_CONF "nginx.conf"
+#define NGINX_PID "nginx.pid"
extern int ngx_max_module;
diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h
index b943960..bf393f6 100644
--- a/src/core/ngx_config.h
+++ b/src/core/ngx_config.h
@@ -39,7 +39,7 @@
typedef u_int ngx_uint_t;
/* STUB: autoconf */
-#define PTR_FMT "%X"
+#define PTR_FMT "%08X"
#include <ngx_auto_config.h>
@@ -60,6 +60,8 @@
/* TODO: #ifndef */
#define NGX_RESTART_SIGNAL HUP
#define NGX_ROTATE_SIGNAL USR1
+#define NGX_SHUTDOWN_SIGNAL TERM
+#define NGX_INTERRUPT_SIGNAL INT
#endif
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index fede0a0..98b71c8 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -82,13 +82,6 @@
len = ngx_cached_err_log_time.len;
-#if 0
- ngx_localtime(&tm);
- len = ngx_snprintf(errstr, sizeof(errstr), "%4d/%02d/%02d %02d:%02d:%02d",
- tm.ngx_tm_year, tm.ngx_tm_mon, tm.ngx_tm_mday,
- tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec);
-#endif
-
len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
" [%s] ", err_levels[level]);
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
index 71da9d5..c3771d7 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
@@ -190,6 +190,24 @@
#define ngx_log_debug1(level, log, err, fmt, arg1)
#endif
+#if (NGX_DEBUG)
+#define ngx_log_debug2(level, log, err, fmt, arg1, arg2) \
+ if (log->log_level & level) \
+ ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, arg1, arg2)
+#else
+#define ngx_log_debug2(level, log, err, fmt, arg1, arg2)
+#endif
+
+#if (NGX_DEBUG)
+#define ngx_log_debug6(level, log, err, fmt, \
+ arg1, arg2, arg3, arg4, arg5, arg6) \
+ if (log->log_level & level) \
+ ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, \
+ arg1, arg2, arg3, arg4, arg5, arg6)
+#else
+#define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
+#endif
+
/*********************************/
#else /* NO VARIADIC MACROS */
@@ -209,6 +227,24 @@
#else
#define ngx_log_debug1(level, log, err, fmt, arg1)
#endif
+
+#if (NGX_DEBUG)
+#define ngx_log_debug2(level, log, err, fmt, arg1, arg2) \
+ if (log->log_level & level) \
+ ngx_log_debug_core(log, err, fmt, arg1, arg2)
+#else
+#define ngx_log_debug2(level, log, err, fmt, arg1, arg2)
+#endif
+
+#if (NGX_DEBUG)
+#define ngx_log_debug6(level, log, err, fmt, \
+ arg1, arg2, arg3, arg4, arg5, arg6) \
+ if (log->log_level & level) \
+ ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
+#else
+#define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
+#endif
+
#endif