Klaus Demo nginx / f2884e1
compatibility with glibc 2.3, warn_unused_result attribute for write() Igor Sysoev 13 years ago
5 changed file(s) with 69 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
190190 int ngx_cdecl
191191 main(int argc, char *const *argv)
192192 {
193 char *p;
194 ssize_t n;
193195 ngx_int_t i;
194196 ngx_log_t *log;
195197 ngx_cycle_t *cycle, init_cycle;
239241 }
240242
241243 if (ngx_show_version) {
242 ngx_write_fd(ngx_stderr_fileno, "nginx version: " NGINX_VER CRLF,
243 sizeof("nginx version: " NGINX_VER CRLF) - 1);
244
245 p = "nginx version: " NGINX_VER CRLF;
246 n = sizeof("nginx version: " NGINX_VER CRLF) - 1;
247
248 if (ngx_write_fd(ngx_stderr_fileno, p, n) != n) {
249 return 1;
250 }
244251
245252 if (ngx_show_configure) {
246253 #ifdef NGX_COMPILER
247 ngx_write_fd(ngx_stderr_fileno, "built by " NGX_COMPILER CRLF,
248 sizeof("built by " NGX_COMPILER CRLF) - 1);
249 #endif
250
251 #ifndef __WATCOMC__
252
253 /* OpenWatcomC could not build the long NGX_CONFIGURE string */
254
255 ngx_write_fd(ngx_stderr_fileno,
256 "configure arguments: " NGX_CONFIGURE CRLF,
257 sizeof("configure arguments :" NGX_CONFIGURE CRLF) - 1);
258 #endif
254 p = "built by " NGX_COMPILER CRLF;
255 n = sizeof("built by " NGX_COMPILER CRLF) - 1;
256
257 if (ngx_write_fd(ngx_stderr_fileno, p, n) != n) {
258 return 1;
259 }
260 #endif
261
262 p = "configure arguments: " NGX_CONFIGURE CRLF;
263 n = sizeof("configure arguments :" NGX_CONFIGURE CRLF) - 1;
264
265 if (ngx_write_fd(ngx_stderr_fileno, p, n) != n) {
266 return 1;
267 }
259268 }
260269
261270 if (!ngx_test_config) {
911911 static void
912912 ngx_conf_flush_files(ngx_cycle_t *cycle)
913913 {
914 ssize_t n, len;
914915 ngx_uint_t i;
915916 ngx_list_part_t *part;
916917 ngx_open_file_t *file;
931932 i = 0;
932933 }
933934
934 if (file[i].buffer == NULL || file[i].pos - file[i].buffer == 0) {
935 len = file[i].pos - file[i].buffer;
936
937 if (file[i].buffer == NULL || len == 0) {
935938 continue;
936939 }
937940
938 ngx_write_fd(file[i].fd, file[i].buffer, file[i].pos - file[i].buffer);
941 n = ngx_write_fd(file[i].fd, file[i].buffer, len);
942
943 if (n == NGX_FILE_ERROR) {
944 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
945 ngx_write_fd_n " to \"%s\" failed",
946 file[i].name.data);
947
948 } else if (n != len) {
949 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
950 ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",
951 file[i].name.data, n, len);
952 }
939953 }
940954 }
941955
995995 void
996996 ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
997997 {
998 ssize_t n, len;
998999 ngx_fd_t fd;
9991000 ngx_uint_t i;
10001001 ngx_list_part_t *part;
10181019 continue;
10191020 }
10201021
1021 if (file[i].buffer && file[i].pos - file[i].buffer != 0) {
1022 ngx_write_fd(file[i].fd, file[i].buffer,
1023 file[i].pos - file[i].buffer);
1022 len = file[i].pos - file[i].buffer;
1023
1024 if (file[i].buffer && len != 0) {
1025
1026 n = ngx_write_fd(file[i].fd, file[i].buffer, len);
1027
1028 if (n == NGX_FILE_ERROR) {
1029 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
1030 ngx_write_fd_n " to \"%s\" failed",
1031 file[i].name.data);
1032
1033 } else if (n != len) {
1034 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
1035 ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",
1036 file[i].name.data, n, len);
1037 }
1038
10241039 file[i].pos = file[i].buffer;
10251040 }
10261041
157157
158158 ngx_linefeed(p);
159159
160 ngx_write_fd(log->file->fd, errstr, p - errstr);
160 (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
161161 }
162162
163163
9898 #define ngx_read_fd read
9999 #define ngx_read_fd_n "read()"
100100
101 #define ngx_write_fd write
101 /*
102 * we use inlined function instead of simple #define
103 * because glibc 2.3 sets warn_unused_result attribute for write()
104 * and in this case gcc 4.3 ignores (void) cast
105 */
106 static ngx_inline ssize_t
107 ngx_write_fd(ngx_fd_t fd, void *buf, size_t n)
108 {
109 return write(fd, buf, n);
110 }
111
102112 #define ngx_write_fd_n "write()"
103113
104114 #define ngx_linefeed(p) *p++ = LF;