Klaus Demo nginx / 32c8df4
Changed ngx_open_and_stat_file() to use ngx_str_t. No functional changes. Andrey Belov 10 years ago
1 changed file(s) with 20 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
2121
2222
2323 static void ngx_open_file_cache_cleanup(void *data);
24 static ngx_int_t ngx_open_and_stat_file(u_char *name, ngx_open_file_info_t *of,
25 ngx_log_t *log);
24 static ngx_int_t ngx_open_and_stat_file(ngx_str_t *name,
25 ngx_open_file_info_t *of, ngx_log_t *log);
2626 static void ngx_open_file_add_event(ngx_open_file_cache_t *cache,
2727 ngx_cached_open_file_t *file, ngx_open_file_info_t *of, ngx_log_t *log);
2828 static void ngx_open_file_cleanup(void *data);
169169 return NGX_ERROR;
170170 }
171171
172 rc = ngx_open_and_stat_file(name->data, of, pool->log);
172 rc = ngx_open_and_stat_file(name, of, pool->log);
173173
174174 if (rc == NGX_OK && !of->is_dir) {
175175 cln->handler = ngx_pool_cleanup_file;
204204
205205 /* file was not used often enough to keep open */
206206
207 rc = ngx_open_and_stat_file(name->data, of, pool->log);
207 rc = ngx_open_and_stat_file(name, of, pool->log);
208208
209209 if (rc != NGX_OK && (of->err == 0 || !of->errors)) {
210210 goto failed;
262262 of->fd = file->fd;
263263 of->uniq = file->uniq;
264264
265 rc = ngx_open_and_stat_file(name->data, of, pool->log);
265 rc = ngx_open_and_stat_file(name, of, pool->log);
266266
267267 if (rc != NGX_OK && (of->err == 0 || !of->errors)) {
268268 goto failed;
310310
311311 if (ngx_close_file(file->fd) == NGX_FILE_ERROR) {
312312 ngx_log_error(NGX_LOG_ALERT, pool->log, ngx_errno,
313 ngx_close_file_n " \"%s\" failed",
314 name->data);
313 ngx_close_file_n " \"%V\" failed", name);
315314 }
316315
317316 goto add_event;
328327
329328 /* not found */
330329
331 rc = ngx_open_and_stat_file(name->data, of, pool->log);
330 rc = ngx_open_and_stat_file(name, of, pool->log);
332331
333332 if (rc != NGX_OK && (of->err == 0 || !of->errors)) {
334333 goto failed;
451450 if (of->fd != NGX_INVALID_FILE) {
452451 if (ngx_close_file(of->fd) == NGX_FILE_ERROR) {
453452 ngx_log_error(NGX_LOG_ALERT, pool->log, ngx_errno,
454 ngx_close_file_n " \"%s\" failed", name->data);
453 ngx_close_file_n " \"%V\" failed", name);
455454 }
456455 }
457456
460459
461460
462461 static ngx_int_t
463 ngx_open_and_stat_file(u_char *name, ngx_open_file_info_t *of, ngx_log_t *log)
462 ngx_open_and_stat_file(ngx_str_t *name, ngx_open_file_info_t *of,
463 ngx_log_t *log)
464464 {
465465 ngx_fd_t fd;
466466 ngx_file_info_t fi;
467467
468468 if (of->fd != NGX_INVALID_FILE) {
469469
470 if (ngx_file_info(name, &fi) == NGX_FILE_ERROR) {
470 if (ngx_file_info(name->data, &fi) == NGX_FILE_ERROR) {
471471 of->failed = ngx_file_info_n;
472472 goto failed;
473473 }
478478
479479 } else if (of->test_dir) {
480480
481 if (ngx_file_info(name, &fi) == NGX_FILE_ERROR) {
481 if (ngx_file_info(name->data, &fi) == NGX_FILE_ERROR) {
482482 of->failed = ngx_file_info_n;
483483 goto failed;
484484 }
495495 * This flag has no effect on a regular files.
496496 */
497497
498 fd = ngx_open_file(name, NGX_FILE_RDONLY|NGX_FILE_NONBLOCK,
498 fd = ngx_open_file(name->data, NGX_FILE_RDONLY|NGX_FILE_NONBLOCK,
499499 NGX_FILE_OPEN, 0);
500500
501501 } else {
502 fd = ngx_open_file(name, NGX_FILE_APPEND, NGX_FILE_CREATE_OR_OPEN,
502 fd = ngx_open_file(name->data, NGX_FILE_APPEND,
503 NGX_FILE_CREATE_OR_OPEN,
503504 NGX_FILE_DEFAULT_ACCESS);
504505 }
505506
510511
511512 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) {
512513 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno,
513 ngx_fd_info_n " \"%s\" failed", name);
514 ngx_fd_info_n " \"%V\" failed", name);
514515
515516 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
516517 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
517 ngx_close_file_n " \"%s\" failed", name);
518 ngx_close_file_n " \"%V\" failed", name);
518519 }
519520
520521 of->fd = NGX_INVALID_FILE;
525526 if (ngx_is_dir(&fi)) {
526527 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
527528 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
528 ngx_close_file_n " \"%s\" failed", name);
529 ngx_close_file_n " \"%V\" failed", name);
529530 }
530531
531532 of->fd = NGX_INVALID_FILE;
536537 if (of->read_ahead && ngx_file_size(&fi) > NGX_MIN_READ_AHEAD) {
537538 if (ngx_read_ahead(fd, of->read_ahead) == NGX_ERROR) {
538539 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
539 ngx_read_ahead_n " \"%s\" failed", name);
540 ngx_read_ahead_n " \"%V\" failed", name);
540541 }
541542 }
542543
543544 if (of->directio <= ngx_file_size(&fi)) {
544545 if (ngx_directio_on(fd) == NGX_FILE_ERROR) {
545546 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
546 ngx_directio_on_n " \"%s\" failed", name);
547 ngx_directio_on_n " \"%V\" failed", name);
547548
548549 } else {
549550 of->is_directio = 1;