comparison src/core/nginx.c @ 6257:5eb4d7541107

Extract out version info function. The code for displaying version info and configuration info seemed to be cluttering up the main function. I was finding it hard to read main. This extracts out all of the logic for displaying version and configuration info into its own function, thus making main easier to read.
author Kurtis Nusbaum <klnusbaum@gmail.com>
date Sun, 12 Jul 2015 08:31:38 -0700
parents 1b7e246e6b38
children 7ac57369036c
comparison
equal deleted inserted replaced
6256:9dfc4ba140f9 6257:5eb4d7541107
8 #include <ngx_config.h> 8 #include <ngx_config.h>
9 #include <ngx_core.h> 9 #include <ngx_core.h>
10 #include <nginx.h> 10 #include <nginx.h>
11 11
12 12
13 static void ngx_show_version_info();
13 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle); 14 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle);
14 static ngx_int_t ngx_get_options(int argc, char *const *argv); 15 static ngx_int_t ngx_get_options(int argc, char *const *argv);
15 static ngx_int_t ngx_process_options(ngx_cycle_t *cycle); 16 static ngx_int_t ngx_process_options(ngx_cycle_t *cycle);
16 static ngx_int_t ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv); 17 static ngx_int_t ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv);
17 static void *ngx_core_module_create_conf(ngx_cycle_t *cycle); 18 static void *ngx_core_module_create_conf(ngx_cycle_t *cycle);
192 if (ngx_get_options(argc, argv) != NGX_OK) { 193 if (ngx_get_options(argc, argv) != NGX_OK) {
193 return 1; 194 return 1;
194 } 195 }
195 196
196 if (ngx_show_version) { 197 if (ngx_show_version) {
197 ngx_write_stderr("nginx version: " NGINX_VER_BUILD NGX_LINEFEED); 198 ngx_show_version_info();
198
199 if (ngx_show_help) {
200 ngx_write_stderr(
201 "Usage: nginx [-?hvVtTq] [-s signal] [-c filename] "
202 "[-p prefix] [-g directives]" NGX_LINEFEED
203 NGX_LINEFEED
204 "Options:" NGX_LINEFEED
205 " -?,-h : this help" NGX_LINEFEED
206 " -v : show version and exit" NGX_LINEFEED
207 " -V : show version and configure options then exit"
208 NGX_LINEFEED
209 " -t : test configuration and exit" NGX_LINEFEED
210 " -T : test configuration, dump it and exit"
211 NGX_LINEFEED
212 " -q : suppress non-error messages "
213 "during configuration testing" NGX_LINEFEED
214 " -s signal : send signal to a master process: "
215 "stop, quit, reopen, reload" NGX_LINEFEED
216 #ifdef NGX_PREFIX
217 " -p prefix : set prefix path (default: "
218 NGX_PREFIX ")" NGX_LINEFEED
219 #else
220 " -p prefix : set prefix path (default: NONE)" NGX_LINEFEED
221 #endif
222 " -c filename : set configuration file (default: "
223 NGX_CONF_PATH ")" NGX_LINEFEED
224 " -g directives : set global directives out of configuration "
225 "file" NGX_LINEFEED NGX_LINEFEED
226 );
227 }
228
229 if (ngx_show_configure) {
230
231 #ifdef NGX_COMPILER
232 ngx_write_stderr("built by " NGX_COMPILER NGX_LINEFEED);
233 #endif
234
235 #if (NGX_SSL)
236 if (SSLeay() == SSLEAY_VERSION_NUMBER) {
237 ngx_write_stderr("built with " OPENSSL_VERSION_TEXT
238 NGX_LINEFEED);
239 } else {
240 ngx_write_stderr("built with " OPENSSL_VERSION_TEXT
241 " (running with ");
242 ngx_write_stderr((char *) (uintptr_t)
243 SSLeay_version(SSLEAY_VERSION));
244 ngx_write_stderr(")" NGX_LINEFEED);
245 }
246 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
247 ngx_write_stderr("TLS SNI support enabled" NGX_LINEFEED);
248 #else
249 ngx_write_stderr("TLS SNI support disabled" NGX_LINEFEED);
250 #endif
251 #endif
252
253 ngx_write_stderr("configure arguments:" NGX_CONFIGURE NGX_LINEFEED);
254 }
255 199
256 if (!ngx_test_config) { 200 if (!ngx_test_config) {
257 return 0; 201 return 0;
258 } 202 }
259 } 203 }
414 } else { 358 } else {
415 ngx_master_process_cycle(cycle); 359 ngx_master_process_cycle(cycle);
416 } 360 }
417 361
418 return 0; 362 return 0;
363 }
364
365
366 static void
367 ngx_show_version_info()
368 {
369 ngx_write_stderr("nginx version: " NGINX_VER_BUILD NGX_LINEFEED);
370
371 if (ngx_show_help) {
372 ngx_write_stderr(
373 "Usage: nginx [-?hvVtTq] [-s signal] [-c filename] "
374 "[-p prefix] [-g directives]" NGX_LINEFEED
375 NGX_LINEFEED
376 "Options:" NGX_LINEFEED
377 " -?,-h : this help" NGX_LINEFEED
378 " -v : show version and exit" NGX_LINEFEED
379 " -V : show version and configure options then exit"
380 NGX_LINEFEED
381 " -t : test configuration and exit" NGX_LINEFEED
382 " -T : test configuration, dump it and exit"
383 NGX_LINEFEED
384 " -q : suppress non-error messages "
385 "during configuration testing" NGX_LINEFEED
386 " -s signal : send signal to a master process: "
387 "stop, quit, reopen, reload" NGX_LINEFEED
388 #ifdef NGX_PREFIX
389 " -p prefix : set prefix path (default: " NGX_PREFIX ")"
390 NGX_LINEFEED
391 #else
392 " -p prefix : set prefix path (default: NONE)" NGX_LINEFEED
393 #endif
394 " -c filename : set configuration file (default: " NGX_CONF_PATH
395 ")" NGX_LINEFEED
396 " -g directives : set global directives out of configuration "
397 "file" NGX_LINEFEED NGX_LINEFEED
398 );
399 }
400
401 if (ngx_show_configure) {
402
403 #ifdef NGX_COMPILER
404 ngx_write_stderr("built by " NGX_COMPILER NGX_LINEFEED);
405 #endif
406
407 #if (NGX_SSL)
408 if (SSLeay() == SSLEAY_VERSION_NUMBER) {
409 ngx_write_stderr("built with " OPENSSL_VERSION_TEXT NGX_LINEFEED);
410 } else {
411 ngx_write_stderr("built with " OPENSSL_VERSION_TEXT
412 " (running with ");
413 ngx_write_stderr((char *) (uintptr_t)
414 SSLeay_version(SSLEAY_VERSION));
415 ngx_write_stderr(")" NGX_LINEFEED);
416 }
417 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
418 ngx_write_stderr("TLS SNI support enabled" NGX_LINEFEED);
419 #else
420 ngx_write_stderr("TLS SNI support disabled" NGX_LINEFEED);
421 #endif
422 #endif
423
424 ngx_write_stderr("configure arguments:" NGX_CONFIGURE NGX_LINEFEED);
425 }
419 } 426 }
420 427
421 428
422 static ngx_int_t 429 static ngx_int_t
423 ngx_add_inherited_sockets(ngx_cycle_t *cycle) 430 ngx_add_inherited_sockets(ngx_cycle_t *cycle)