Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-04-09 20:03:04 +0400
committerIgor Sysoev <igor@sysoev.ru>2004-04-09 20:03:04 +0400
commit407b0deeaf8455b220f0fdc5754d599dd3830a46 (patch)
treedfcbd24e036064ead477df71c4a3ee77562178d5 /src/os/unix/ngx_process_cycle.c
parent3d3d2e4700e2de6d6864c2164dccff6e78c51b3d (diff)
nginx-0.0.3-2004-04-09-20:03:04 import
Diffstat (limited to 'src/os/unix/ngx_process_cycle.c')
-rw-r--r--src/os/unix/ngx_process_cycle.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index 2410671f1..2797670df 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -3,6 +3,8 @@
#include <ngx_core.h>
#include <ngx_event.h>
+#include <nginx.h>
+
static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx);
static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
@@ -531,3 +533,54 @@ 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)
+{
+ size_t len;
+ u_char pid[NGX_INT64_LEN + 1];
+ ngx_core_conf_t *ccf;
+
+ ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
+
+ 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;
+
+ } else {
+ ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEW_PID_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));
+ }
+
+ len = ngx_snprintf((char *) pid, /* STUB */ 10, PID_T_FMT, ngx_getpid());
+ 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;
+}