comparison src/masqmail.c @ 72:ad034b57f3b2

fixed Debian bug 536060 (log files are closed after SIGHUP receival) Explanation: When run in daemon mode, first the log files are opened. They get assigned to the file descriptors 3 and 4 usually. Then std{in,out,err} are closed. When SIGHUP comes in, all open files are closes and masqmail reexecutes itself. The new masqmail instance opens the log files at fd 0 and 1 now, but std{in,out,err} are closed afterwards, thus the log files are closed. The fix is to close the log files before std{in,out,err} are closed, in case the log files have higher fds. After std{in,out,err} were closed, the log files get opened again, now. See also: http://bugs.debian.org/536060
author meillo@marmaro.de
date Wed, 16 Jun 2010 10:32:20 +0200
parents 3cb6f383f07e
children 9db75b801dc4
comparison
equal deleted inserted replaced
71:98cda87105a7 72:ad034b57f3b2
159 signal(SIGTERM, sigterm_handler); 159 signal(SIGTERM, sigterm_handler);
160 write_pidfile(PIDFILEDIR "/masqmail.pid"); 160 write_pidfile(PIDFILEDIR "/masqmail.pid");
161 161
162 conf.do_verbose = FALSE; 162 conf.do_verbose = FALSE;
163 163
164 /* closing and reopening the log ensures that it is open afterwards
165 because it is possible that the log is assigned to fd 1 and gets
166 thus closes by fclose(stdout). Similar for the debugfile.
167 */
168 logclose();
164 fclose(stdin); 169 fclose(stdin);
165 fclose(stdout); 170 fclose(stdout);
166 fclose(stderr); 171 fclose(stderr);
172 logopen();
167 173
168 listen_port(do_listen ? conf.listen_addresses : NULL, queue_interval, argv); 174 listen_port(do_listen ? conf.listen_addresses : NULL, queue_interval, argv);
169 } 175 }
170 176
171 #ifdef ENABLE_POP3 177 #ifdef ENABLE_POP3
192 signal(SIGTERM, sigterm_handler); 198 signal(SIGTERM, sigterm_handler);
193 write_pidfile(PIDFILEDIR "/masqmail-get.pid"); 199 write_pidfile(PIDFILEDIR "/masqmail-get.pid");
194 200
195 conf.do_verbose = FALSE; 201 conf.do_verbose = FALSE;
196 202
203 /* closing and reopening the log ensures that it is open afterwards
204 because it is possible that the log is assigned to fd 1 and gets
205 thus closes by fclose(stdout). Similar for the debugfile.
206 */
207 logclose();
197 fclose(stdin); 208 fclose(stdin);
198 fclose(stdout); 209 fclose(stdout);
199 fclose(stderr); 210 fclose(stderr);
211 logopen();
200 212
201 get_daemon(get_interval, argv); 213 get_daemon(get_interval, argv);
202 } 214 }
203 #endif 215 #endif
204 216