From 02a67ef273d508863b9b8bc3f0b2c7def2e92664 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Wed, 6 Nov 2019 12:08:09 +0100 Subject: [PATCH] Refactor, move daemon defines to header file Signed-off-by: Joachim Nilsson --- src/syslogd.c | 90 ----------------------------------------------- src/syslogd.h | 97 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 94 insertions(+), 93 deletions(-) diff --git a/src/syslogd.c b/src/syslogd.c index f59ceec..35f78a5 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -99,56 +99,6 @@ static char sccsid[] __attribute__((unused)) = #include "syslogd.h" #include "compat.h" -/* - * Linux uses EIO instead of EBADFD (mrn 12 May 96) - */ -#ifdef linux -#define EHANGUP EIO -#else -#define EHANGUP EBADFD -#endif - -#ifndef UTMP_FILE -#ifdef UTMP_FILENAME -#define UTMP_FILE UTMP_FILENAME -#else -#ifdef _PATH_UTMP -#define UTMP_FILE _PATH_UTMP -#else -#define UTMP_FILE "/etc/utmp" -#endif -#endif -#endif - -#ifndef _PATH_LOGCONF -#define _PATH_LOGCONF "/etc/syslog.conf" -#endif - -#if defined(SYSLOGD_PIDNAME) -#undef _PATH_LOGPID -#define _PATH_LOGPID _PATH_VARRUN SYSLOGD_PIDNAME -#else -#ifndef _PATH_LOGPID -#define _PATH_LOGPID _PATH_VARRUN "syslogd.pid" -#endif -#endif - -#ifndef _PATH_DEV -#define _PATH_DEV "/dev/" -#endif - -#ifndef _PATH_CONSOLE -#define _PATH_CONSOLE "/dev/console" -#endif - -#ifndef _PATH_TTY -#define _PATH_TTY "/dev/tty" -#endif - -#ifndef _PATH_LOG -#define _PATH_LOG "/dev/log" -#endif - char *ConfFile = _PATH_LOGCONF; char *PidFile = _PATH_LOGPID; char ctty[] = _PATH_CONSOLE; @@ -166,52 +116,12 @@ int funix[MAXFUNIX] = { -1, }; -/* - * Flags to logmsg(). - */ - -#define IGN_CONS 0x001 /* don't print on console */ -#define SYNC_FILE 0x002 /* do fsync on file after printing */ -#define ADDDATE 0x004 /* add a date to the message */ -#define MARK 0x008 /* this message is a mark */ -#define RFC5424 0x010 /* format log message according to RFC 5424 */ - /* * Intervals at which we flush out "message repeated" messages, * in seconds after previous message is logged. After each flush, * we move to the next interval until we reach the largest. */ static int repeatinterval[] = { 30, 120, 600 }; /* # of secs before flush */ -#define MAXREPEAT ((sizeof(repeatinterval) / sizeof(repeatinterval[0])) - 1) -#define REPEATTIME(f) ((f)->f_time + repeatinterval[(f)->f_repeatcount]) -#define BACKOFF(f) \ - { \ - if (++(f)->f_repeatcount > MAXREPEAT) \ - (f)->f_repeatcount = MAXREPEAT; \ - } -#ifndef INET_SUSPEND_TIME -#define INET_SUSPEND_TIME 180 /* equal to 3 minutes */ -#endif -#define INET_RETRY_MAX 10 /* maximum of retries for getaddrinfo() */ - -#define LIST_DELIMITER ':' /* delimiter between two hosts */ - -/* values for f_type */ -#define F_UNUSED 0 /* unused entry */ -#define F_FILE 1 /* regular file */ -#define F_TTY 2 /* terminal */ -#define F_CONSOLE 3 /* console terminal */ -#define F_FORW 4 /* remote machine */ -#define F_USERS 5 /* list of users */ -#define F_WALL 6 /* everyone logged on */ -#define F_FORW_SUSP 7 /* suspended host forwarding */ -#define F_FORW_UNKN 8 /* unknown host forwarding */ -#define F_PIPE 9 /* named pipe */ -char *TypeNames[] = { - "UNUSED", "FILE", "TTY", "CONSOLE", - "FORW", "USERS", "WALL", "FORW(SUSPENDED)", - "FORW(UNKNOWN)", "PIPE" -}; static SIMPLEQ_HEAD(files, filed) fhead = SIMPLEQ_HEAD_INITIALIZER(fhead); struct filed consfile; diff --git a/src/syslogd.h b/src/syslogd.h index 909027f..5f179bc 100644 --- a/src/syslogd.h +++ b/src/syslogd.h @@ -35,6 +35,56 @@ #include "queue.h" #include "syslog.h" +/* + * Linux uses EIO instead of EBADFD (mrn 12 May 96) + */ +#ifdef linux +#define EHANGUP EIO +#else +#define EHANGUP EBADFD +#endif + +#ifndef UTMP_FILE +#ifdef UTMP_FILENAME +#define UTMP_FILE UTMP_FILENAME +#else +#ifdef _PATH_UTMP +#define UTMP_FILE _PATH_UTMP +#else +#define UTMP_FILE "/etc/utmp" +#endif +#endif +#endif + +#ifndef _PATH_LOGCONF +#define _PATH_LOGCONF "/etc/syslog.conf" +#endif + +#if defined(SYSLOGD_PIDNAME) +#undef _PATH_LOGPID +#define _PATH_LOGPID _PATH_VARRUN SYSLOGD_PIDNAME +#else +#ifndef _PATH_LOGPID +#define _PATH_LOGPID _PATH_VARRUN "syslogd.pid" +#endif +#endif + +#ifndef _PATH_DEV +#define _PATH_DEV "/dev/" +#endif + +#ifndef _PATH_CONSOLE +#define _PATH_CONSOLE "/dev/console" +#endif + +#ifndef _PATH_TTY +#define _PATH_TTY "/dev/tty" +#endif + +#ifndef _PATH_LOG +#define _PATH_LOG "/dev/log" +#endif + #ifdef UT_NAMESIZE #define UNAMESZ UT_NAMESIZE /* length of a login name */ #else @@ -43,15 +93,56 @@ #define MAXUNAMES 20 /* maximum number of user names */ #define MAXFNAME 200 /* max file pathname length */ -/* Traditional syslog timestamp format. */ -#define RFC3164_DATELEN 15 -#define RFC3164_DATEFMT "%b %e %H:%M:%S" +#ifndef INET_SUSPEND_TIME +#define INET_SUSPEND_TIME 180 /* equal to 3 minutes */ +#endif +#define INET_RETRY_MAX 10 /* maximum of retries for getaddrinfo() */ + +#define LIST_DELIMITER ':' /* delimiter between two hosts */ /* From The Practice of Programming, by Kernighan and Pike */ #ifndef NELEMS #define NELEMS(array) (sizeof(array) / sizeof(array[0])) #endif +/* + * Flags to logmsg(). + */ +#define IGN_CONS 0x001 /* don't print on console */ +#define SYNC_FILE 0x002 /* do fsync on file after printing */ +#define ADDDATE 0x004 /* add a date to the message */ +#define MARK 0x008 /* this message is a mark */ +#define RFC5424 0x010 /* format log message according to RFC 5424 */ + +#define RFC3164_DATELEN 15 +#define RFC3164_DATEFMT "%b %e %H:%M:%S" + +/* + * Helper macros for "message repeated" messages + */ +#define MAXREPEAT ((sizeof(repeatinterval) / sizeof(repeatinterval[0])) - 1) +#define REPEATTIME(f) ((f)->f_time + repeatinterval[(f)->f_repeatcount]) +#define BACKOFF(f) \ + if (++(f)->f_repeatcount > MAXREPEAT) \ + (f)->f_repeatcount = MAXREPEAT; + +/* values for f_type */ +#define F_UNUSED 0 /* unused entry */ +#define F_FILE 1 /* regular file */ +#define F_TTY 2 /* terminal */ +#define F_CONSOLE 3 /* console terminal */ +#define F_FORW 4 /* remote machine */ +#define F_USERS 5 /* list of users */ +#define F_WALL 6 /* everyone logged on */ +#define F_FORW_SUSP 7 /* suspended host forwarding */ +#define F_FORW_UNKN 8 /* unknown host forwarding */ +#define F_PIPE 9 /* named pipe */ +char *TypeNames[] = { + "UNUSED", "FILE", "TTY", "CONSOLE", + "FORW", "USERS", "WALL", "FORW(SUSPENDED)", + "FORW(UNKNOWN)", "PIPE" +}; + /* Timestamps of log entries. */ struct logtime { struct tm tm;