44 * Revisions by Christopher B. Browne, Liberty RMS
55 * Win32 Service code added by Dave Page
66 *
7- * $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.c,v 1.29 2005/01/26 22:25:13 tgl Exp $
7+ * $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.c,v 1.30 2005/04/03 00:01:51 tgl Exp $
88 */
99
1010#include "postgres_fe.h"
1818#ifdef WIN32
1919#include <windows.h>
2020#endif
21+ #include <sys/stat.h>
22+ #include <fcntl.h>
2123
2224#include "pg_autovacuum.h"
2325
@@ -186,13 +188,13 @@ log_entry(const char *logentry, int level)
186188 * Function used to detach the pg_autovacuum daemon from the tty and go into
187189 * the background.
188190 *
189- * This code is mostly ripped directly from pm_dameonize in postmaster.c with
190- * unneeded code removed.
191+ * This code is ripped directly from pmdaemonize in postmaster.c.
191192 */
192193#ifndef WIN32
193194static void
194195daemonize (void )
195196{
197+ int i ;
196198pid_t pid ;
197199
198200pid = fork ();
@@ -209,7 +211,8 @@ daemonize(void)
209211}
210212
211213/* GH: If there's no setsid(), we hopefully don't need silent mode.
212- * Until there's a better solution. */
214+ * Until there's a better solution.
215+ */
213216#ifdef HAVE_SETSID
214217if (setsid ()< 0 )
215218{
@@ -218,7 +221,11 @@ daemonize(void)
218221_exit (1 );
219222}
220223#endif
221-
224+ i = open (NULL_DEV ,O_RDWR );
225+ dup2 (i ,0 );
226+ dup2 (i ,1 );
227+ dup2 (i ,2 );
228+ close (i );
222229}
223230#endif /* WIN32 */
224231