source: nginx/src/core/nginx.c

Last change on this file was 7248:fdd6a070d518, checked in by Ruslan Ermilov <ru@…>, 2 years ago

Improved code readability (closes #1512).

File size: 37.7 KB
Line 
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
5 */
6
7
8#include <ngx_config.h>
9#include <ngx_core.h>
10#include <nginx.h>
11
12
13static void ngx_show_version_info(void);
14static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle);
15static void ngx_cleanup_environment(void *data);
16static ngx_int_t ngx_get_options(int argc, char *const *argv);
17static ngx_int_t ngx_process_options(ngx_cycle_t *cycle);
18static ngx_int_t ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv);
19static void *ngx_core_module_create_conf(ngx_cycle_t *cycle);
20static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf);
21static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
22static char *ngx_set_env(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
23static char *ngx_set_priority(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
24static char *ngx_set_cpu_affinity(ngx_conf_t *cf, ngx_command_t *cmd,
25 void *conf);
26static char *ngx_set_worker_processes(ngx_conf_t *cf, ngx_command_t *cmd,
27 void *conf);
28static char *ngx_load_module(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
29#if (NGX_HAVE_DLOPEN)
30static void ngx_unload_module(void *data);
31#endif
32
33
34static ngx_conf_enum_t ngx_debug_points[] = {
35 { ngx_string("stop"), NGX_DEBUG_POINTS_STOP },
36 { ngx_string("abort"), NGX_DEBUG_POINTS_ABORT },
37 { ngx_null_string, 0 }
38};
39
40
41static ngx_command_t ngx_core_commands[] = {
42
43 { ngx_string("daemon"),
44 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_FLAG,
45 ngx_conf_set_flag_slot,
46 0,
47 offsetof(ngx_core_conf_t, daemon),
48 NULL },
49
50 { ngx_string("master_process"),
51 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_FLAG,
52 ngx_conf_set_flag_slot,
53 0,
54 offsetof(ngx_core_conf_t, master),
55 NULL },
56
57 { ngx_string("timer_resolution"),
58 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
59 ngx_conf_set_msec_slot,
60 0,
61 offsetof(ngx_core_conf_t, timer_resolution),
62 NULL },
63
64 { ngx_string("pid"),
65 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
66 ngx_conf_set_str_slot,
67 0,
68 offsetof(ngx_core_conf_t, pid),
69 NULL },
70
71 { ngx_string("lock_file"),
72 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
73 ngx_conf_set_str_slot,
74 0,
75 offsetof(ngx_core_conf_t, lock_file),
76 NULL },
77
78 { ngx_string("worker_processes"),
79 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
80 ngx_set_worker_processes,
81 0,
82 0,
83 NULL },
84
85 { ngx_string("debug_points"),
86 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
87 ngx_conf_set_enum_slot,
88 0,
89 offsetof(ngx_core_conf_t, debug_points),
90 &ngx_debug_points },
91
92 { ngx_string("user"),
93 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE12,
94 ngx_set_user,
95 0,
96 0,
97 NULL },
98
99 { ngx_string("worker_priority"),
100 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
101 ngx_set_priority,
102 0,
103 0,
104 NULL },
105
106 { ngx_string("worker_cpu_affinity"),
107 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_1MORE,
108 ngx_set_cpu_affinity,
109 0,
110 0,
111 NULL },
112
113 { ngx_string("worker_rlimit_nofile"),
114 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
115 ngx_conf_set_num_slot,
116 0,
117 offsetof(ngx_core_conf_t, rlimit_nofile),
118 NULL },
119
120 { ngx_string("worker_rlimit_core"),
121 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
122 ngx_conf_set_off_slot,
123 0,
124 offsetof(ngx_core_conf_t, rlimit_core),
125 NULL },
126
127 { ngx_string("worker_shutdown_timeout"),
128 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
129 ngx_conf_set_msec_slot,
130 0,
131 offsetof(ngx_core_conf_t, shutdown_timeout),
132 NULL },
133
134 { ngx_string("working_directory"),
135 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
136 ngx_conf_set_str_slot,
137 0,
138 offsetof(ngx_core_conf_t, working_directory),
139 NULL },
140
141 { ngx_string("env"),
142 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
143 ngx_set_env,
144 0,
145 0,
146 NULL },
147
148 { ngx_string("load_module"),
149 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
150 ngx_load_module,
151 0,
152 0,
153 NULL },
154
155 ngx_null_command
156};
157
158
159static ngx_core_module_t ngx_core_module_ctx = {
160 ngx_string("core"),
161 ngx_core_module_create_conf,
162 ngx_core_module_init_conf
163};
164
165
166ngx_module_t ngx_core_module = {
167 NGX_MODULE_V1,
168 &ngx_core_module_ctx, /* module context */
169 ngx_core_commands, /* module directives */
170 NGX_CORE_MODULE, /* module type */
171 NULL, /* init master */
172 NULL, /* init module */
173 NULL, /* init process */
174 NULL, /* init thread */
175 NULL, /* exit thread */
176 NULL, /* exit process */
177 NULL, /* exit master */
178 NGX_MODULE_V1_PADDING
179};
180
181
182static ngx_uint_t ngx_show_help;
183static ngx_uint_t ngx_show_version;
184static ngx_uint_t ngx_show_configure;
185static u_char *ngx_prefix;
186static u_char *ngx_conf_file;
187static u_char *ngx_conf_params;
188static char *ngx_signal;
189
190
191static char **ngx_os_environ;
192
193
194int ngx_cdecl
195main(int argc, char *const *argv)
196{
197 ngx_buf_t *b;
198 ngx_log_t *log;
199 ngx_uint_t i;
200 ngx_cycle_t *cycle, init_cycle;
201 ngx_conf_dump_t *cd;
202 ngx_core_conf_t *ccf;
203
204 ngx_debug_init();
205
206 if (ngx_strerror_init() != NGX_OK) {
207 return 1;
208 }
209
210 if (ngx_get_options(argc, argv) != NGX_OK) {
211 return 1;
212 }
213
214 if (ngx_show_version) {
215 ngx_show_version_info();
216
217 if (!ngx_test_config) {
218 return 0;
219 }
220 }
221
222 /* TODO */ ngx_max_sockets = -1;
223
224 ngx_time_init();
225
226#if (NGX_PCRE)
227 ngx_regex_init();
228#endif
229
230 ngx_pid = ngx_getpid();
231 ngx_parent = ngx_getppid();
232
233 log = ngx_log_init(ngx_prefix);
234 if (log == NULL) {
235 return 1;
236 }
237
238 /* STUB */
239#if (NGX_OPENSSL)
240 ngx_ssl_init(log);
241#endif
242
243 /*
244 * init_cycle->log is required for signal handlers and
245 * ngx_process_options()
246 */
247
248 ngx_memzero(&init_cycle, sizeof(ngx_cycle_t));
249 init_cycle.log = log;
250 ngx_cycle = &init_cycle;
251
252 init_cycle.pool = ngx_create_pool(1024, log);
253 if (init_cycle.pool == NULL) {
254 return 1;
255 }
256
257 if (ngx_save_argv(&init_cycle, argc, argv) != NGX_OK) {
258 return 1;
259 }
260
261 if (ngx_process_options(&init_cycle) != NGX_OK) {
262 return 1;
263 }
264
265 if (ngx_os_init(log) != NGX_OK) {
266 return 1;
267 }
268
269 /*
270 * ngx_crc32_table_init() requires ngx_cacheline_size set in ngx_os_init()
271 */
272
273 if (ngx_crc32_table_init() != NGX_OK) {
274 return 1;
275 }
276
277 /*
278 * ngx_slab_sizes_init() requires ngx_pagesize set in ngx_os_init()
279 */
280
281 ngx_slab_sizes_init();
282
283 if (ngx_add_inherited_sockets(&init_cycle) != NGX_OK) {
284 return 1;
285 }
286
287 if (ngx_preinit_modules() != NGX_OK) {
288 return 1;
289 }
290
291 cycle = ngx_init_cycle(&init_cycle);
292 if (cycle == NULL) {
293 if (ngx_test_config) {
294 ngx_log_stderr(0, "configuration file %s test failed",
295 init_cycle.conf_file.data);
296 }
297
298 return 1;
299 }
300
301 if (ngx_test_config) {
302 if (!ngx_quiet_mode) {
303 ngx_log_stderr(0, "configuration file %s test is successful",
304 cycle->conf_file.data);
305 }
306
307 if (ngx_dump_config) {
308 cd = cycle->config_dump.elts;
309
310 for (i = 0; i < cycle->config_dump.nelts; i++) {
311
312 ngx_write_stdout("# configuration file ");
313 (void) ngx_write_fd(ngx_stdout, cd[i].name.data,
314 cd[i].name.len);
315 ngx_write_stdout(":" NGX_LINEFEED);
316
317 b = cd[i].buffer;
318
319 (void) ngx_write_fd(ngx_stdout, b->pos, b->last - b->pos);
320 ngx_write_stdout(NGX_LINEFEED);
321 }
322 }
323
324 return 0;
325 }
326
327 if (ngx_signal) {
328 return ngx_signal_process(cycle, ngx_signal);
329 }
330
331 ngx_os_status(cycle->log);
332
333 ngx_cycle = cycle;
334
335 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
336
337 if (ccf->master && ngx_process == NGX_PROCESS_SINGLE) {
338 ngx_process = NGX_PROCESS_MASTER;
339 }
340
341#if !(NGX_WIN32)
342
343 if (ngx_init_signals(cycle->log) != NGX_OK) {
344 return 1;
345 }
346
347 if (!ngx_inherited && ccf->daemon) {
348 if (ngx_daemon(cycle->log) != NGX_OK) {
349 return 1;
350 }
351
352 ngx_daemonized = 1;
353 }
354
355 if (ngx_inherited) {
356 ngx_daemonized = 1;
357 }
358
359#endif
360
361 if (ngx_create_pidfile(&ccf->pid, cycle->log) != NGX_OK) {
362 return 1;
363 }
364
365 if (ngx_log_redirect_stderr(cycle) != NGX_OK) {
366 return 1;
367 }
368
369 if (log->file->fd != ngx_stderr) {
370 if (ngx_close_file(log->file->fd) == NGX_FILE_ERROR) {
371 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
372 ngx_close_file_n " built-in log failed");
373 }
374 }
375
376 ngx_use_stderr = 0;
377
378 if (ngx_process == NGX_PROCESS_SINGLE) {
379 ngx_single_process_cycle(cycle);
380
381 } else {
382 ngx_master_process_cycle(cycle);
383 }
384
385 return 0;
386}
387
388
389static void
390ngx_show_version_info(void)
391{
392 ngx_write_stderr("nginx version: " NGINX_VER_BUILD NGX_LINEFEED);
393
394 if (ngx_show_help) {
395 ngx_write_stderr(
396 "Usage: nginx [-?hvVtTq] [-s signal] [-c filename] "
397 "[-p prefix] [-g directives]" NGX_LINEFEED
398 NGX_LINEFEED
399 "Options:" NGX_LINEFEED
400 " -?,-h : this help" NGX_LINEFEED
401 " -v : show version and exit" NGX_LINEFEED
402 " -V : show version and configure options then exit"
403 NGX_LINEFEED
404 " -t : test configuration and exit" NGX_LINEFEED
405 " -T : test configuration, dump it and exit"
406 NGX_LINEFEED
407 " -q : suppress non-error messages "
408 "during configuration testing" NGX_LINEFEED
409 " -s signal : send signal to a master process: "
410 "stop, quit, reopen, reload" NGX_LINEFEED
411#ifdef NGX_PREFIX
412 " -p prefix : set prefix path (default: " NGX_PREFIX ")"
413 NGX_LINEFEED
414#else
415 " -p prefix : set prefix path (default: NONE)" NGX_LINEFEED
416#endif
417 " -c filename : set configuration file (default: " NGX_CONF_PATH
418 ")" NGX_LINEFEED
419 " -g directives : set global directives out of configuration "
420 "file" NGX_LINEFEED NGX_LINEFEED
421 );
422 }
423
424 if (ngx_show_configure) {
425
426#ifdef NGX_COMPILER
427 ngx_write_stderr("built by " NGX_COMPILER NGX_LINEFEED);
428#endif
429
430#if (NGX_SSL)
431 if (ngx_strcmp(ngx_ssl_version(), OPENSSL_VERSION_TEXT) == 0) {
432 ngx_write_stderr("built with " OPENSSL_VERSION_TEXT NGX_LINEFEED);
433 } else {
434 ngx_write_stderr("built with " OPENSSL_VERSION_TEXT
435 " (running with ");
436 ngx_write_stderr((char *) (uintptr_t) ngx_ssl_version());
437 ngx_write_stderr(")" NGX_LINEFEED);
438 }
439#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
440 ngx_write_stderr("TLS SNI support enabled" NGX_LINEFEED);
441#else
442 ngx_write_stderr("TLS SNI support disabled" NGX_LINEFEED);
443#endif
444#endif
445
446 ngx_write_stderr("configure arguments:" NGX_CONFIGURE NGX_LINEFEED);
447 }
448}
449
450
451static ngx_int_t
452ngx_add_inherited_sockets(ngx_cycle_t *cycle)
453{
454 u_char *p, *v, *inherited;
455 ngx_int_t s;
456 ngx_listening_t *ls;
457
458 inherited = (u_char *) getenv(NGINX_VAR);
459
460 if (inherited == NULL) {
461 return NGX_OK;
462 }
463
464 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
465 "using inherited sockets from \"%s\"", inherited);
466
467 if (ngx_array_init(&cycle->listening, cycle->pool, 10,
468 sizeof(ngx_listening_t))
469 != NGX_OK)
470 {
471 return NGX_ERROR;
472 }
473
474 for (p = inherited, v = p; *p; p++) {
475 if (*p == ':' || *p == ';') {
476 s = ngx_atoi(v, p - v);
477 if (s == NGX_ERROR) {
478 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
479 "invalid socket number \"%s\" in " NGINX_VAR
480 " environment variable, ignoring the rest"
481 " of the variable", v);
482 break;
483 }
484
485 v = p + 1;
486
487 ls = ngx_array_push(&cycle->listening);
488 if (ls == NULL) {
489 return NGX_ERROR;
490 }
491
492 ngx_memzero(ls, sizeof(ngx_listening_t));
493
494 ls->fd = (ngx_socket_t) s;
495 }
496 }
497
498 if (v != p) {
499 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
500 "invalid socket number \"%s\" in " NGINX_VAR
501 " environment variable, ignoring", v);
502 }
503
504 ngx_inherited = 1;
505
506 return ngx_set_inherited_sockets(cycle);
507}
508
509
510char **
511ngx_set_environment(ngx_cycle_t *cycle, ngx_uint_t *last)
512{
513 char **p, **env;
514 ngx_str_t *var;
515 ngx_uint_t i, n;
516 ngx_core_conf_t *ccf;
517 ngx_pool_cleanup_t *cln;
518
519 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
520
521 if (last == NULL && ccf->environment) {
522 return ccf->environment;
523 }
524
525 var = ccf->env.elts;
526
527 for (i = 0; i < ccf->env.nelts; i++) {
528 if (ngx_strcmp(var[i].data, "TZ") == 0
529 || ngx_strncmp(var[i].data, "TZ=", 3) == 0)
530 {
531 goto tz_found;
532 }
533 }
534
535 var = ngx_array_push(&ccf->env);
536 if (var == NULL) {
537 return NULL;
538 }
539
540 var->len = 2;
541 var->data = (u_char *) "TZ";
542
543 var = ccf->env.elts;
544
545tz_found:
546
547 n = 0;
548
549 for (i = 0; i < ccf->env.nelts; i++) {
550
551 if (var[i].data[var[i].len] == '=') {
552 n++;
553 continue;
554 }
555
556 for (p = ngx_os_environ; *p; p++) {
557
558 if (ngx_strncmp(*p, var[i].data, var[i].len) == 0
559 && (*p)[var[i].len] == '=')
560 {
561 n++;
562 break;
563 }
564 }
565 }
566
567 if (last) {
568 env = ngx_alloc((*last + n + 1) * sizeof(char *), cycle->log);
569 if (env == NULL) {
570 return NULL;
571 }
572
573 *last = n;
574
575 } else {
576 cln = ngx_pool_cleanup_add(cycle->pool, 0);
577 if (cln == NULL) {
578 return NULL;
579 }
580
581 env = ngx_alloc((n + 1) * sizeof(char *), cycle->log);
582 if (env == NULL) {
583 return NULL;
584 }
585
586 cln->handler = ngx_cleanup_environment;
587 cln->data = env;
588 }
589
590 n = 0;
591
592 for (i = 0; i < ccf->env.nelts; i++) {
593
594 if (var[i].data[var[i].len] == '=') {
595 env[n++] = (char *) var[i].data;
596 continue;
597 }
598
599 for (p = ngx_os_environ; *p; p++) {
600
601 if (ngx_strncmp(*p, var[i].data, var[i].len) == 0
602 && (*p)[var[i].len] == '=')
603 {
604 env[n++] = *p;
605 break;
606 }
607 }
608 }
609
610 env[n] = NULL;
611
612 if (last == NULL) {
613 ccf->environment = env;
614 environ = env;
615 }
616
617 return env;
618}
619
620
621static void
622ngx_cleanup_environment(void *data)
623{
624 char **env = data;
625
626 if (environ == env) {
627
628 /*
629 * if the environment is still used, as it happens on exit,
630 * the only option is to leak it
631 */
632
633 return;
634 }
635
636 ngx_free(env);
637}
638
639
640ngx_pid_t
641ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
642{
643 char **env, *var;
644 u_char *p;
645 ngx_uint_t i, n;
646 ngx_pid_t pid;
647 ngx_exec_ctx_t ctx;
648 ngx_core_conf_t *ccf;
649 ngx_listening_t *ls;
650
651 ngx_memzero(&ctx, sizeof(ngx_exec_ctx_t));
652
653 ctx.path = argv[0];
654 ctx.name = "new binary process";
655 ctx.argv = argv;
656
657 n = 2;
658 env = ngx_set_environment(cycle, &n);
659 if (env == NULL) {
660 return NGX_INVALID_PID;
661 }
662
663 var = ngx_alloc(sizeof(NGINX_VAR)
664 + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
665 cycle->log);
666 if (var == NULL) {
667 ngx_free(env);
668 return NGX_INVALID_PID;
669 }
670
671 p = ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR));
672
673 ls = cycle->listening.elts;
674 for (i = 0; i < cycle->listening.nelts; i++) {
675 p = ngx_sprintf(p, "%ud;", ls[i].fd);
676 }
677
678 *p = '\0';
679
680 env[n++] = var;
681
682#if (NGX_SETPROCTITLE_USES_ENV)
683
684 /* allocate the spare 300 bytes for the new binary process title */
685
686 env[n++] = "SPARE=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
687 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
688 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
689 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
690 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
691
692#endif
693
694 env[n] = NULL;
695
696#if (NGX_DEBUG)
697 {
698 char **e;
699 for (e = env; *e; e++) {
700 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "env: %s", *e);
701 }
702 }
703#endif
704
705 ctx.envp = (char *const *) env;
706
707 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
708
709 if (ngx_rename_file(ccf->pid.data, ccf->oldpid.data) == NGX_FILE_ERROR) {
710 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
711 ngx_rename_file_n " %s to %s failed "
712 "before executing new binary process \"%s\"",
713 ccf->pid.data, ccf->oldpid.data, argv[0]);
714
715 ngx_free(env);
716 ngx_free(var);
717
718 return NGX_INVALID_PID;
719 }
720
721 pid = ngx_execute(cycle, &ctx);
722
723 if (pid == NGX_INVALID_PID) {
724 if (ngx_rename_file(ccf->oldpid.data, ccf->pid.data)
725 == NGX_FILE_ERROR)
726 {
727 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
728 ngx_rename_file_n " %s back to %s failed after "
729 "an attempt to execute new binary process \"%s\"",
730 ccf->oldpid.data, ccf->pid.data, argv[0]);
731 }
732 }
733
734 ngx_free(env);
735 ngx_free(var);
736
737 return pid;
738}
739
740
741static ngx_int_t
742ngx_get_options(int argc, char *const *argv)
743{
744 u_char *p;
745 ngx_int_t i;
746
747 for (i = 1; i < argc; i++) {
748
749 p = (u_char *) argv[i];
750
751 if (*p++ != '-') {
752 ngx_log_stderr(0, "invalid option: \"%s\"", argv[i]);
753 return NGX_ERROR;
754 }
755
756 while (*p) {
757
758 switch (*p++) {
759
760 case '?':
761 case 'h':
762 ngx_show_version = 1;
763 ngx_show_help = 1;
764 break;
765
766 case 'v':
767 ngx_show_version = 1;
768 break;
769
770 case 'V':
771 ngx_show_version = 1;
772 ngx_show_configure = 1;
773 break;
774
775 case 't':
776 ngx_test_config = 1;
777 break;
778
779 case 'T':
780 ngx_test_config = 1;
781 ngx_dump_config = 1;
782 break;
783
784 case 'q':
785 ngx_quiet_mode = 1;
786 break;
787
788 case 'p':
789 if (*p) {
790 ngx_prefix = p;
791 goto next;
792 }
793
794 if (argv[++i]) {
795 ngx_prefix = (u_char *) argv[i];
796 goto next;
797 }
798
799 ngx_log_stderr(0, "option \"-p\" requires directory name");
800 return NGX_ERROR;
801
802 case 'c':
803 if (*p) {
804 ngx_conf_file = p;
805 goto next;
806 }
807
808 if (argv[++i]) {
809 ngx_conf_file = (u_char *) argv[i];
810 goto next;
811 }
812
813 ngx_log_stderr(0, "option \"-c\" requires file name");
814 return NGX_ERROR;
815
816 case 'g':
817 if (*p) {
818 ngx_conf_params = p;
819 goto next;
820 }
821
822 if (argv[++i]) {
823 ngx_conf_params = (u_char *) argv[i];
824 goto next;
825 }
826
827 ngx_log_stderr(0, "option \"-g\" requires parameter");
828 return NGX_ERROR;
829
830 case 's':
831 if (*p) {
832 ngx_signal = (char *) p;
833
834 } else if (argv[++i]) {
835 ngx_signal = argv[i];
836
837 } else {
838 ngx_log_stderr(0, "option \"-s\" requires parameter");
839 return NGX_ERROR;
840 }
841
842 if (ngx_strcmp(ngx_signal, "stop") == 0
843 || ngx_strcmp(ngx_signal, "quit") == 0
844 || ngx_strcmp(ngx_signal, "reopen") == 0
845 || ngx_strcmp(ngx_signal, "reload") == 0)
846 {
847 ngx_process = NGX_PROCESS_SIGNALLER;
848 goto next;
849 }
850
851 ngx_log_stderr(0, "invalid option: \"-s %s\"", ngx_signal);
852 return NGX_ERROR;
853
854 default:
855 ngx_log_stderr(0, "invalid option: \"%c\"", *(p - 1));
856 return NGX_ERROR;
857 }
858 }
859
860 next:
861
862 continue;
863 }
864
865 return NGX_OK;
866}
867
868
869static ngx_int_t
870ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv)
871{
872#if (NGX_FREEBSD)
873
874 ngx_os_argv = (char **) argv;
875 ngx_argc = argc;
876 ngx_argv = (char **) argv;
877
878#else
879 size_t len;
880 ngx_int_t i;
881
882 ngx_os_argv = (char **) argv;
883 ngx_argc = argc;
884
885 ngx_argv = ngx_alloc((argc + 1) * sizeof(char *), cycle->log);
886 if (ngx_argv == NULL) {
887 return NGX_ERROR;
888 }
889
890 for (i = 0; i < argc; i++) {
891 len = ngx_strlen(argv[i]) + 1;
892
893 ngx_argv[i] = ngx_alloc(len, cycle->log);
894 if (ngx_argv[i] == NULL) {
895 return NGX_ERROR;
896 }
897
898 (void) ngx_cpystrn((u_char *) ngx_argv[i], (u_char *) argv[i], len);
899 }
900
901 ngx_argv[i] = NULL;
902
903#endif
904
905 ngx_os_environ = environ;
906
907 return NGX_OK;
908}
909
910
911static ngx_int_t
912ngx_process_options(ngx_cycle_t *cycle)
913{
914 u_char *p;
915 size_t len;
916
917 if (ngx_prefix) {
918 len = ngx_strlen(ngx_prefix);
919 p = ngx_prefix;
920
921 if (len && !ngx_path_separator(p[len - 1])) {
922 p = ngx_pnalloc(cycle->pool, len + 1);
923 if (p == NULL) {
924 return NGX_ERROR;
925 }
926
927 ngx_memcpy(p, ngx_prefix, len);
928 p[len++] = '/';
929 }
930
931 cycle->conf_prefix.len = len;
932 cycle->conf_prefix.data = p;
933 cycle->prefix.len = len;
934 cycle->prefix.data = p;
935
936 } else {
937
938#ifndef NGX_PREFIX
939
940 p = ngx_pnalloc(cycle->pool, NGX_MAX_PATH);
941 if (p == NULL) {
942 return NGX_ERROR;
943 }
944
945 if (ngx_getcwd(p, NGX_MAX_PATH) == 0) {
946 ngx_log_stderr(ngx_errno, "[emerg]: " ngx_getcwd_n " failed");
947 return NGX_ERROR;
948 }
949
950 len = ngx_strlen(p);
951
952 p[len++] = '/';
953
954 cycle->conf_prefix.len = len;
955 cycle->conf_prefix.data = p;
956 cycle->prefix.len = len;
957 cycle->prefix.data = p;
958
959#else
960
961#ifdef NGX_CONF_PREFIX
962 ngx_str_set(&cycle->conf_prefix, NGX_CONF_PREFIX);
963#else
964 ngx_str_set(&cycle->conf_prefix, NGX_PREFIX);
965#endif
966 ngx_str_set(&cycle->prefix, NGX_PREFIX);
967
968#endif
969 }
970
971 if (ngx_conf_file) {
972 cycle->conf_file.len = ngx_strlen(ngx_conf_file);
973 cycle->conf_file.data = ngx_conf_file;
974
975 } else {
976 ngx_str_set(&cycle->conf_file, NGX_CONF_PATH);
977 }
978
979 if (ngx_conf_full_name(cycle, &cycle->conf_file, 0) != NGX_OK) {
980 return NGX_ERROR;
981 }
982
983 for (p = cycle->conf_file.data + cycle->conf_file.len - 1;
984 p > cycle->conf_file.data;
985 p--)
986 {
987 if (ngx_path_separator(*p)) {
988 cycle->conf_prefix.len = p - cycle->conf_file.data + 1;
989 cycle->conf_prefix.data = cycle->conf_file.data;
990 break;
991 }
992 }
993
994 if (ngx_conf_params) {
995 cycle->conf_param.len = ngx_strlen(ngx_conf_params);
996 cycle->conf_param.data = ngx_conf_params;
997 }
998
999 if (ngx_test_config) {
1000 cycle->log->log_level = NGX_LOG_INFO;
1001 }
1002
1003 return NGX_OK;
1004}
1005
1006
1007static void *
1008ngx_core_module_create_conf(ngx_cycle_t *cycle)
1009{
1010 ngx_core_conf_t *ccf;
1011
1012 ccf = ngx_pcalloc(cycle->pool, sizeof(ngx_core_conf_t));
1013 if (ccf == NULL) {
1014 return NULL;
1015 }
1016
1017 /*
1018 * set by ngx_pcalloc()
1019 *
1020 * ccf->pid = NULL;
1021 * ccf->oldpid = NULL;
1022 * ccf->priority = 0;
1023 * ccf->cpu_affinity_auto = 0;
1024 * ccf->cpu_affinity_n = 0;
1025 * ccf->cpu_affinity = NULL;
1026 */
1027
1028 ccf->daemon = NGX_CONF_UNSET;
1029 ccf->master = NGX_CONF_UNSET;
1030 ccf->timer_resolution = NGX_CONF_UNSET_MSEC;
1031 ccf->shutdown_timeout = NGX_CONF_UNSET_MSEC;
1032
1033 ccf->worker_processes = NGX_CONF_UNSET;
1034 ccf->debug_points = NGX_CONF_UNSET;
1035
1036 ccf->rlimit_nofile = NGX_CONF_UNSET;
1037 ccf->rlimit_core = NGX_CONF_UNSET;
1038
1039 ccf->user = (ngx_uid_t) NGX_CONF_UNSET_UINT;
1040 ccf->group = (ngx_gid_t) NGX_CONF_UNSET_UINT;
1041
1042 if (ngx_array_init(&ccf->env, cycle->pool, 1, sizeof(ngx_str_t))
1043 != NGX_OK)
1044 {
1045 return NULL;
1046 }
1047
1048 return ccf;
1049}
1050
1051
1052static char *
1053ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
1054{
1055 ngx_core_conf_t *ccf = conf;
1056
1057 ngx_conf_init_value(ccf->daemon, 1);
1058 ngx_conf_init_value(ccf->master, 1);
1059 ngx_conf_init_msec_value(ccf->timer_resolution, 0);
1060 ngx_conf_init_msec_value(ccf->shutdown_timeout, 0);
1061
1062 ngx_conf_init_value(ccf->worker_processes, 1);
1063 ngx_conf_init_value(ccf->debug_points, 0);
1064
1065#if (NGX_HAVE_CPU_AFFINITY)
1066
1067 if (!ccf->cpu_affinity_auto
1068 && ccf->cpu_affinity_n
1069 && ccf->cpu_affinity_n != 1
1070 && ccf->cpu_affinity_n != (ngx_uint_t) ccf->worker_processes)
1071 {
1072 ngx_log_error(NGX_LOG_WARN, cycle->log, 0,
1073 "the number of \"worker_processes\" is not equal to "
1074 "the number of \"worker_cpu_affinity\" masks, "
1075 "using last mask for remaining worker processes");
1076 }
1077
1078#endif
1079
1080
1081 if (ccf->pid.len == 0) {
1082 ngx_str_set(&ccf->pid, NGX_PID_PATH);
1083 }
1084
1085 if (ngx_conf_full_name(cycle, &ccf->pid, 0) != NGX_OK) {
1086 return NGX_CONF_ERROR;
1087 }
1088
1089 ccf->oldpid.len = ccf->pid.len + sizeof(NGX_OLDPID_EXT);
1090
1091 ccf->oldpid.data = ngx_pnalloc(cycle->pool, ccf->oldpid.len);
1092 if (ccf->oldpid.data == NULL) {
1093 return NGX_CONF_ERROR;
1094 }
1095
1096 ngx_memcpy(ngx_cpymem(ccf->oldpid.data, ccf->pid.data, ccf->pid.len),
1097 NGX_OLDPID_EXT, sizeof(NGX_OLDPID_EXT));
1098
1099
1100#if !(NGX_WIN32)
1101
1102 if (ccf->user == (uid_t) NGX_CONF_UNSET_UINT && geteuid() == 0) {
1103 struct group *grp;
1104 struct passwd *pwd;
1105
1106 ngx_set_errno(0);
1107 pwd = getpwnam(NGX_USER);
1108 if (pwd == NULL) {
1109 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
1110 "getpwnam(\"" NGX_USER "\") failed");
1111 return NGX_CONF_ERROR;
1112 }
1113
1114 ccf->username = NGX_USER;
1115 ccf->user = pwd->pw_uid;
1116
1117 ngx_set_errno(0);
1118 grp = getgrnam(NGX_GROUP);
1119 if (grp == NULL) {
1120 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
1121 "getgrnam(\"" NGX_GROUP "\") failed");
1122 return NGX_CONF_ERROR;
1123 }
1124
1125 ccf->group = grp->gr_gid;
1126 }
1127
1128
1129 if (ccf->lock_file.len == 0) {
1130 ngx_str_set(&ccf->lock_file, NGX_LOCK_PATH);
1131 }
1132
1133 if (ngx_conf_full_name(cycle, &ccf->lock_file, 0) != NGX_OK) {
1134 return NGX_CONF_ERROR;
1135 }
1136
1137 {
1138 ngx_str_t lock_file;
1139
1140 lock_file = cycle->old_cycle->lock_file;
1141
1142 if (lock_file.len) {
1143 lock_file.len--;
1144
1145 if (ccf->lock_file.len != lock_file.len
1146 || ngx_strncmp(ccf->lock_file.data, lock_file.data, lock_file.len)
1147 != 0)
1148 {
1149 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
1150 "\"lock_file\" could not be changed, ignored");
1151 }
1152
1153 cycle->lock_file.len = lock_file.len + 1;
1154 lock_file.len += sizeof(".accept");
1155
1156 cycle->lock_file.data = ngx_pstrdup(cycle->pool, &lock_file);
1157 if (cycle->lock_file.data == NULL) {
1158 return NGX_CONF_ERROR;
1159 }
1160
1161 } else {
1162 cycle->lock_file.len = ccf->lock_file.len + 1;
1163 cycle->lock_file.data = ngx_pnalloc(cycle->pool,
1164 ccf->lock_file.len + sizeof(".accept"));
1165 if (cycle->lock_file.data == NULL) {
1166 return NGX_CONF_ERROR;
1167 }
1168
1169 ngx_memcpy(ngx_cpymem(cycle->lock_file.data, ccf->lock_file.data,
1170 ccf->lock_file.len),
1171 ".accept", sizeof(".accept"));
1172 }
1173 }
1174
1175#endif
1176
1177 return NGX_CONF_OK;
1178}
1179
1180
1181static char *
1182ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1183{
1184#if (NGX_WIN32)
1185
1186 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
1187 "\"user\" is not supported, ignored");
1188
1189 return NGX_CONF_OK;
1190
1191#else
1192
1193 ngx_core_conf_t *ccf = conf;
1194
1195 char *group;
1196 struct passwd *pwd;
1197 struct group *grp;
1198 ngx_str_t *value;
1199
1200 if (ccf->user != (uid_t) NGX_CONF_UNSET_UINT) {
1201 return "is duplicate";
1202 }
1203
1204 if (geteuid() != 0) {
1205 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
1206 "the \"user\" directive makes sense only "
1207 "if the master process runs "
1208 "with super-user privileges, ignored");
1209 return NGX_CONF_OK;
1210 }
1211
1212 value = cf->args->elts;
1213
1214 ccf->username = (char *) value[1].data;
1215
1216 ngx_set_errno(0);
1217 pwd = getpwnam((const char *) value[1].data);
1218 if (pwd == NULL) {
1219 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
1220 "getpwnam(\"%s\") failed", value[1].data);
1221 return NGX_CONF_ERROR;
1222 }
1223
1224 ccf->user = pwd->pw_uid;
1225
1226 group = (char *) ((cf->args->nelts == 2) ? value[1].data : value[2].data);
1227
1228 ngx_set_errno(0);
1229 grp = getgrnam(group);
1230 if (grp == NULL) {
1231 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
1232 "getgrnam(\"%s\") failed", group);
1233 return NGX_CONF_ERROR;
1234 }
1235
1236 ccf->group = grp->gr_gid;
1237
1238 return NGX_CONF_OK;
1239
1240#endif
1241}
1242
1243
1244static char *
1245ngx_set_env(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1246{
1247 ngx_core_conf_t *ccf = conf;
1248
1249 ngx_str_t *value, *var;
1250 ngx_uint_t i;
1251
1252 var = ngx_array_push(&ccf->env);
1253 if (var == NULL) {
1254 return NGX_CONF_ERROR;
1255 }
1256
1257 value = cf->args->elts;
1258 *var = value[1];
1259
1260 for (i = 0; i < value[1].len; i++) {
1261
1262 if (value[1].data[i] == '=') {
1263
1264 var->len = i;
1265
1266 return NGX_CONF_OK;
1267 }
1268 }
1269
1270 return NGX_CONF_OK;
1271}
1272
1273
1274static char *
1275ngx_set_priority(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1276{
1277 ngx_core_conf_t *ccf = conf;
1278
1279 ngx_str_t *value;
1280 ngx_uint_t n, minus;
1281
1282 if (ccf->priority != 0) {
1283 return "is duplicate";
1284 }
1285
1286 value = cf->args->elts;
1287
1288 if (value[1].data[0] == '-') {
1289 n = 1;
1290 minus = 1;
1291
1292 } else if (value[1].data[0] == '+') {
1293 n = 1;
1294 minus = 0;
1295
1296 } else {
1297 n = 0;
1298 minus = 0;
1299 }
1300
1301 ccf->priority = ngx_atoi(&value[1].data[n], value[1].len - n);
1302 if (ccf->priority == NGX_ERROR) {
1303 return "invalid number";
1304 }
1305
1306 if (minus) {
1307 ccf->priority = -ccf->priority;
1308 }
1309
1310 return NGX_CONF_OK;
1311}
1312
1313
1314static char *
1315ngx_set_cpu_affinity(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1316{
1317#if (NGX_HAVE_CPU_AFFINITY)
1318 ngx_core_conf_t *ccf = conf;
1319
1320 u_char ch, *p;
1321 ngx_str_t *value;
1322 ngx_uint_t i, n;
1323 ngx_cpuset_t *mask;
1324
1325 if (ccf->cpu_affinity) {
1326 return "is duplicate";
1327 }
1328
1329 mask = ngx_palloc(cf->pool, (cf->args->nelts - 1) * sizeof(ngx_cpuset_t));
1330 if (mask == NULL) {
1331 return NGX_CONF_ERROR;
1332 }
1333
1334 ccf->cpu_affinity_n = cf->args->nelts - 1;
1335 ccf->cpu_affinity = mask;
1336
1337 value = cf->args->elts;
1338
1339 if (ngx_strcmp(value[1].data, "auto") == 0) {
1340
1341 if (cf->args->nelts > 3) {
1342 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1343 "invalid number of arguments in "
1344 "\"worker_cpu_affinity\" directive");
1345 return NGX_CONF_ERROR;
1346 }
1347
1348 ccf->cpu_affinity_auto = 1;
1349
1350 CPU_ZERO(&mask[0]);
1351 for (i = 0; i < (ngx_uint_t) ngx_min(ngx_ncpu, CPU_SETSIZE); i++) {
1352 CPU_SET(i, &mask[0]);
1353 }
1354
1355 n = 2;
1356
1357 } else {
1358 n = 1;
1359 }
1360
1361 for ( /* void */ ; n < cf->args->nelts; n++) {
1362
1363 if (value[n].len > CPU_SETSIZE) {
1364 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1365 "\"worker_cpu_affinity\" supports up to %d CPUs only",
1366 CPU_SETSIZE);
1367 return NGX_CONF_ERROR;
1368 }
1369
1370 i = 0;
1371 CPU_ZERO(&mask[n - 1]);
1372
1373 for (p = value[n].data + value[n].len - 1;
1374 p >= value[n].data;
1375 p--)
1376 {
1377 ch = *p;
1378
1379 if (ch == ' ') {
1380 continue;
1381 }
1382
1383 i++;
1384
1385 if (ch == '0') {
1386 continue;
1387 }
1388
1389 if (ch == '1') {
1390 CPU_SET(i - 1, &mask[n - 1]);
1391 continue;
1392 }
1393
1394 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1395 "invalid character \"%c\" in \"worker_cpu_affinity\"",
1396 ch);
1397 return NGX_CONF_ERROR;
1398 }
1399 }
1400
1401#else
1402
1403 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
1404 "\"worker_cpu_affinity\" is not supported "
1405 "on this platform, ignored");
1406#endif
1407
1408 return NGX_CONF_OK;
1409}
1410
1411
1412ngx_cpuset_t *
1413ngx_get_cpu_affinity(ngx_uint_t n)
1414{
1415#if (NGX_HAVE_CPU_AFFINITY)
1416 ngx_uint_t i, j;
1417 ngx_cpuset_t *mask;
1418 ngx_core_conf_t *ccf;
1419
1420 static ngx_cpuset_t result;
1421
1422 ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx,
1423 ngx_core_module);
1424
1425 if (ccf->cpu_affinity == NULL) {
1426 return NULL;
1427 }
1428
1429 if (ccf->cpu_affinity_auto) {
1430 mask = &ccf->cpu_affinity[ccf->cpu_affinity_n - 1];
1431
1432 for (i = 0, j = n; /* void */ ; i++) {
1433
1434 if (CPU_ISSET(i % CPU_SETSIZE, mask) && j-- == 0) {
1435 break;
1436 }
1437
1438 if (i == CPU_SETSIZE && j == n) {
1439 /* empty mask */
1440 return NULL;
1441 }
1442
1443 /* void */
1444 }
1445
1446 CPU_ZERO(&result);
1447 CPU_SET(i % CPU_SETSIZE, &result);
1448
1449 return &result;
1450 }
1451
1452 if (ccf->cpu_affinity_n > n) {
1453 return &ccf->cpu_affinity[n];
1454 }
1455
1456 return &ccf->cpu_affinity[ccf->cpu_affinity_n - 1];
1457
1458#else
1459
1460 return NULL;
1461
1462#endif
1463}
1464
1465
1466static char *
1467ngx_set_worker_processes(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1468{
1469 ngx_str_t *value;
1470 ngx_core_conf_t *ccf;
1471
1472 ccf = (ngx_core_conf_t *) conf;
1473
1474 if (ccf->worker_processes != NGX_CONF_UNSET) {
1475 return "is duplicate";
1476 }
1477
1478 value = cf->args->elts;
1479
1480 if (ngx_strcmp(value[1].data, "auto") == 0) {
1481 ccf->worker_processes = ngx_ncpu;
1482 return NGX_CONF_OK;
1483 }
1484
1485 ccf->worker_processes = ngx_atoi(value[1].data, value[1].len);
1486
1487 if (ccf->worker_processes == NGX_ERROR) {
1488 return "invalid value";
1489 }
1490
1491 return NGX_CONF_OK;
1492}
1493
1494
1495static char *
1496ngx_load_module(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1497{
1498#if (NGX_HAVE_DLOPEN)
1499 void *handle;
1500 char **names, **order;
1501 ngx_str_t *value, file;
1502 ngx_uint_t i;
1503 ngx_module_t *module, **modules;
1504 ngx_pool_cleanup_t *cln;
1505
1506 if (cf->cycle->modules_used) {
1507 return "is specified too late";
1508 }
1509
1510 value = cf->args->elts;
1511
1512 file = value[1];
1513
1514 if (ngx_conf_full_name(cf->cycle, &file, 0) != NGX_OK) {
1515 return NGX_CONF_ERROR;
1516 }
1517
1518 cln = ngx_pool_cleanup_add(cf->cycle->pool, 0);
1519 if (cln == NULL) {
1520 return NGX_CONF_ERROR;
1521 }
1522
1523 handle = ngx_dlopen(file.data);
1524 if (handle == NULL) {
1525 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1526 ngx_dlopen_n " \"%s\" failed (%s)",
1527 file.data, ngx_dlerror());
1528 return NGX_CONF_ERROR;
1529 }
1530
1531 cln->handler = ngx_unload_module;
1532 cln->data = handle;
1533
1534 modules = ngx_dlsym(handle, "ngx_modules");
1535 if (modules == NULL) {
1536 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1537 ngx_dlsym_n " \"%V\", \"%s\" failed (%s)",
1538 &value[1], "ngx_modules", ngx_dlerror());
1539 return NGX_CONF_ERROR;
1540 }
1541
1542 names = ngx_dlsym(handle, "ngx_module_names");
1543 if (names == NULL) {
1544 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1545 ngx_dlsym_n " \"%V\", \"%s\" failed (%s)",
1546 &value[1], "ngx_module_names", ngx_dlerror());
1547 return NGX_CONF_ERROR;
1548 }
1549
1550 order = ngx_dlsym(handle, "ngx_module_order");
1551
1552 for (i = 0; modules[i]; i++) {
1553 module = modules[i];
1554 module->name = names[i];
1555
1556 if (ngx_add_module(cf, &file, module, order) != NGX_OK) {
1557 return NGX_CONF_ERROR;
1558 }
1559
1560 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cf->log, 0, "module: %s i:%ui",
1561 module->name, module->index);
1562 }
1563
1564 return NGX_CONF_OK;
1565
1566#else
1567
1568 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1569 "\"load_module\" is not supported "
1570 "on this platform");
1571 return NGX_CONF_ERROR;
1572
1573#endif
1574}
1575
1576
1577#if (NGX_HAVE_DLOPEN)
1578
1579static void
1580ngx_unload_module(void *data)
1581{
1582 void *handle = data;
1583
1584 if (ngx_dlclose(handle) != 0) {
1585 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
1586 ngx_dlclose_n " failed (%s)", ngx_dlerror());
1587 }
1588}
1589
1590#endif
Note: See TracBrowser for help on using the repository browser.