Simplify, remove #ifdefs for always defined paths

We always want to build with support for UNIX domain socket and remote
syslog (both receive and send).  We can safely state that all systems
we aim to target supports FHS.

Also, start clean up gratuitous use of SYSV #ifdefs.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-10-23 10:37:14 +02:00
parent b3727fcf0b
commit f67ed6934a
5 changed files with 16 additions and 119 deletions

View File

@ -7,24 +7,13 @@
Compilation has been tested with versions 2.5.8, 2.6.3 and 2.7.0 of Compilation has been tested with versions 2.5.8, 2.6.3 and 2.7.0 of
the gcc compiler and libc versions 4.5.26 and 4.6.27. the gcc compiler and libc versions 4.5.26 and 4.6.27.
3.) The FSSTND makes suggestions as to appropriate locations for 3.) For proper functioning both of these utilities are best run as root.
system binaries. Since not everyone agrees with standards it is
up to the system administrator installing the utilities to choose
the most appropriate locations for the binaries and their
configuration files. By default the package will compile and
install following the FSSTND recommendations. If a decision is
made to change this behavior consult the makefile and the sources.
The FSSTND define controls selection of values which may be
influenced by the choice of conformance with the FSSTND or site
preferences.
4.) For proper functioning both of these utilities are best run as root.
This is probably not much of a problem since they will probably be This is probably not much of a problem since they will probably be
started either by init or as part of the rc.* startup process. There started either by init or as part of the rc.* startup process. There
may be security concerns with running syslogd as root. Please repeat may be security concerns with running syslogd as root. Please repeat
step 1 if you are unsure of why this may be the case. step 1 if you are unsure of why this may be the case.
5.) If kernel address to symbol translation is desired there is the 4.) If kernel address to symbol translation is desired there is the
possibility that a new kernel will need to be compiled. The patches possibility that a new kernel will need to be compiled. The patches
to delimit kernel addresses requiring translation were added to to delimit kernel addresses requiring translation were added to
kernel 1.3.43. If this kernel or a newer kernel is used there is kernel 1.3.43. If this kernel or a newer kernel is used there is

View File

@ -25,19 +25,17 @@ AM_CFLAGS += -Wno-unused-result -Wno-unused-parameter
AM_CFLAGS += -fomit-frame-pointer -fno-strength-reduce AM_CFLAGS += -fomit-frame-pointer -fno-strength-reduce
syslogd_SOURCES = syslogd.c pidfile.c pidfile.h syslogd_SOURCES = syslogd.c pidfile.c pidfile.h
syslogd_CPPFLAGS = -DSYSV -DFSSTND -DSYSLOG_INET -DINET6 -DNO_SCCS -DSYSLOG_UNIXAF \ syslogd_CPPFLAGS = -DSYSV -DINET6 -D_BSD_SOURCE -D_SVID_SOURCE -D_DEFAULT_SOURCE
-D_BSD_SOURCE -D_SVID_SOURCE -D_DEFAULT_SOURCE
klogd_SOURCES = klogd.c klogd.h syslog.c pidfile.c pidfile.h \ klogd_SOURCES = klogd.c klogd.h syslog.c pidfile.c pidfile.h \
ksym.c ksyms.h ksym_mod.c module.h ksym.c ksyms.h ksym_mod.c module.h
klogd_CPPFLAGS = -DSYSV -DFSSTND -DALLOW_KERNEL_LOGGING \ klogd_CPPFLAGS = -DSYSV -DALLOW_KERNEL_LOGGING \
-D_BSD_SOURCE -D_SVID_SOURCE -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_DEFAULT_SOURCE
logger_SOURCES = logger.c syslog.c logger_SOURCES = logger.c syslog.c
logger_CPPFLAGS = -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE logger_CPPFLAGS = -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE
tsyslogd_SOURCES = syslogd.c pidfile.c pidfile.h tsyslogd_SOURCES = syslogd.c pidfile.c pidfile.h
tsyslogd_CPPFLAGS = -DSYSV -DFSSTND -DSYSLOG_INET -DINET6 -DNO_SCCS -DSYSLOG_UNIXAF \ tsyslogd_CPPFLAGS = -DSYSV -DINET6 -D_BSD_SOURCE -D_SVID_SOURCE -D_DEFAULT_SOURCE -DTESTING
-D_BSD_SOURCE -D_SVID_SOURCE -D_DEFAULT_SOURCE -DTESTING
syslog_tst_SOURCES = syslog_tst.c syslog_tst_SOURCES = syslog_tst.c

View File

@ -49,10 +49,6 @@ MANDIR = $(prefix)/usr/share/man
# useful if klogd is started simultaneously or in close-proximity to syslogd. # useful if klogd is started simultaneously or in close-proximity to syslogd.
# KLOGD_START_DELAY = -DKLOGD_DELAY=5 # KLOGD_START_DELAY = -DKLOGD_DELAY=5
# The following define determines whether the package adheres to the
# file system standard.
FSSTND = -DFSSTND
# The following define establishes ownership for the man pages. # The following define establishes ownership for the man pages.
# Avery tells me that there is a difference between Debian and # Avery tells me that there is a difference between Debian and
# Slackware. Rather than choose sides I am leaving it up to the user. # Slackware. Rather than choose sides I am leaving it up to the user.
@ -67,10 +63,9 @@ MAN_PERMS = 644
# ballot below. # ballot below.
SYSLOGD_PIDNAME = -DSYSLOGD_PIDNAME=\"syslogd.pid\" SYSLOGD_PIDNAME = -DSYSLOGD_PIDNAME=\"syslogd.pid\"
SYSLOGD_FLAGS= -DSYSLOG_INET -DSYSLOG_UNIXAF -DINET6 -DNO_SCCS ${FSSTND} \ SYSLOGD_FLAGS= -DINET6 ${SYSLOGD_PIDNAME}
${SYSLOGD_PIDNAME}
SYSLOG_FLAGS= -DALLOW_KERNEL_LOGGING SYSLOG_FLAGS= -DALLOW_KERNEL_LOGGING
KLOGD_FLAGS = ${FSSTND} ${KLOGD_START_DELAY} KLOGD_FLAGS = ${KLOGD_START_DELAY}
DEB = DEB =
all: syslogd klogd all: syslogd klogd

View File

@ -284,11 +284,7 @@
#define LOG_LINE_LENGTH 1000 #define LOG_LINE_LENGTH 1000
#ifndef TESTING #ifndef TESTING
#if defined(FSSTND)
static char *PidFile = _PATH_VARRUN "klogd.pid"; static char *PidFile = _PATH_VARRUN "klogd.pid";
#else
static char *PidFile = "/etc/klogd.pid";
#endif
#endif #endif
static int kmsg; static int kmsg;

View File

@ -570,10 +570,7 @@ static char sccsid[] __attribute__((unused)) =
#include "pidfile.h" #include "pidfile.h"
#endif #endif
#include "config.h" #include "config.h"
#if defined(__linux__)
#include <paths.h> #include <paths.h>
#endif
#ifndef UTMP_FILE #ifndef UTMP_FILE
#ifdef UTMP_FILENAME #ifdef UTMP_FILENAME
@ -593,18 +590,10 @@ static char sccsid[] __attribute__((unused)) =
#if defined(SYSLOGD_PIDNAME) #if defined(SYSLOGD_PIDNAME)
#undef _PATH_LOGPID #undef _PATH_LOGPID
#if defined(FSSTND)
#define _PATH_LOGPID _PATH_VARRUN SYSLOGD_PIDNAME #define _PATH_LOGPID _PATH_VARRUN SYSLOGD_PIDNAME
#else #else
#define _PATH_LOGPID "/etc/" SYSLOGD_PIDNAME
#endif
#else
#ifndef _PATH_LOGPID #ifndef _PATH_LOGPID
#if defined(FSSTND)
#define _PATH_LOGPID _PATH_VARRUN "syslogd.pid" #define _PATH_LOGPID _PATH_VARRUN "syslogd.pid"
#else
#define _PATH_LOGPID "/etc/syslogd.pid"
#endif
#endif #endif
#endif #endif
@ -734,12 +723,10 @@ int repeatinterval[] = { 30, 60 }; /* # of secs before flush */
if (++(f)->f_repeatcount > MAXREPEAT) \ if (++(f)->f_repeatcount > MAXREPEAT) \
(f)->f_repeatcount = MAXREPEAT; \ (f)->f_repeatcount = MAXREPEAT; \
} }
#ifdef SYSLOG_INET
#ifndef INET_SUSPEND_TIME #ifndef INET_SUSPEND_TIME
#define INET_SUSPEND_TIME 180 /* equal to 3 minutes */ #define INET_SUSPEND_TIME 180 /* equal to 3 minutes */
#endif #endif
#define INET_RETRY_MAX 10 /* maximum of retries for getaddrinfo() */ #define INET_RETRY_MAX 10 /* maximum of retries for getaddrinfo() */
#endif
#define LIST_DELIMITER ':' /* delimiter between two hosts */ #define LIST_DELIMITER ':' /* delimiter between two hosts */
@ -868,13 +855,9 @@ int decode(char *name, struct code *codetab);
static void logit(char *, ...); static void logit(char *, ...);
static void allocate_log(void); static void allocate_log(void);
void sighup_handler(int); void sighup_handler(int);
static int create_unix_socket(const char *path);
#ifdef SYSLOG_UNIXAF
static int create_unix_socket(const char *path);
#endif
#ifdef SYSLOG_INET
static int *create_inet_sockets(); static int *create_inet_sockets();
#endif
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -907,9 +890,7 @@ int main(int argc, char *argv[])
#ifndef TESTING #ifndef TESTING
int fd; int fd;
#ifdef SYSLOG_INET
struct sockaddr_storage frominet; struct sockaddr_storage frominet;
#endif
pid_t ppid = getpid(); pid_t ppid = getpid();
#endif #endif
int ch; int ch;
@ -1052,11 +1033,10 @@ int main(int argc, char *argv[])
} }
} else } else
#endif #endif
{
debugging_on = 1; debugging_on = 1;
#ifndef SYSV
else
setlinebuf(stdout); setlinebuf(stdout);
#endif }
#ifndef TESTING #ifndef TESTING
/* tuck my process id away */ /* tuck my process id away */
@ -1131,7 +1111,7 @@ int main(int argc, char *argv[])
errno = 0; errno = 0;
FD_ZERO(&readfds); FD_ZERO(&readfds);
maxfds = 0; maxfds = 0;
#ifdef SYSLOG_UNIXAF
#ifndef TESTING #ifndef TESTING
/* /*
* Add the Unix Domain Sockets to the list of read * Add the Unix Domain Sockets to the list of read
@ -1146,8 +1126,7 @@ int main(int argc, char *argv[])
} }
} }
#endif #endif
#endif
#ifdef SYSLOG_INET
#ifndef TESTING #ifndef TESTING
/* /*
* Add the Internet Domain Socket to the list of read * Add the Internet Domain Socket to the list of read
@ -1163,7 +1142,6 @@ int main(int argc, char *argv[])
logit("Listening on syslog UDP port.\n"); logit("Listening on syslog UDP port.\n");
} }
#endif #endif
#endif
#ifdef TESTING #ifdef TESTING
FD_SET(fileno(stdin), &readfds); FD_SET(fileno(stdin), &readfds);
if (fileno(stdin) > maxfds) if (fileno(stdin) > maxfds)
@ -1218,7 +1196,6 @@ int main(int argc, char *argv[])
} }
#ifndef TESTING #ifndef TESTING
#ifdef SYSLOG_UNIXAF
for (i = 0; i < nfunix; i++) { for (i = 0; i < nfunix; i++) {
if ((fd = funix[i]) != -1 && FD_ISSET(fd, &readfds)) { if ((fd = funix[i]) != -1 && FD_ISSET(fd, &readfds)) {
memset(line, 0, sizeof(line)); memset(line, 0, sizeof(line));
@ -1233,9 +1210,7 @@ int main(int argc, char *argv[])
} }
} }
} }
#endif
#ifdef SYSLOG_INET
if (InetInuse && AcceptRemote && finet) { if (InetInuse && AcceptRemote && finet) {
for (i = 0; i < *finet; i++) { for (i = 0; i < *finet; i++) {
if (finet[i + 1] != -1 && FD_ISSET(finet[i + 1], &readfds)) { if (finet[i + 1] != -1 && FD_ISSET(finet[i + 1], &readfds)) {
@ -1266,7 +1241,6 @@ int main(int argc, char *argv[])
} }
} }
} }
#endif
#else #else
if (FD_ISSET(fileno(stdin), &readfds)) { if (FD_ISSET(fileno(stdin), &readfds)) {
logit("Message from stdin.\n"); logit("Message from stdin.\n");
@ -1337,7 +1311,6 @@ static void increase_rcvbuf(int fd)
} }
} }
#ifdef SYSLOG_UNIXAF
static int create_unix_socket(const char *path) static int create_unix_socket(const char *path)
{ {
struct sockaddr_un sunx; struct sockaddr_un sunx;
@ -1359,9 +1332,6 @@ static int create_unix_socket(const char *path)
logerror(line); logerror(line);
logit("cannot create %s (%d).\n", path, errno); logit("cannot create %s (%d).\n", path, errno);
close(fd); close(fd);
#ifndef SYSV
die(0);
#endif
return -1; return -1;
} }
@ -1369,9 +1339,7 @@ static int create_unix_socket(const char *path)
return fd; return fd;
} }
#endif
#ifdef SYSLOG_INET
static int *create_inet_sockets(void) static int *create_inet_sockets(void)
{ {
struct addrinfo hints, *res, *r; struct addrinfo hints, *res, *r;
@ -1459,7 +1427,6 @@ static int *create_inet_sockets(void)
} }
return socks; return socks;
} }
#endif
char **crunch_list(list) char *list; char **crunch_list(list) char *list;
{ {
@ -1519,26 +1486,11 @@ char **crunch_list(list) char *list;
} }
void untty(void) void untty(void)
#ifdef SYSV
{ {
if (!Debug) { if (!Debug) {
setsid(); setsid();
} }
return;
} }
#else
{
int i;
if (!Debug) {
i = open(_PATH_TTY, O_RDWR);
if (i >= 0) {
(void)ioctl(i, (int)TIOCNOTTY, NULL);
(void)close(i);
}
}
}
#endif
/* /*
* Parse the line to make sure that the msg is not a composite of more * Parse the line to make sure that the msg is not a composite of more
@ -1717,28 +1669,16 @@ time_t now;
void logmsg(int pri, char *msg, const char *from, int flags) void logmsg(int pri, char *msg, const char *from, int flags)
{ {
struct filed *f; struct filed *f;
#ifdef __gnu_linux__
sigset_t mask; sigset_t mask;
#else
#ifndef SYSV
sigset_t omask;
#endif
#endif
char *timestamp; char *timestamp;
int fac, prilev, lognum, msglen; int fac, prilev, lognum, msglen;
logit("logmsg: %s, flags %x, from %s, msg %s\n", textpri(pri), flags, from, msg); logit("logmsg: %s, flags %x, from %s, msg %s\n", textpri(pri), flags, from, msg);
#ifdef __gnu_linux__
sigemptyset(&mask); sigemptyset(&mask);
sigaddset(&mask, SIGHUP); sigaddset(&mask, SIGHUP);
sigaddset(&mask, SIGALRM); sigaddset(&mask, SIGALRM);
sigprocmask(SIG_BLOCK, &mask, NULL); sigprocmask(SIG_BLOCK, &mask, NULL);
#else
#ifndef SYSV
omask = sigblock(sigmask(SIGHUP) | sigmask(SIGALRM));
#endif
#endif
/* /*
* Check to see if msg looks non-standard. * Check to see if msg looks non-standard.
@ -1776,15 +1716,11 @@ void logmsg(int pri, char *msg, const char *from, int flags)
(void)close(f->f_file); (void)close(f->f_file);
f->f_file = -1; f->f_file = -1;
} }
#ifdef __gnu_linux__
sigprocmask(SIG_UNBLOCK, &mask, NULL); sigprocmask(SIG_UNBLOCK, &mask, NULL);
#else
#ifndef SYSV
(void)sigsetmask(omask);
#endif
#endif
return; return;
} }
#ifdef SYSV #ifdef SYSV
for (lognum = 0; lognum <= nlogs; lognum++) { for (lognum = 0; lognum <= nlogs; lognum++) {
f = &Files[lognum]; f = &Files[lognum];
@ -1867,13 +1803,8 @@ void logmsg(int pri, char *msg, const char *from, int flags)
} }
} }
} }
#ifdef __gnu_linux__
sigprocmask(SIG_UNBLOCK, &mask, NULL); sigprocmask(SIG_UNBLOCK, &mask, NULL);
#else
#ifndef SYSV
(void)sigsetmask(omask);
#endif
#endif
} }
#if FALSE #if FALSE
} /* balance parentheses for emacs */ } /* balance parentheses for emacs */
@ -2041,12 +1972,10 @@ void fprintlog(struct filed *f, char *from, int flags, char *msg)
struct iovec iov[6]; struct iovec iov[6];
struct iovec *v = iov; struct iovec *v = iov;
char repbuf[80]; char repbuf[80];
#ifdef SYSLOG_INET
struct addrinfo hints, *ai; struct addrinfo hints, *ai;
time_t fwd_suspend; time_t fwd_suspend;
char line[MAXLINE + 1]; char line[MAXLINE + 1];
int l, err; int l, err;
#endif
logit("Called fprintlog, "); logit("Called fprintlog, ");
@ -2084,7 +2013,6 @@ void fprintlog(struct filed *f, char *from, int flags, char *msg)
logit("\n"); logit("\n");
break; break;
#ifdef SYSLOG_INET
case F_FORW_SUSP: case F_FORW_SUSP:
fwd_suspend = time(NULL) - f->f_time; fwd_suspend = time(NULL) - f->f_time;
if (fwd_suspend >= INET_SUSPEND_TIME) { if (fwd_suspend >= INET_SUSPEND_TIME) {
@ -2183,7 +2111,6 @@ void fprintlog(struct filed *f, char *from, int flags, char *msg)
} }
} }
break; break;
#endif
case F_CONSOLE: case F_CONSOLE:
f->f_time = now; f->f_time = now;
@ -2787,7 +2714,6 @@ void init(void)
/* close the configuration file */ /* close the configuration file */
(void)fclose(cf); (void)fclose(cf);
#ifdef SYSLOG_UNIXAF
for (i = 0; i < nfunix; i++) { for (i = 0; i < nfunix; i++) {
if (funix[i] != -1) if (funix[i] != -1)
/* Don't close the socket, preserve it instead /* Don't close the socket, preserve it instead
@ -2797,9 +2723,7 @@ void init(void)
if ((funix[i] = create_unix_socket(funixn[i])) != -1) if ((funix[i] = create_unix_socket(funixn[i])) != -1)
logit("Opened UNIX socket `%s'.\n", funixn[i]); logit("Opened UNIX socket `%s'.\n", funixn[i]);
} }
#endif
#ifdef SYSLOG_INET
if (Forwarding || AcceptRemote) { if (Forwarding || AcceptRemote) {
if (!finet) { if (!finet) {
finet = create_inet_sockets(); finet = create_inet_sockets();
@ -2818,7 +2742,6 @@ void init(void)
} }
InetInuse = 0; InetInuse = 0;
} }
#endif
Initialized = 1; Initialized = 1;
@ -2913,9 +2836,7 @@ static int strtobytes(char *arg)
*/ */
void cfline(char *line, struct filed *f) void cfline(char *line, struct filed *f)
{ {
#ifdef SYSLOG_INET
struct addrinfo hints, *ai; struct addrinfo hints, *ai;
#endif
char buf[MAXLINE]; char buf[MAXLINE];
char xbuf[MAXLINE + 24]; char xbuf[MAXLINE + 24];
char *p, *q, *bp; char *p, *q, *bp;
@ -3067,7 +2988,6 @@ void cfline(char *line, struct filed *f)
logit("leading char in action: %c\n", *p); logit("leading char in action: %c\n", *p);
switch (*p) { switch (*p) {
case '@': case '@':
#ifdef SYSLOG_INET
bp = p; bp = p;
while ((q = strchr(bp, ';'))) { while ((q = strchr(bp, ';'))) {
*q++ = 0; *q++ = 0;
@ -3098,7 +3018,6 @@ void cfline(char *line, struct filed *f)
f->f_type = F_FORW; f->f_type = F_FORW;
f->f_un.f_forw.f_addr = ai; f->f_un.f_forw.f_addr = ai;
} }
#endif
break; break;
case '|': case '|':