]> git.pld-linux.org Git - packages/lighttpd.git/blame - lighttpd-modinit-before-fork.patch
up to 1.4.38
[packages/lighttpd.git] / lighttpd-modinit-before-fork.patch
CommitLineData
e6332a1d
ER
1--- ./src/server.c (working copy)
2+++ lighttpd-1.4.19/src/server.c 2008-09-19 17:43:33.695522751 +0300
25bbbdde
ER
3@@ -865,34 +865,9 @@
4 return -1;
5 }
6
7-#ifdef HAVE_FORK
8- /* network is up, let's deamonize ourself */
9- if (srv->srvconf.dont_daemonize == 0) daemonize();
10-#endif
11-
12 srv->gid = getgid();
13 srv->uid = getuid();
14
15- /* write pid file */
16- if (pid_fd != -1) {
17- buffer_copy_long(srv->tmp_buf, getpid());
e6332a1d 18- buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("\n"));
25bbbdde
ER
19- write(pid_fd, srv->tmp_buf->ptr, srv->tmp_buf->used - 1);
20- close(pid_fd);
21- pid_fd = -1;
22- }
23-
24- /* Close stderr ASAP in the child process to make sure that nothing
25- * is being written to that fd which may not be valid anymore. */
26- if (-1 == log_error_open(srv)) {
27- log_error_write(srv, __FILE__, __LINE__, "s", "Opening errorlog failed. Going down.");
28-
29- plugins_free(srv);
30- network_close(srv);
31- server_free(srv);
32- return -1;
33- }
34-
35 if (HANDLER_GO_ON != plugins_call_set_defaults(srv)) {
36 log_error_write(srv, __FILE__, __LINE__, "s", "Configuration of plugins failed. Going down.");
37
e6332a1d 38@@ -918,7 +893,86 @@
25bbbdde
ER
39 return -1;
40 }
41
42+ if (NULL == (srv->ev = fdevent_init(srv->max_fds + 1, srv->event_handler))) {
43+ log_error_write(srv, __FILE__, __LINE__,
44+ "s", "fdevent_init failed");
45+ return -1;
46+ }
47+ /*
48+ * kqueue() is called here, select resets its internals,
49+ * all server sockets get their handlers
50+ *
51+ * */
52+ if (0 != network_register_fdevents(srv)) {
53+ plugins_free(srv);
54+ network_close(srv);
55+ server_free(srv);
e6332a1d 56+
25bbbdde
ER
57+ return -1;
58+ }
e6332a1d 59+
25bbbdde
ER
60+ /* might fail if user is using fam (not gamin) and famd isn't running */
61+ if (NULL == (srv->stat_cache = stat_cache_init())) {
62+ log_error_write(srv, __FILE__, __LINE__, "s",
63+ "stat-cache could not be setup, dieing.");
64+ return -1;
65+ }
e6332a1d 66+
25bbbdde
ER
67+#ifdef HAVE_FAM_H
68+ /* setup FAM */
69+ if (srv->srvconf.stat_cache_engine == STAT_CACHE_ENGINE_FAM) {
70+ if (0 != FAMOpen2(srv->stat_cache->fam, "lighttpd")) {
71+ log_error_write(srv, __FILE__, __LINE__, "s",
72+ "could not open a fam connection, dieing.");
73+ return -1;
74+ }
75+#ifdef HAVE_FAMNOEXISTS
76+ FAMNoExists(srv->stat_cache->fam);
77+#endif
78+
79+ srv->stat_cache->fam_fcce_ndx = -1;
80+ fdevent_register(srv->ev, FAMCONNECTION_GETFD(srv->stat_cache->fam), stat_cache_handle_fdevent, NULL);
81+ fdevent_event_add(srv->ev, &(srv->stat_cache->fam_fcce_ndx), FAMCONNECTION_GETFD(srv->stat_cache->fam), FDEVENT_IN);
82+ }
83+#endif
84+
85+
86+ /* get the current number of FDs */
87+ srv->cur_fds = open("/dev/null", O_RDONLY);
88+ close(srv->cur_fds);
89+
90+ for (i = 0; i < srv->srv_sockets.used; i++) {
91+ server_socket *srv_socket = srv->srv_sockets.ptr[i];
92+ if (-1 == fdevent_fcntl_set(srv->ev, srv_socket->fd)) {
93+ log_error_write(srv, __FILE__, __LINE__, "ss", "fcntl failed:", strerror(errno));
94+ return -1;
95+ }
96+ }
97+
98+ /* Close stderr ASAP to make sure that nothing is being written to
99+ * that fd which may not be valid anymore after forking. */
100+ if (-1 == log_error_open(srv)) {
101+ log_error_write(srv, __FILE__, __LINE__, "s", "Opening errorlog failed. Going down.");
102+
103+ plugins_free(srv);
104+ network_close(srv);
105+ server_free(srv);
106+ return -1;
107+ }
108+
109+#ifdef HAVE_FORK
110+ /* network is up, let's deamonize ourself */
111+ if (srv->srvconf.dont_daemonize == 0) daemonize();
112+#endif
e6332a1d 113
25bbbdde
ER
114+ /* write pid file */
115+ if (pid_fd != -1) {
116+ buffer_copy_long(srv->tmp_buf, getpid());
e6332a1d 117+ buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("\n"));
25bbbdde
ER
118+ write(pid_fd, srv->tmp_buf->ptr, srv->tmp_buf->used - 1);
119+ close(pid_fd);
120+ pid_fd = -1;
121+ }
e6332a1d
ER
122
123
25bbbdde 124 #ifdef HAVE_SIGACTION
e6332a1d 125@@ -1042,62 +1096,6 @@
25bbbdde
ER
126 }
127 #endif
128
129- if (NULL == (srv->ev = fdevent_init(srv->max_fds + 1, srv->event_handler))) {
130- log_error_write(srv, __FILE__, __LINE__,
131- "s", "fdevent_init failed");
132- return -1;
133- }
134- /*
135- * kqueue() is called here, select resets its internals,
136- * all server sockets get their handlers
137- *
138- * */
139- if (0 != network_register_fdevents(srv)) {
140- plugins_free(srv);
141- network_close(srv);
142- server_free(srv);
143-
144- return -1;
145- }
146-
147- /* might fail if user is using fam (not gamin) and famd isn't running */
148- if (NULL == (srv->stat_cache = stat_cache_init())) {
149- log_error_write(srv, __FILE__, __LINE__, "s",
150- "stat-cache could not be setup, dieing.");
151- return -1;
152- }
153-
154-#ifdef HAVE_FAM_H
155- /* setup FAM */
156- if (srv->srvconf.stat_cache_engine == STAT_CACHE_ENGINE_FAM) {
157- if (0 != FAMOpen2(srv->stat_cache->fam, "lighttpd")) {
158- log_error_write(srv, __FILE__, __LINE__, "s",
159- "could not open a fam connection, dieing.");
160- return -1;
161- }
162-#ifdef HAVE_FAMNOEXISTS
163- FAMNoExists(srv->stat_cache->fam);
164-#endif
165-
166- srv->stat_cache->fam_fcce_ndx = -1;
167- fdevent_register(srv->ev, FAMCONNECTION_GETFD(srv->stat_cache->fam), stat_cache_handle_fdevent, NULL);
168- fdevent_event_add(srv->ev, &(srv->stat_cache->fam_fcce_ndx), FAMCONNECTION_GETFD(srv->stat_cache->fam), FDEVENT_IN);
169- }
170-#endif
171-
172-
173- /* get the current number of FDs */
174- srv->cur_fds = open("/dev/null", O_RDONLY);
175- close(srv->cur_fds);
176-
177- for (i = 0; i < srv->srv_sockets.used; i++) {
178- server_socket *srv_socket = srv->srv_sockets.ptr[i];
179- if (-1 == fdevent_fcntl_set(srv->ev, srv_socket->fd)) {
180- log_error_write(srv, __FILE__, __LINE__, "ss", "fcntl failed:", strerror(errno));
181- return -1;
182- }
183- }
184-
185 /* main-loop */
186 while (!srv_shutdown) {
187 int n;
This page took 0.06285 seconds and 4 git commands to generate.