aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/nginx.c29
-rw-r--r--src/core/ngx_atomic.h4
-rw-r--r--src/core/ngx_connection.c7
-rw-r--r--src/core/ngx_core.h2
-rw-r--r--src/core/ngx_cycle.c46
-rw-r--r--src/core/ngx_cycle.h15
-rw-r--r--src/core/ngx_log.c6
-rw-r--r--src/core/ngx_log.h8
8 files changed, 81 insertions, 36 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 21363d268..92c938d60 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -5,6 +5,8 @@
#include <nginx.h>
+#if 0
+
typedef struct {
ngx_flag_t daemon;
ngx_flag_t master;
@@ -30,8 +32,10 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
#if (NGX_THREADS)
static int ngx_worker_thread_cycle(void *data);
#endif
+
+#endif
+
static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp);
-static ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv);
static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle);
static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle);
static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
@@ -110,11 +114,9 @@ ngx_int_t ngx_change_binary;
int main(int argc, char *const *argv, char **envp)
{
- ngx_fd_t fd;
ngx_int_t i;
ngx_log_t *log;
ngx_cycle_t *cycle, init_cycle;
- ngx_open_file_t *file;
ngx_core_conf_t *ccf;
ngx_master_ctx_t ctx;
#if !(WIN32)
@@ -254,6 +256,8 @@ int main(int argc, char *const *argv, char **envp)
}
+#if 0
+
/* TODO: broken NGX_PROCESS_SINGLE */
static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
@@ -744,6 +748,8 @@ int ngx_worker_thread_cycle(void *data)
#endif
+#endif
+
static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp)
{
@@ -791,7 +797,7 @@ static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp)
}
-static ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
+ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
{
char *env[2], *var, *p;
ngx_int_t i;
@@ -885,8 +891,8 @@ static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle)
ccf->daemon = NGX_CONF_UNSET;
ccf->master = NGX_CONF_UNSET;
ccf->worker_reopen = NGX_CONF_UNSET;
- ccf->user = (uid_t) NGX_CONF_UNSET;
- ccf->group = (gid_t) NGX_CONF_UNSET;
+ ccf->user = (ngx_uid_t) NGX_CONF_UNSET;
+ ccf->group = (ngx_gid_t) NGX_CONF_UNSET;
((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf;
@@ -896,6 +902,15 @@ static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle)
static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
+#if (WIN32)
+
+ ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
+ "\"user\" is not supported, ignored");
+
+ return NGX_CONF_OK;
+
+#else
+
struct passwd *pwd;
struct group *grp;
ngx_str_t *value;
@@ -932,4 +947,6 @@ static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ccf->group = grp->gr_gid;
return NGX_CONF_OK;
+
+#endif
}
diff --git a/src/core/ngx_atomic.h b/src/core/ngx_atomic.h
index bf771e95c..17362aa32 100644
--- a/src/core/ngx_atomic.h
+++ b/src/core/ngx_atomic.h
@@ -72,8 +72,8 @@ static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock,
typedef volatile uint32_t ngx_atomic_t;
/* STUB */
-#define ngx_atomic_inc(x) x++;
-#define ngx_atomic_dec(x) x--;
+#define ngx_atomic_inc(x) (*(x))++;
+#define ngx_atomic_dec(x) (*(x))--;
#define ngx_atomic_cmp_set(lock, old, set) 1;
/**/
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
index 989a0de1f..8a858735e 100644
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -248,7 +248,12 @@ ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
return 0;
}
- if (err == NGX_ECONNRESET || err == NGX_EPIPE || err == NGX_ENOTCONN) {
+ if (err == NGX_ECONNRESET
+#if !(WIN32)
+ || err == NGX_EPIPE
+#endif
+ || err == NGX_ENOTCONN)
+ {
switch (c->log_error) {
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h
index 7735ab10b..57bdafc64 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -21,6 +21,7 @@ typedef struct ngx_connection_s ngx_connection_t;
#include <ngx_errno.h>
#include <ngx_process.h>
#include <ngx_thread.h>
+#include <ngx_user.h>
#include <ngx_string.h>
#include <ngx_parse.h>
#include <ngx_log.h>
@@ -39,6 +40,7 @@ typedef struct ngx_connection_s ngx_connection_t;
#include <ngx_times.h>
#include <ngx_inet.h>
#include <ngx_cycle.h>
+#include <ngx_process_cycle.h>
#include <ngx_conf_file.h>
#include <ngx_os.h>
#include <ngx_connection.h>
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index 017db87f1..3827c0d4e 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -24,7 +24,6 @@ static ngx_connection_t dumb;
ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
{
ngx_int_t i, n, failed;
- ngx_str_t conf_file;
ngx_log_t *log;
ngx_conf_t conf;
ngx_pool_t *pool;
@@ -227,13 +226,17 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
}
}
- /* TODO: Win32 DuplicateHandle ? */
- if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
+#if (WIN32)
+ /* TODO: TEST */
+ CloseHandle(GetStdHandle(STD_ERROR_HANDLE));
+ SetStdHandle(STD_ERROR_HANDLE, cycle->log->file->fd);
+#else
+ if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
"dup2(STDERR) failed");
failed = 1;
}
-
+#endif
if (failed) {
@@ -370,7 +373,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
}
-void ngx_reopen_files(ngx_cycle_t *cycle, uid_t user)
+void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
{
ngx_fd_t fd;
ngx_int_t i;
@@ -395,19 +398,6 @@ void ngx_reopen_files(ngx_cycle_t *cycle, uid_t user)
continue;
}
- if (user != (uid_t) -1) {
- if (chown(file[i].name.data, user, -1) == -1) {
- ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
- "chown \"%s\" failed", file[i].name.data);
-
- if (ngx_close_file(fd) == NGX_FILE_ERROR) {
- ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
- ngx_close_file_n " \"%s\" failed",
- file[i].name.data);
- }
- }
- }
-
#if (WIN32)
if (ngx_file_append_mode(fd) == NGX_ERROR) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
@@ -423,6 +413,19 @@ void ngx_reopen_files(ngx_cycle_t *cycle, uid_t user)
continue;
}
#else
+ if (user != (ngx_uid_t) -1) {
+ if (chown(file[i].name.data, user, -1) == -1) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "chown \"%s\" failed", file[i].name.data);
+
+ if (ngx_close_file(fd) == NGX_FILE_ERROR) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ ngx_close_file_n " \"%s\" failed",
+ file[i].name.data);
+ }
+ }
+ }
+
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"fcntl(FD_CLOEXEC) \"%s\" failed",
@@ -447,11 +450,16 @@ void ngx_reopen_files(ngx_cycle_t *cycle, uid_t user)
file[i].fd = fd;
}
- /* TODO: Win32 DuplicateHandle ? */
+#if (WIN32)
+ /* TODO: TEST */
+ CloseHandle(GetStdHandle(STD_ERROR_HANDLE));
+ SetStdHandle(STD_ERROR_HANDLE, cycle->log->file->fd);
+#else
if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"dup2(STDERR) failed");
}
+#endif
}
diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h
index d9f1a607b..4d301f94d 100644
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -25,12 +25,25 @@ struct ngx_cycle_s {
};
+typedef struct {
+ ngx_flag_t daemon;
+ ngx_flag_t master;
+ ngx_flag_t worker_reopen;
+ ngx_uid_t user;
+ ngx_gid_t group;
+ ngx_str_t pid;
+ ngx_str_t newpid;
+} ngx_core_conf_t;
+
+
ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle);
-void ngx_reopen_files(ngx_cycle_t *cycle, uid_t user);
+void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user);
+ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv);
extern volatile ngx_cycle_t *ngx_cycle;
extern ngx_array_t ngx_old_cycles;
+extern ngx_module_t ngx_core_module;
#endif /* _NGX_CYCLE_H_INCLUDED_ */
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 349fe6bb1..371c72519 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -47,10 +47,10 @@ static const char *debug_levels[] = {
#if (HAVE_VARIADIC_MACROS)
-void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
+void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, ...)
#else
-void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
+void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, va_list args)
#endif
{
@@ -176,7 +176,7 @@ static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len)
#if !(HAVE_VARIADIC_MACROS)
-void ngx_log_error(int level, ngx_log_t *log, ngx_err_t err,
+void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, ...)
{
va_list args;
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
index 375acae73..d1fdab63d 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
@@ -92,7 +92,7 @@ struct ngx_log_s {
#define ngx_log_error(level, log, args...) \
if (log->log_level >= level) ngx_log_error_core(level, log, args)
-void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
+void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, ...);
/*********************************/
@@ -104,7 +104,7 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
#define ngx_log_error(level, log, ...) \
if (log->log_level >= level) ngx_log_error_core(level, log, __VA_ARGS__)
-void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
+void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, ...);
/*********************************/
@@ -113,9 +113,9 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
#define HAVE_VARIADIC_MACROS 0
-void ngx_log_error(int level, ngx_log_t *log, ngx_err_t err,
+void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, ...);
-void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
+void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, va_list args);
void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...);
void ngx_assert_core(ngx_log_t *log, const char *fmt, ...);