summaryrefslogtreecommitdiff
path: root/www-misc/pglogd/files/pglogd-2.3-foreground.patch
blob: 9ccf1e43f4b7f6820c6c5ea9bd0e15593d540795 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
diff --git a/pglogd.c b/pglogd.c
index 4635a4c..c13f1c2 100644
--- a/pglogd.c
+++ b/pglogd.c
@@ -210,6 +210,7 @@ main(int argc, char **argv)
 	 */
 	char *cpConfigFile;			/* The user supplied configuration file. */
 	int iSkipDatabase;			/* Whether or not to skip the database connection at start-up. */
+	int iDaemonize;				/* Whether to become a daemon */
 
 
 	/*
@@ -266,13 +267,15 @@ main(int argc, char **argv)
 
 	cpConfigFile = NULL;
 	iSkipDatabase = FALSE;
+	iDaemonize = TRUE;
 
 
 	/*
-	 * Check for our two options:
+	 * Check for our three options:
 	 *
 	 *  1. Skip connecting to the database at statup.
 	 *  2. Read from a specified config file.
+	 *  3. Run in foreground.
 	 */
 	for ( i = 1 ; i < argc ; i++ )
 	{
@@ -284,6 +287,8 @@ main(int argc, char **argv)
 
 		else if ( strncmp(&(*argv[i]), "-s", 2) == 0 )
 			iSkipDatabase = TRUE;
+		else if ( strncmp(&(*argv[i]), "-f", 2) == 0 )
+		    	iDaemonize = FALSE;
 	}
 
 
@@ -352,26 +357,28 @@ main(int argc, char **argv)
 	}
 
 
-	/*
-	 * Become a deamon, muhaaaa
-	 */
-	if ( (pPid = fork()) < 0 )
-	{
-		fprintf(stderr, "%s: Fatal error, could not fork() [%d]\n", cpAppName, errno);
-		exit(ERR_FORK);
-	}
+	if(iDaemonize) {
+	    /*
+	     * Become a deamon, muhaaaa
+	     */
+	    if ( (pPid = fork()) < 0 )
+	    {
+		    fprintf(stderr, "%s: Fatal error, could not fork() [%d]\n", cpAppName, errno);
+		    exit(ERR_FORK);
+	    }
 
-	else if ( pPid != 0 )
-		exit(ERR_NORMAL);
+	    else if ( pPid != 0 )
+		    exit(ERR_NORMAL);
 
 
-	/*
-	 * Parent is gone, the child becomes the session leader.
-	 */
-	setsid();
+	    /*
+	     * Parent is gone, the child becomes the session leader.
+	     */
+	    setsid();
+	    iDaemon = 1;
+	}
 	chdir("/");
 	umask(S_IWGRP|S_IWOTH);
-	iDaemon = 1;
 
 	logentry("Resuming normal operation.", 0);