"nginx -v" outputs is in stderr.
Takahiro Kujirai
takahiro.kujirai at it.zeus-enterprise.co.jp
Wed Feb 17 08:07:12 UTC 2016
Hi all,
This is Takahiro Kujirai.
When I typed "nginx -v > /tmp/nginx.txt" on nginx 1.9.11, I found output
is in stderr.
-------
[root at localhost ~]# nginx -v > /tmp/nginx.txt
nginx version: nginx/1.9.11
[root at localhost ~]#
[root at localhost ~]# nginx -v 2> /tmp/nginx.txt
[root at localhost ~]# cat /tmp/nginx.txt
nginx version: nginx/1.9.11
I read source code(line374-434 of
https://github.com/nginx/nginx/blob/master/src/core/nginx.c),
I found using ngx_write_stderr.
-------
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);
}
}
I think "stdout" is good, not "stderr", is this the design?
And I created patch for this problem.
-------
[root at localhost ~]# diff -u ./src/core/nginx.c ./src2/core/nginx.c
--- ./src/core/nginx.c2016-02-10 22:56:57.915997223 +0900
+++ ./src2/core/nginx.c2016-02-09 23:11:57.000000000 +0900
@@ -374,10 +374,10 @@
static void
ngx_show_version_info()
{
- ngx_write_stdout("nginx version: " NGINX_VER_BUILD NGX_LINEFEED);
+ ngx_write_stderr("nginx version: " NGINX_VER_BUILD NGX_LINEFEED);
if (ngx_show_help) {
- ngx_write_stdout(
+ ngx_write_stderr(
"Usage: nginx [-?hvVtTq] [-s signal] [-c filename] "
"[-p prefix] [-g directives]" NGX_LINEFEED
NGX_LINEFEED
@@ -409,27 +409,27 @@
if (ngx_show_configure) {
#ifdef NGX_COMPILER
- ngx_write_stdout("built by " NGX_COMPILER NGX_LINEFEED);
+ ngx_write_stderr("built by " NGX_COMPILER NGX_LINEFEED);
#endif
#if (NGX_SSL)
if (SSLeay() == SSLEAY_VERSION_NUMBER) {
- ngx_write_stdout("built with " OPENSSL_VERSION_TEXT
NGX_LINEFEED);
+ ngx_write_stderr("built with " OPENSSL_VERSION_TEXT
NGX_LINEFEED);
} else {
- ngx_write_stdout("built with " OPENSSL_VERSION_TEXT
+ ngx_write_stderr("built with " OPENSSL_VERSION_TEXT
" (running with ");
- ngx_write_stdout((char *) (uintptr_t)
+ ngx_write_stderr((char *) (uintptr_t)
SSLeay_version(SSLEAY_VERSION));
- ngx_write_stdout(")" NGX_LINEFEED);
+ ngx_write_stderr(")" NGX_LINEFEED);
}
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
- ngx_write_stdout("TLS SNI support enabled" NGX_LINEFEED);
+ ngx_write_stderr("TLS SNI support enabled" NGX_LINEFEED);
#else
- ngx_write_stdout("TLS SNI support disabled" NGX_LINEFEED);
+ ngx_write_stderr("TLS SNI support disabled" NGX_LINEFEED);
#endif
#endif
- ngx_write_stdout("configure arguments:" NGX_CONFIGURE
NGX_LINEFEED);
+ ngx_write_stderr("configure arguments:" NGX_CONFIGURE
NGX_LINEFEED);
}
}
Best Regards,
Takahiro Kujirai
@Zeus-Enterprise.Co.Ltd
More information about the nginx-devel
mailing list