summaryrefslogtreecommitdiffstats
path: root/tools/syslogd.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2013-04-17 11:10:51 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2013-04-17 11:10:51 +0200
commit3d914eb90cd7aed1342a01c5993f8c2de4cd1283 (patch)
tree46046d3136b5ca4fd864813b36b62d330a9c9559 /tools/syslogd.c
parent39b35a32b4a45ccb6506e15b02780c30ca8c3973 (diff)
parent9d59080b4a43ca6d19bece357cb1132374a2116a (diff)
downloadrsyslog-3d914eb90cd7aed1342a01c5993f8c2de4cd1283.tar.gz
rsyslog-3d914eb90cd7aed1342a01c5993f8c2de4cd1283.tar.bz2
rsyslog-3d914eb90cd7aed1342a01c5993f8c2de4cd1283.zip
Merge branch 'master' into master-imjournal
Diffstat (limited to 'tools/syslogd.c')
-rw-r--r--tools/syslogd.c53
1 files changed, 34 insertions, 19 deletions
diff --git a/tools/syslogd.c b/tools/syslogd.c
index c2928a8f..77adb2cb 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -218,7 +218,7 @@ static ratelimit_t *dflt_ratelimiter = NULL; /* ratelimiter for submits without
static ratelimit_t *internalMsg_ratelimiter = NULL; /* ratelimiter for rsyslog-own messages */
int MarkInterval = 20 * 60; /* interval between marks in seconds - read-only after startup */
int send_to_all = 0; /* send message to all IPv4/IPv6 addresses */
-static int NoFork = 0; /* don't fork - don't run in daemon mode - read-only after startup */
+static int doFork = 1; /* fork - run in daemon mode - read-only after startup */
int bHaveMainQueue = 0;/* set to 1 if the main queue - in queueing mode - is available
* If the main queue is either not yet ready or not running in
* queueing mode (mode DIRECT!), then this is set to 0.
@@ -473,7 +473,7 @@ logmsgInternal(int iErr, int pri, uchar *msg, int flags)
* permits us to process unmodified config files which otherwise contain a
* supressor statement.
*/
- if(((Debug == DEBUG_FULL || NoFork) && ourConf->globals.bErrMsgToStderr) || iConfigVerify) {
+ if(((Debug == DEBUG_FULL || !doFork) && ourConf->globals.bErrMsgToStderr) || iConfigVerify) {
if(LOG_PRI(pri) == LOG_ERR)
fprintf(stderr, "rsyslogd: %s\n", msg);
}
@@ -567,6 +567,7 @@ msgConsumer(void __attribute__((unused)) *notNeeded, batch_t *pBatch, int *pbShu
assert(pBatch != NULL);
pBatch->pbShutdownImmediate = pbShutdownImmediate; /* TODO: move this to batch creation! */
preprocessBatch(pBatch);
+dbgprintf("DDDD: batches ShutdownImmediate is %p\n", pBatch->pbShutdownImmediate);
ruleset.ProcessBatch(pBatch);
//TODO: the BATCH_STATE_COMM must be set somewhere down the road, but we
//do not have this yet and so we emulate -- 2010-06-10
@@ -1528,6 +1529,13 @@ queryLocalHostname(void)
*/
glbl.SetLocalHostName(LocalHostName);
glbl.SetLocalDomain(LocalDomain);
+
+ if ( strlen((char*)LocalDomain) ) {
+ CHKmalloc(LocalFQDNName = (uchar*)malloc(strlen((char*)LocalDomain)+strlen((char*)LocalHostName)+1));
+ if ( sprintf((char*)LocalFQDNName,"%s.%s",(char*)LocalHostName,(char*)LocalDomain) )
+ glbl.SetLocalFQDNName(LocalFQDNName);
+ }
+
glbl.GenerateLocalHostNameProperty(); /* must be redone after conf processing, FQDN setting may have changed */
finalize_it:
RETiRet;
@@ -1614,8 +1622,7 @@ doGlblProcessInit(void)
thrdInit();
- if( !(Debug == DEBUG_FULL || NoFork) )
- {
+ if(doFork) {
DBGPRINTF("Checking pidfile '%s'.\n", PidFile);
if (!check_pid(PidFile))
{
@@ -1627,16 +1634,23 @@ doGlblProcessInit(void)
/* stop writing debug messages to stdout (if debugging is on) */
stddbg = -1;
+ dbgprintf("ready for forking\n");
if (fork()) {
/* Parent process
*/
- sleep(300);
- /* Not reached unless something major went wrong. 5
- * minutes should be a fair amount of time to wait.
- * Please note that this procedure is important since
- * the father must not exit before syslogd isn't
- * initialized or the klogd won't be able to flush its
- * logs. -Joey
+ dbgprintf("parent process going to sleep for 60 secs\n");
+ sleep(60);
+ /* Not reached unless something major went wrong. 1
+ * minute should be a fair amount of time to wait.
+ * The parent should not exit before rsyslogd is
+ * properly initilized (at least almost) or the init
+ * system may get a wrong impression of our readyness.
+ * Note that we exit before being completely initialized,
+ * but at this point it is very, very unlikely that something
+ * bad can happen. We do this here, because otherwise we would
+ * need to have much more code to handle priv drop (which we
+ * don't consider worth for the init system, especially as it
+ * is going away on the majority of distros).
*/
exit(1); /* "good" exit - after forking, not diasabling anything */
}
@@ -1645,6 +1659,7 @@ doGlblProcessInit(void)
close(0);
/* we keep stdout and stderr open in case we have to emit something */
i = 3;
+ dbgprintf("in child, finalizing initialization\n");
/* if (sd_booted()) */ {
const char *e;
@@ -1678,7 +1693,8 @@ doGlblProcessInit(void)
i = SD_LISTEN_FDS_START + sd_fds;
}
for ( ; i < num_fds; i++)
- (void) close(i);
+ if(i != dbgGetDbglogFd())
+ close(i);
untty();
} else {
@@ -1889,7 +1905,7 @@ int realMain(int argc, char **argv)
fprintf(stderr, "rsyslogd: error -m is no longer supported - use immark instead");
break;
case 'n': /* don't fork */
- NoFork = 1;
+ doFork = 0;
break;
case 'N': /* enable config verify mode */
iConfigVerify = atoi(arg);
@@ -1993,17 +2009,16 @@ int realMain(int argc, char **argv)
if(!iConfigVerify)
CHKiRet(doGlblProcessInit());
+ /* Send a signal to the parent so it can terminate. */
+ if(glblGetOurPid() != ppid)
+ kill(ppid, SIGTERM);
+
CHKiRet(init());
if(Debug && debugging_on) {
dbgprintf("Debugging enabled, SIGUSR1 to turn off debugging.\n");
}
- /* Send a signal to the parent so it can terminate. */
- if(glblGetOurPid() != ppid)
- kill(ppid, SIGTERM);
-
-
/* END OF INTIALIZATION */
DBGPRINTF("initialization completed, transitioning to regular run mode\n");
@@ -2014,7 +2029,7 @@ int realMain(int argc, char **argv)
* is still in its infancy (and not really done), we currently accept this issue.
* rgerhards, 2009-06-29
*/
- if(!(Debug == DEBUG_FULL || NoFork)) {
+ if(doFork) {
close(1);
close(2);
ourConf->globals.bErrMsgToStderr = 0;