summaryrefslogtreecommitdiffstats
path: root/tools/syslogd.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/syslogd.c')
-rw-r--r--tools/syslogd.c122
1 files changed, 76 insertions, 46 deletions
diff --git a/tools/syslogd.c b/tools/syslogd.c
index 1148108c..c9734d14 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -135,6 +135,7 @@
#include "net.h"
#include "vm.h"
#include "prop.h"
+#include "sd-daemon.h"
/* definitions for objects we access */
DEFobjCurrIf(obj)
@@ -392,7 +393,7 @@ static char **crunch_list(char *list)
char **result = NULL;
p = list;
-
+
/* strip off trailing delimiters */
while (p[strlen(p)-1] == LIST_DELIMITER) {
count--;
@@ -401,18 +402,18 @@ static char **crunch_list(char *list)
/* cut off leading delimiters */
while (p[0] == LIST_DELIMITER) {
count--;
- p++;
+ p++;
}
-
+
/* count delimiters to calculate elements */
for (count=i=0; p[i]; i++)
if (p[i] == LIST_DELIMITER) count++;
-
+
if ((result = (char **)MALLOC(sizeof(char *) * (count+2))) == NULL) {
printf ("Sorry, can't get enough memory, exiting.\n");
exit(0); /* safe exit, because only called during startup */
}
-
+
/*
* We now can assume that the first and last
* characters are different from any delimiters,
@@ -573,9 +574,9 @@ logmsgInternal(int iErr, int pri, uchar *msg, int flags)
}
if(bHaveMainQueue == 0) { /* not yet in queued mode */
- iminternalAddMsg(pri, pMsg);
+ iminternalAddMsg(pMsg);
} else {
- /* we have the queue, so we can simply provide the
+ /* we have the queue, so we can simply provide the
* message to the queue engine.
*/
submitMsg(pMsg);
@@ -698,7 +699,6 @@ msgConsumer(void __attribute__((unused)) *notNeeded, batch_t *pBatch, int *pbShu
assert(pBatch != NULL);
pBatch->pbShutdownImmediate = pbShutdownImmediate; /* TODO: move this to batch creation! */
preprocessBatch(pBatch);
-//pBatch->bSingleRuleset = 0; // TODO: testing aid, remove!!!!
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
@@ -722,7 +722,7 @@ submitMsg(msg_t *pMsg)
DEFiRet;
ISOBJ_TYPE_assert(pMsg, msg);
-
+
pRuleset = MsgGetRuleset(pMsg);
pQueue = (pRuleset == NULL) ? pMsgQueue : ruleset.GetRulesetQueue(pRuleset);
@@ -788,7 +788,7 @@ DEFFUNC_llExecFunc(flushRptdMsgsActions)
{
action_t *pAction = (action_t*) pData;
assert(pAction != NULL);
-
+
BEGINfunc
LockObj(pAction);
/* TODO: time() performance: the call below could be moved to
@@ -843,7 +843,7 @@ static void debug_switch()
dbgprintf("\n");
debugging_on = 0;
}
-
+
memset(&sigAct, 0, sizeof (sigAct));
sigemptyset(&sigAct.sa_mask);
sigAct.sa_handler = debug_switch;
@@ -1031,7 +1031,7 @@ destructAllActions(void)
/* die() is called when the program shall end. This typically only occurs
- * during sigterm or during the initialization.
+ * during sigterm or during the initialization.
* As die() is intended to shutdown rsyslogd, it is
* safe to call exit() here. Just make sure that die() itself is not called
* at inapropriate places. As a general rule of thumb, it is a bad idea to add
@@ -1071,7 +1071,7 @@ die(int sig)
errno = 0;
logmsgInternal(NO_ERRCODE, LOG_SYSLOG|LOG_INFO, (uchar*)buf, 0);
}
-
+
/* drain queue (if configured so) and stop main queue worker thread pool */
DBGPRINTF("Terminating main queue...\n");
qqueueDestruct(&pMsgQueue);
@@ -1195,7 +1195,7 @@ static rsRetVal setUmask(void __attribute__((unused)) *pVal, int iUmask)
}
-/* drop to specified group
+/* drop to specified group
* if something goes wrong, the function never returns
* Note that such an abort can cause damage to on-disk structures, so we should
* re-design the "interface" in the long term. -- rgerhards, 2008-11-26
@@ -1223,7 +1223,7 @@ static void doDropPrivGid(int iGid)
}
-/* drop to specified user
+/* drop to specified user
* if something goes wrong, the function never returns
* Note that such an abort can cause damage to on-disk structures, so we should
* re-design the "interface" in the long term. -- rgerhards, 2008-11-19
@@ -1464,7 +1464,7 @@ static void dbgPrintInitInfo(void)
/* TODO: add
iActionRetryCount = 0;
iActionRetryInterval = 30000;
- static int iMainMsgQtoWrkMinMsgs = 100;
+ static int iMainMsgQtoWrkMinMsgs = 100;
static int iMainMsgQbSaveOnShutdown = 1;
iMainMsgQueMaxDiskSpace = 0;
setQPROP(qqueueSetiMinMsgsPerWrkr, "$MainMsgQueueWorkerThreadMinimumMessages", 100);
@@ -1736,7 +1736,7 @@ init(void)
* identify this instance. -- rgerhards, 2005-08-17
*/
if(bLogStatusMsgs) {
- snprintf(bufStartUpMsg, sizeof(bufStartUpMsg)/sizeof(char),
+ snprintf(bufStartUpMsg, sizeof(bufStartUpMsg)/sizeof(char),
" [origin software=\"rsyslogd\" " "swVersion=\"" VERSION \
"\" x-pid=\"%d\" x-info=\"http://www.rsyslog.com\"] start",
(int) myPid);
@@ -1766,7 +1766,7 @@ finalize_it:
-/* Put the rsyslog main thread to sleep for n seconds. This was introduced as
+/* Put the rsyslog main thread to sleep for n seconds. This was introduced as
* a quick and dirty workaround for a privilege drop race in regard to listener
* startup, which itself was a result of the not-yet-done proper coding of
* privilege drop code (quite some effort). It may be useful for other occasions, too.
@@ -1851,7 +1851,7 @@ static rsRetVal setMainMsgQueType(void __attribute__((unused)) *pVal, uchar *psz
void sighup_handler()
{
struct sigaction sigAct;
-
+
bHadHUP = 1;
memset(&sigAct, 0, sizeof (sigAct));
@@ -1872,10 +1872,9 @@ void sigttin_handler()
*/
static inline void processImInternal(void)
{
- int iPri;
msg_t *pMsg;
- while(iminternalRemoveMsg(&iPri, &pMsg) == RS_RET_OK) {
+ while(iminternalRemoveMsg(&pMsg) == RS_RET_OK) {
submitMsg(pMsg);
}
}
@@ -2115,11 +2114,6 @@ static void printVersion(void)
#else
printf("\tFEATURE_LARGEFILE:\t\t\tNo\n");
#endif
-#ifdef USE_NETZIP
- printf("\tFEATURE_NETZIP (message compression):\tYes\n");
-#else
- printf("\tFEATURE_NETZIP (message compression):\tNo\n");
-#endif
#if defined(SYSLOG_INET) && defined(USE_GSSAPI)
printf("\tGSSAPI Kerberos 5 support:\t\tYes\n");
#else
@@ -2131,9 +2125,14 @@ static void printVersion(void)
printf("\tFEATURE_DEBUG (debug build, slow code):\tNo\n");
#endif
#ifdef HAVE_ATOMIC_BUILTINS
- printf("\tAtomic operations supported:\t\tYes\n");
+ printf("\t32bit Atomic operations supported:\tYes\n");
#else
- printf("\tAtomic operations supported:\t\tNo\n");
+ printf("\t32bit Atomic operations supported:\tNo\n");
+#endif
+#ifdef HAVE_ATOMIC_BUILTINS64
+ printf("\t64bit Atomic operations supported:\tYes\n");
+#else
+ printf("\t64bit Atomic operations supported:\tNo\n");
#endif
#ifdef RTINST
printf("\tRuntime Instrumentation (slow code):\tYes\n");
@@ -2433,16 +2432,50 @@ doGlblProcessInit(void)
*/
exit(1); /* "good" exit - after forking, not diasabling anything */
}
+
num_fds = getdtablesize();
close(0);
/* we keep stdout and stderr open in case we have to emit something */
- for (i = 3; i < num_fds; i++)
+ i = 3;
+
+ /* if (sd_booted()) */ {
+ const char *e;
+ char buf[24] = { '\0' };
+ char *p = NULL;
+ unsigned long l;
+ int sd_fds;
+
+ /* fork & systemd socket activation:
+ * fetch listen pid and update to ours,
+ * when it is set to pid of our parent.
+ */
+ if ( (e = getenv("LISTEN_PID"))) {
+ errno = 0;
+ l = strtoul(e, &p, 10);
+ if (errno == 0 && l > 0 && (!p || !*p)) {
+ if (getppid() == (pid_t)l) {
+ snprintf(buf, sizeof(buf), "%d",
+ getpid());
+ setenv("LISTEN_PID", buf, 1);
+ }
+ }
+ }
+
+ /*
+ * close only all further fds, except
+ * of the fds provided by systemd.
+ */
+ sd_fds = sd_listen_fds(0);
+ if (sd_fds > 0)
+ i = SD_LISTEN_FDS_START + sd_fds;
+ }
+ for ( ; i < num_fds; i++)
(void) close(i);
+
untty();
- }
- else
- {
- fputs(" Already running.\n", stderr);
+ } else {
+ fputs(" Already running. If you want to run multiple instances, you need "
+ "to specify different pid files (use -i option)\n", stderr);
exit(1); /* "good" exit, done if syslogd is already running */
}
}
@@ -2494,7 +2527,7 @@ doGlblProcessInit(void)
* modularize it a bit more...
*/
int realMain(int argc, char **argv)
-{
+{
DEFiRet;
register uchar *p;
@@ -2524,7 +2557,7 @@ int realMain(int argc, char **argv)
* of other options, we do this during the inital option processing. With later
* versions (if a dependency on -c option is introduced), we must move that code
* to other places, but I think it is quite appropriate and saves code to do this
- * only when actually neeeded.
+ * only when actually neeeded.
* rgerhards, 2008-04-04
*/
while((ch = getopt(argc, argv, "46a:Ac:def:g:hi:l:m:M:nN:op:qQr::s:t:T:u:vwx")) != EOF) {
@@ -2589,7 +2622,7 @@ int realMain(int argc, char **argv)
case 'v': /* MUST be carried out immediately! */
printVersion();
exit(0); /* exit for -v option - so this is a "good one" */
- case '?':
+ case '?':
default:
usage();
}
@@ -2645,7 +2678,7 @@ int realMain(int argc, char **argv)
* Good software also always checks its return values...
* If syslogd starts up before DNS is up & /etc/hosts
* doesn't have LocalHostName listed, gethostbyname will
- * return NULL.
+ * return NULL.
*/
/* TODO: gethostbyname() is not thread-safe, but replacing it is
* not urgent as we do not run on multiple threads here. rgerhards, 2007-09-25
@@ -2654,7 +2687,7 @@ int realMain(int argc, char **argv)
if(hent) {
free(LocalHostName);
CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_name));
-
+
if((p = (uchar*)strchr((char*)LocalHostName, '.')))
{
*p++ = '\0';
@@ -2666,7 +2699,7 @@ int realMain(int argc, char **argv)
/* Convert to lower case to recognize the correct domain laterly */
for(p = LocalDomain ; *p ; p++)
*p = (char)tolower((int)*p);
-
+
/* we now have our hostname and can set it inside the global vars.
* TODO: think if all of this would better be a runtime function
* rgerhards, 2008-04-17
@@ -2822,7 +2855,7 @@ int realMain(int argc, char **argv)
case 'x': /* disable dns for remote messages */
glbl.SetDisableDNS(1);
break;
- case '?':
+ case '?':
default:
usage();
}
@@ -2846,7 +2879,7 @@ int realMain(int argc, char **argv)
if(iCompatibilityMode < 4) {
errmsg.LogError(0, NO_ERRCODE, "WARNING: rsyslogd is running in compatibility mode. Automatically "
"generated config directives may interfer with your rsyslog.conf settings. "
- "We suggest upgrading your config and adding -c4 as the first "
+ "We suggest upgrading your config and adding -c5 as the first "
"rsyslogd option.");
}
@@ -2871,15 +2904,12 @@ int realMain(int argc, char **argv)
if(!iConfigVerify)
CHKiRet(doGlblProcessInit());
- /* re-generate local host name property, as the config may have changed our FQDN settings */
- glbl.GenerateLocalHostNameProperty();
-
CHKiRet(mainThread());
/* do any de-init's that need to be done AFTER this comment */
die(bFinished);
-
+
thrdExit();
finalize_it:
@@ -2901,7 +2931,7 @@ finalize_it:
* rgerhards, 20080-01-28
*/
int main(int argc, char **argv)
-{
+{
dbgClassInit();
return realMain(argc, argv);
}