Mercurial > hg > nginx
comparison src/core/ngx_cycle.c @ 2738:ae81441e23f4
implement "-s signal" option for Unix
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 21 Apr 2009 20:25:49 +0000 |
parents | 218b8949f2fd |
children | d8316f307b6a |
comparison
equal
deleted
inserted
replaced
2737:d52cf82d0d77 | 2738:ae81441e23f4 |
---|---|
567 } | 567 } |
568 #endif | 568 #endif |
569 } | 569 } |
570 } | 570 } |
571 | 571 |
572 if (ngx_open_listening_sockets(cycle) != NGX_OK) { | 572 if (ngx_process != NGX_PROCESS_SIGNALLER) { |
573 goto failed; | 573 if (ngx_open_listening_sockets(cycle) != NGX_OK) { |
574 } | 574 goto failed; |
575 | 575 } |
576 if (!ngx_test_config) { | 576 |
577 ngx_configure_listening_socket(cycle); | 577 if (!ngx_test_config) { |
578 ngx_configure_listening_socket(cycle); | |
579 } | |
578 } | 580 } |
579 | 581 |
580 | 582 |
581 /* commit the new cycle configuration */ | 583 /* commit the new cycle configuration */ |
582 | 584 |
981 | 983 |
982 if (ngx_delete_file(name) == NGX_FILE_ERROR) { | 984 if (ngx_delete_file(name) == NGX_FILE_ERROR) { |
983 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | 985 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
984 ngx_delete_file_n " \"%s\" failed", name); | 986 ngx_delete_file_n " \"%s\" failed", name); |
985 } | 987 } |
988 } | |
989 | |
990 | |
991 ngx_int_t | |
992 ngx_signal_process(ngx_cycle_t *cycle, char *sig) | |
993 { | |
994 ssize_t n; | |
995 ngx_int_t pid; | |
996 ngx_file_t file; | |
997 ngx_core_conf_t *ccf; | |
998 u_char buf[NGX_INT64_LEN + 2]; | |
999 | |
1000 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "signal process started"); | |
1001 | |
1002 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | |
1003 | |
1004 file.name = ccf->pid; | |
1005 file.log = cycle->log; | |
1006 | |
1007 file.fd = ngx_open_file(file.name.data, NGX_FILE_RDONLY, | |
1008 NGX_FILE_OPEN, NGX_FILE_DEFAULT_ACCESS); | |
1009 | |
1010 if (file.fd == NGX_INVALID_FILE) { | |
1011 ngx_log_error(NGX_LOG_ERR, cycle->log, ngx_errno, | |
1012 ngx_open_file_n " \"%s\" failed", file.name.data); | |
1013 return 1; | |
1014 } | |
1015 | |
1016 n = ngx_read_file(&file, buf, NGX_INT64_LEN + 2, 0); | |
1017 | |
1018 if (ngx_close_file(file.fd) == NGX_FILE_ERROR) { | |
1019 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
1020 ngx_close_file_n " \"%s\" failed", file.name.data); | |
1021 } | |
1022 | |
1023 if (n == NGX_ERROR) { | |
1024 return 1; | |
1025 } | |
1026 | |
1027 while (n-- && (buf[n] == CR || buf[n] == LF)) { /* void */ } | |
1028 | |
1029 pid = ngx_atoi(buf, ++n); | |
1030 | |
1031 if (pid == NGX_ERROR) { | |
1032 ngx_log_error(NGX_LOG_ERR, cycle->log, 0, | |
1033 "invalid PID number \"%*s\" in \"%s\"", | |
1034 n, buf, file.name.data); | |
1035 return 1; | |
1036 } | |
1037 | |
1038 return ngx_os_signal_process(cycle, sig, pid); | |
1039 | |
986 } | 1040 } |
987 | 1041 |
988 | 1042 |
989 static ngx_int_t | 1043 static ngx_int_t |
990 ngx_test_lockfile(u_char *file, ngx_log_t *log) | 1044 ngx_test_lockfile(u_char *file, ngx_log_t *log) |