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);