Klaus Demo nginx / 4724f2b
use uname(2) instead of /proc/, this allows to run nginx in chroot Igor Sysoev 14 years ago
2 changed file(s) with 13 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
4949 #include <sys/ioctl.h>
5050 #include <sys/sysctl.h>
5151 #include <crypt.h>
52 #include <sys/utsname.h> /* uname() */
5253
5354
5455 #include <ngx_auto_config.h>
77 #include <ngx_core.h>
88
99
10 static ngx_int_t ngx_linux_procfs(char *name, char *buf, size_t len,
11 ngx_log_t *log);
12
13
14 char ngx_linux_kern_ostype[50];
15 char ngx_linux_kern_osrelease[50];
10 u_char ngx_linux_kern_ostype[50];
11 u_char ngx_linux_kern_osrelease[50];
1612
1713 int ngx_linux_rtsig_max;
1814
3430 ngx_int_t
3531 ngx_os_specific_init(ngx_log_t *log)
3632 {
37 int name[2];
38 size_t len;
39 ngx_err_t err;
33 int name[2];
34 size_t len;
35 ngx_err_t err;
36 struct utsname u;
4037
41 if (ngx_linux_procfs("/proc/sys/kernel/ostype",
42 ngx_linux_kern_ostype,
43 sizeof(ngx_linux_kern_ostype), log)
44 == -1)
45 {
38 if (uname(&u) == -1) {
39 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "uname() failed");
4640 return NGX_ERROR;
4741 }
4842
49 if (ngx_linux_procfs("/proc/sys/kernel/osrelease",
50 ngx_linux_kern_osrelease,
51 sizeof(ngx_linux_kern_osrelease), log)
52 == -1)
53 {
54 return NGX_ERROR;
55 }
43 (void) ngx_cpystrn(ngx_linux_kern_ostype, (u_char *) u.sysname,
44 sizeof(ngx_linux_kern_ostype));
5645
46 (void) ngx_cpystrn(ngx_linux_kern_osrelease, (u_char *) u.release,
47 sizeof(ngx_linux_kern_osrelease));
5748
5849 name[0] = CTL_KERN;
5950 name[1] = KERN_RTSIGMAX;
8879 ngx_log_error(NGX_LOG_NOTICE, log, 0, "sysctl(KERN_RTSIGMAX): %d",
8980 ngx_linux_rtsig_max);
9081 }
91
92
93 static ngx_int_t
94 ngx_linux_procfs(char *name, char *buf, size_t len, ngx_log_t *log)
95 {
96 int n;
97 ngx_fd_t fd;
98
99 fd = open(name, O_RDONLY);
100
101 if (fd == NGX_INVALID_FILE) {
102 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
103 "open(\"%s\") failed", name);
104
105 return NGX_ERROR;
106 }
107
108 n = read(fd, buf, len);
109
110 if (n == -1) {
111 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
112 "read(\"%s\") failed", name);
113
114 } else {
115 if (buf[n - 1] == '\n') {
116 buf[--n] = '\0';
117 }
118 }
119
120 ngx_close_file(fd);
121
122 return n;
123 }