Welcome! Log In Create A New Profile

Advanced

[PATCH] Extract out version info function

Kurtis Nusbaum
September 27, 2015 12:18AM
# HG changeset patch
# User Kurtis Nusbaum <klnusbaum@gmail.com>
# Date 1436715098 25200
# Sun Jul 12 08:31:38 2015 -0700
# Node ID 1d5846fa79e64a0920c189a266849bf23b6cab63
# Parent b40af2fd1c1665bc79bd6c50233dd6c834f60b6b
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.

diff -r b40af2fd1c16 -r 1d5846fa79e6 src/core/nginx.c
--- a/src/core/nginx.c Thu Sep 24 17:19:08 2015 +0300
+++ b/src/core/nginx.c Sun Jul 12 08:31:38 2015 -0700
@@ -10,6 +10,7 @@
#include <nginx.h>


+static void ngx_show_version_info();
static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle);
static ngx_int_t ngx_get_options(int argc, char *const *argv);
static ngx_int_t ngx_process_options(ngx_cycle_t *cycle);
@@ -194,65 +195,7 @@
}

if (ngx_show_version) {
- ngx_write_stderr("nginx version: " NGINX_VER_BUILD NGX_LINEFEED);
-
- if (ngx_show_help) {
- ngx_write_stderr(
- "Usage: nginx [-?hvVtTq] [-s signal] [-c filename] "
- "[-p prefix] [-g directives]" NGX_LINEFEED
- NGX_LINEFEED
- "Options:" NGX_LINEFEED
- " -?,-h : this help" NGX_LINEFEED
- " -v : show version and exit" NGX_LINEFEED
- " -V : show version and configure options then exit"
- NGX_LINEFEED
- " -t : test configuration and exit" NGX_LINEFEED
- " -T : test configuration, dump it and exit"
- NGX_LINEFEED
- " -q : suppress non-error messages "
- "during configuration testing" NGX_LINEFEED
- " -s signal : send signal to a master process: "
- "stop, quit, reopen, reload" NGX_LINEFEED
-#ifdef NGX_PREFIX
- " -p prefix : set prefix path (default: "
- NGX_PREFIX ")" NGX_LINEFEED
-#else
- " -p prefix : set prefix path (default: NONE)" NGX_LINEFEED
-#endif
- " -c filename : set configuration file (default: "
- NGX_CONF_PATH ")" NGX_LINEFEED
- " -g directives : set global directives out of configuration "
- "file" NGX_LINEFEED NGX_LINEFEED
- );
- }
-
- if (ngx_show_configure) {
-
-#ifdef NGX_COMPILER
- ngx_write_stderr("built by " NGX_COMPILER NGX_LINEFEED);
-#endif
-
-#if (NGX_SSL)
- if (SSLeay() == SSLEAY_VERSION_NUMBER) {
- ngx_write_stderr("built with " OPENSSL_VERSION_TEXT
- NGX_LINEFEED);
- } else {
- ngx_write_stderr("built with " OPENSSL_VERSION_TEXT
- " (running with ");
- ngx_write_stderr((char *) (uintptr_t)
- SSLeay_version(SSLEAY_VERSION));
- ngx_write_stderr(")" NGX_LINEFEED);
- }
-#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
- ngx_write_stderr("TLS SNI support enabled" NGX_LINEFEED);
-#else
- ngx_write_stderr("TLS SNI support disabled" NGX_LINEFEED);
-#endif
-#endif
-
- ngx_write_stderr("configure arguments:" NGX_CONFIGURE NGX_LINEFEED);
- }
-
+ ngx_show_version_info();
if (!ngx_test_config) {
return 0;
}
@@ -419,6 +362,69 @@
}


+static void
+ngx_show_version_info()
+{
+ ngx_write_stderr("nginx version: " NGINX_VER_BUILD NGX_LINEFEED);
+
+ if (ngx_show_help) {
+ ngx_write_stderr(
+ "Usage: nginx [-?hvVtTq] [-s signal] [-c filename] "
+ "[-p prefix] [-g directives]" NGX_LINEFEED
+ NGX_LINEFEED
+ "Options:" NGX_LINEFEED
+ " -?,-h : this help" NGX_LINEFEED
+ " -v : show version and exit" NGX_LINEFEED
+ " -V : show version and configure options then exit"
+ NGX_LINEFEED
+ " -t : test configuration and exit" NGX_LINEFEED
+ " -T : test configuration, dump it and exit"
+ NGX_LINEFEED
+ " -q : suppress non-error messages "
+ "during configuration testing" NGX_LINEFEED
+ " -s signal : send signal to a master process: "
+ "stop, quit, reopen, reload" NGX_LINEFEED
+#ifdef NGX_PREFIX
+ " -p prefix : set prefix path (default: " NGX_PREFIX ")"
+ NGX_LINEFEED
+#else
+ " -p prefix : set prefix path (default: NONE)" NGX_LINEFEED
+#endif
+ " -c filename : set configuration file (default: " NGX_CONF_PATH
+ ")" NGX_LINEFEED
+ " -g directives : set global directives out of configuration "
+ "file" NGX_LINEFEED NGX_LINEFEED
+ );
+ }
+
+ if (ngx_show_configure) {
+
+#ifdef NGX_COMPILER
+ ngx_write_stderr("built by " NGX_COMPILER NGX_LINEFEED);
+#endif
+
+#if (NGX_SSL)
+ if (SSLeay() == SSLEAY_VERSION_NUMBER) {
+ ngx_write_stderr("built with " OPENSSL_VERSION_TEXT NGX_LINEFEED);
+ } else {
+ ngx_write_stderr("built with " OPENSSL_VERSION_TEXT
+ " (running with ");
+ ngx_write_stderr((char *) (uintptr_t)
+ SSLeay_version(SSLEAY_VERSION));
+ ngx_write_stderr(")" NGX_LINEFEED);
+ }
+#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
+ ngx_write_stderr("TLS SNI support enabled" NGX_LINEFEED);
+#else
+ ngx_write_stderr("TLS SNI support disabled" NGX_LINEFEED);
+#endif
+#endif
+
+ ngx_write_stderr("configure arguments:" NGX_CONFIGURE NGX_LINEFEED);
+ }
+}
+
+
static ngx_int_t
ngx_add_inherited_sockets(ngx_cycle_t *cycle)
{

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Extract out version info function

Kurtis Nusbaum 705 September 27, 2015 12:18AM

Re: [PATCH] Extract out version info function

Maxim Dounin 395 September 30, 2015 01:04PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 242
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready