diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/nginx.c | 52 | ||||
-rw-r--r-- | src/core/nginx.h | 1 | ||||
-rw-r--r-- | src/core/ngx_config.h | 4 | ||||
-rw-r--r-- | src/core/ngx_log.c | 7 | ||||
-rw-r--r-- | src/core/ngx_log.h | 36 |
5 files changed, 90 insertions, 10 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index e02866e53..36a8b4bd8 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -16,7 +16,8 @@ static void ngx_clean_old_cycles(ngx_event_t *ev); typedef struct { - int daemon; + int daemon; + ngx_str_t pid; } ngx_core_conf_t; @@ -61,6 +62,7 @@ static ngx_connection_t dumb; u_int ngx_connection_counter; +int done; int restart; int rotate; @@ -73,6 +75,9 @@ int main(int argc, char *const *argv) 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 @@ int main(int argc, char *const *argv) 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 @@ int main(int argc, char *const *argv) 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 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) 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 6a9fd493b..38942aa25 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 b943960b2..bf393f6ab 100644 --- a/src/core/ngx_config.h +++ b/src/core/ngx_config.h @@ -39,7 +39,7 @@ typedef int ngx_int_t; 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 @@ typedef u_int ngx_uint_t; /* 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 fede0a079..98b71c8d3 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -82,13 +82,6 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err, 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 71da9d524..c3771d74a 100644 --- a/src/core/ngx_log.h +++ b/src/core/ngx_log.h @@ -190,6 +190,24 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...); #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 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...); #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 |