r2303 merge:

compatibility with glibc 2.3, warn_unused_result attribute for write()
This commit is contained in:
Igor Sysoev 2008-11-20 17:23:08 +00:00
parent 3d87cb964c
commit d0d575bcd5
5 changed files with 66 additions and 18 deletions

View File

@ -192,6 +192,8 @@ static char **ngx_os_environ;
int ngx_cdecl
main(int argc, char *const *argv)
{
char *p;
ssize_t n;
ngx_int_t i;
ngx_log_t *log;
ngx_cycle_t *cycle, init_cycle;
@ -241,23 +243,30 @@ main(int argc, char *const *argv)
}
if (ngx_show_version) {
ngx_write_fd(ngx_stderr_fileno, "nginx version: " NGINX_VER CRLF,
sizeof("nginx version: " NGINX_VER CRLF) - 1);
p = "nginx version: " NGINX_VER CRLF;
n = sizeof("nginx version: " NGINX_VER CRLF) - 1;
if (ngx_write_fd(ngx_stderr_fileno, p, n) != n) {
return 1;
}
if (ngx_show_configure) {
#ifdef NGX_COMPILER
ngx_write_fd(ngx_stderr_fileno, "built by " NGX_COMPILER CRLF,
sizeof("built by " NGX_COMPILER CRLF) - 1);
p = "built by " NGX_COMPILER CRLF;
n = sizeof("built by " NGX_COMPILER CRLF) - 1;
if (ngx_write_fd(ngx_stderr_fileno, p, n) != n) {
return 1;
}
#endif
#ifndef __WATCOMC__
p = "configure arguments: " NGX_CONFIGURE CRLF;
n = sizeof("configure arguments :" NGX_CONFIGURE CRLF) - 1;
/* OpenWatcomC could not build the long NGX_CONFIGURE string */
ngx_write_fd(ngx_stderr_fileno,
"configure arguments: " NGX_CONFIGURE CRLF,
sizeof("configure arguments :" NGX_CONFIGURE CRLF) - 1);
#endif
if (ngx_write_fd(ngx_stderr_fileno, p, n) != n) {
return 1;
}
}
if (!ngx_test_config) {

View File

@ -806,6 +806,7 @@ ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
static void
ngx_conf_flush_files(ngx_cycle_t *cycle)
{
ssize_t n, len;
ngx_uint_t i;
ngx_list_part_t *part;
ngx_open_file_t *file;
@ -826,11 +827,24 @@ ngx_conf_flush_files(ngx_cycle_t *cycle)
i = 0;
}
if (file[i].buffer == NULL || file[i].pos - file[i].buffer == 0) {
len = file[i].pos - file[i].buffer;
if (file[i].buffer == NULL || len == 0) {
continue;
}
ngx_write_fd(file[i].fd, file[i].buffer, file[i].pos - file[i].buffer);
n = ngx_write_fd(file[i].fd, file[i].buffer, len);
if (n == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_write_fd_n " to \"%s\" failed",
file[i].name.data);
} else if (n != len) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",
file[i].name.data, n, len);
}
}
}

View File

@ -970,6 +970,7 @@ ngx_test_lockfile(u_char *file, ngx_log_t *log)
void
ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
{
ssize_t n, len;
ngx_fd_t fd;
ngx_uint_t i;
ngx_list_part_t *part;
@ -993,9 +994,23 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
continue;
}
if (file[i].buffer && file[i].pos - file[i].buffer != 0) {
ngx_write_fd(file[i].fd, file[i].buffer,
file[i].pos - file[i].buffer);
len = file[i].pos - file[i].buffer;
if (file[i].buffer && len != 0) {
n = ngx_write_fd(file[i].fd, file[i].buffer, len);
if (n == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_write_fd_n " to \"%s\" failed",
file[i].name.data);
} else if (n != len) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",
file[i].name.data, n, len);
}
file[i].pos = file[i].buffer;
}

View File

@ -158,7 +158,7 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
ngx_linefeed(p);
ngx_write_fd(log->file->fd, errstr, p - errstr);
(void) ngx_write_fd(log->file->fd, errstr, p - errstr);
}

View File

@ -68,7 +68,17 @@ ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *ce,
#define ngx_read_fd read
#define ngx_read_fd_n "read()"
#define ngx_write_fd write
/*
* we use inlined function instead of simple #define
* because glibc 2.3 sets warn_unused_result attribute for write()
* and in this case gcc 4.3 ignores (void) cast
*/
static ngx_inline ssize_t
ngx_write_fd(ngx_fd_t fd, void *buf, size_t n)
{
return write(fd, buf, n);
}
#define ngx_write_fd_n "write()"
#define ngx_linefeed(p) *p++ = LF;