use sys_errlist[] in signal handler instead

of non Async-Signal-Safe strerror_r()
This commit is contained in:
Igor Sysoev 2010-03-12 11:15:26 +00:00
parent 7fa1c07896
commit 9eaabc69ca
3 changed files with 29 additions and 6 deletions

View File

@ -133,6 +133,16 @@ ngx_feature_test="char buf[1024]; long n; n = strerror_r(1, buf, 1024);
. auto/feature
ngx_feature="sys_errlist[]"
ngx_feature_name="NGX_HAVE_SYS_ERRLIST"
ngx_feature_run=yes
ngx_feature_incs="#include <stdio.h>"
ngx_feature_path=
ngx_feature_libs=
ngx_feature_test="int n = sys_nerr; const char *p = sys_errlist[1];"
. auto/feature
ngx_feature="localtime_r()"
ngx_feature_name="NGX_HAVE_LOCALTIME_R"
ngx_feature_run=no

View File

@ -64,10 +64,22 @@ u_char *ngx_strerror_r(int err, u_char *errstr, size_t size);
/* Solaris and Tru64 UNIX have thread-safe strerror() */
#define ngx_strerror_r(err, errstr, size) \
#define ngx_strerror_r(err, errstr, size) \
ngx_cpystrn(errstr, (u_char *) strerror(err), size)
#endif
#if (NGX_HAVE_SYS_ERRLIST)
#define ngx_sigsafe_strerror(err) \
(err > 0 && err < sys_nerr) ? sys_errlist[err] : "Unknown error"
#else
#define ngx_sigsafe_strerror(err) ""
#endif
#endif /* _NGX_ERRNO_H_INCLUDED_ */

View File

@ -479,16 +479,17 @@ ngx_process_get_status(void)
*/
if (err == NGX_ECHILD) {
ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, errno,
"waitpid() failed");
ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0,
"waitpid() failed (%d: %s)",
err, ngx_sigsafe_strerror(err));
return;
}
#endif
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, errno,
"waitpid() failed");
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
"waitpid() failed (%d: %s)",
err, ngx_sigsafe_strerror(err));
return;
}