comparison src/os/unix/ngx_unix_init.c @ 93:738fe44c70d5

nginx-0.0.1-2003-05-21-17:28:21 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 21 May 2003 13:28:21 +0000
parents 19cc647ecd91
children 1bf718ce0dde
comparison
equal deleted inserted replaced
92:19cc647ecd91 93:738fe44c70d5
1 1
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3 #include <ngx_core.h> 3 #include <ngx_core.h>
4 4
5 5
6 int ngx_max_sockets; 6 /* STUB */
7 ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size);
8 ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in);
9 int ngx_posix_init(ngx_log_t *log);
10 int ngx_posix_post_conf_init(ngx_log_t *log);
11 /* */
7 12
8 13
9 int ngx_unix_init(ngx_log_t *log) 14 ngx_os_io_t ngx_os_io = {
10 { 15 ngx_unix_recv,
11 struct sigaction sa; 16 NULL,
12 struct rlimit rlmt; 17 NULL,
13 18 ngx_writev_chain,
14 ngx_memzero(&sa, sizeof(struct sigaction)); 19 NGX_HAVE_ZEROCOPY
15 sa.sa_handler = SIG_IGN; 20 };
16 sigemptyset(&sa.sa_mask);
17
18 if (sigaction(SIGPIPE, &sa, NULL) == -1) {
19 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
20 "sigaction(SIGPIPE, SIG_IGN) failed");
21 return NGX_ERROR;
22 }
23 21
24 22
25 if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) { 23 int ngx_os_init(ngx_log_t *log)
26 ngx_log_error(NGX_LOG_ALERT, log, errno, 24 {
27 "getrlimit(RLIMIT_NOFILE) failed)"); 25 return ngx_posix_init(log);
28 return NGX_ERROR;
29 }
30
31 ngx_log_error(NGX_LOG_INFO, log, 0,
32 "getrlimit(RLIMIT_NOFILE): %qd:%qd",
33 rlmt.rlim_cur, rlmt.rlim_max);
34
35 ngx_max_sockets = rlmt.rlim_cur;
36
37 return NGX_OK;
38 } 26 }
39 27
40 28
41 int ngx_unix_post_conf_init(ngx_log_t *log) 29 int ngx_os_post_conf_init(ngx_log_t *log)
42 { 30 {
43 ngx_fd_t pp[2]; 31 return ngx_posix_post_conf_init(log);
44
45 if (pipe(pp) == -1) {
46 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "pipe() failed");
47 return NGX_ERROR;
48 }
49
50 if (dup2(pp[1], STDERR_FILENO) == -1) {
51 ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed");
52 return NGX_ERROR;
53 }
54
55 if (pp[1] > STDERR_FILENO) {
56 if (close(pp[1]) == -1) {
57 ngx_log_error(NGX_LOG_EMERG, log, errno, "close() failed");
58 return NGX_ERROR;
59 }
60 }
61
62 return NGX_OK;
63 } 32 }