Remove old TESTING mode, incl. tsyslogd and syslog-tst

This special build option enabled reading syslog messages from stdin on
syslogd.  It also disabled all other standard features of syslogd, which
made it a bit too far from the real thing.

A better approac is to start syslogd with -p /tmp/foo and let a test
application, e.g. logger -u /tmp/foo, connect using the standard UNIX
domain socket API.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-10-29 10:39:56 +01:00
parent b6dcef71dd
commit 48a9f1fdd7
4 changed files with 13 additions and 128 deletions

View File

@ -19,7 +19,6 @@ AUTOMAKE_OPTIONS = subdir-objects
bin_PROGRAMS = logger
sbin_PROGRAMS = syslogd klogd
noinst_PROGRAMS = tsyslogd syslog_tst
AM_CFLAGS = -W -Wall -Wextra
AM_CFLAGS += -Wno-unused-result -Wno-unused-parameter
@ -38,10 +37,3 @@ logger_SOURCES = logger.c syslog.c
logger_CPPFLAGS = -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_DEFAULT_SOURCE
logger_LDADD = $(LIBS) $(LIBOBJS)
tsyslogd_SOURCES = $(syslogd_SOURCES)
tsyslogd_CPPFLAGS = $(syslogd_CPPFLAGS) -DTESTING
tsyslogd_LDADD = $(LIBS) $(LIBOBJS)
syslog_tst_SOURCES = syslog_tst.c syslog.c
syslog_tst_CPPFLAGS = -D_BSD_SOURCE -D_DEFAULT_SOURCE -DTESTING
syslog_tst_LDADD = $(LIBS) $(LIBOBJS)

View File

@ -44,17 +44,12 @@
* systemd/journald this is reserved and may already exist as
* a directory. For compatibility with GLIBC syslog API, for
* those who opt not to use this replacement API, we use the
* default/traditional Linux path /dev/log. In case we're in
* unit TESTING mode we usr /tmp/log.sock
* default/traditional Linux path /dev/log.
*/
#ifndef TESTING
# ifndef __linux__
# define _PATH_LOG "/var/run/log"
# else
# define _PATH_LOG "/dev/log"
# endif
#ifndef __linux__
#define _PATH_LOG "/var/run/log"
#else
# define _PATH_LOG "/tmp/log.sock"
#define _PATH_LOG "/dev/log"
#endif
/*

View File

@ -1,52 +0,0 @@
/* Program to test daemon logging. */
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <syslog.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
char *nl;
char bufr[512];
int logged = 0;
openlog("DOTEST", LOG_PID, LOG_DAEMON);
if (argc > 1) {
if ((*argv[1] == '-') && (*(argv[1] + 1) == '\0')) {
while (!feof(stdin))
if (fgets(bufr, sizeof(bufr), stdin)) {
if ((nl = strrchr(bufr, '\n')))
*nl = '\0';
syslog(LOG_INFO, "%s", bufr);
logged += strlen(bufr);
if (logged > 1024) {
sleep(1);
logged = 0;
}
}
} else
while (argc-- > 1)
syslog(LOG_INFO, "%s", argv++ [1]);
} else {
syslog(LOG_EMERG, "EMERG log.");
syslog(LOG_ALERT, "Alert log.");
syslog(LOG_CRIT, "Critical log.");
syslog(LOG_ERR, "Error log.");
syslog(LOG_WARNING, "Warning log.");
syslog(LOG_NOTICE, "Notice log.");
syslog(LOG_INFO, "Info log.");
syslog(LOG_DEBUG, "Debug log.");
closelog();
}
return 0;
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/

View File

@ -57,6 +57,8 @@ static char sccsid[] __attribute__((unused)) =
#define TIMERINTVL 30 /* interval for checking flush, mark */
#define RCVBUF_MINSIZE (80 * 1024) /* minimum size of dgram rcv buffer */
#include "config.h"
#include <assert.h>
#include <ctype.h>
#include <getopt.h>
@ -91,12 +93,9 @@ static char sccsid[] __attribute__((unused)) =
#include <netinet/in.h>
#include <resolv.h>
#include <syscall.h>
#ifndef TESTING
#include "pidfile.h"
#endif
#include "config.h"
#include <paths.h>
#include "pidfile.h"
#include "syslogd.h"
#include "compat.h"
@ -314,9 +313,7 @@ void domark();
void debug_switch();
void logerror(const char *type);
void die(int sig);
#ifndef TESTING
void doexit(int sig);
#endif
void init();
static int strtobytes(char *arg);
void cfline(char *line, struct filed *f);
@ -331,13 +328,11 @@ int main(int argc, char *argv[])
{
extern char *optarg;
extern int optind;
#ifndef TESTING
struct sockaddr_storage frominet;
pid_t ppid = getpid();
socklen_t len;
ssize_t msglen;
int fd;
#endif
fd_set readfds;
char line[MAXLINE + 1];
int num_fds, maxfds;
@ -440,7 +435,6 @@ int main(int argc, char *argv[])
if ((argc -= optind))
usage(1);
#ifndef TESTING
if ((!Foreground) && (!Debug)) {
logit("Checking pidfile.\n");
if (!check_pid(PidFile)) {
@ -471,14 +465,11 @@ int main(int argc, char *argv[])
fputs("syslogd: Already running.\n", stderr);
exit(1);
}
} else
#endif
{
} else {
debugging_on = 1;
setlinebuf(stdout);
}
#ifndef TESTING
/* tuck my process id away */
if (!Debug) {
logit("Writing pidfile.\n");
@ -495,8 +486,7 @@ int main(int argc, char *argv[])
kill(ppid, SIGTERM);
exit(1);
}
} /* if ( !Debug ) */
#endif
}
consfile.f_type = F_CONSOLE;
(void)strcpy(consfile.f_un.f_fname, ctty);
@ -521,10 +511,8 @@ int main(int argc, char *argv[])
logit("Allocated parts table for %d file descriptors.\n", num_fds);
if ((parts = malloc(num_fds * sizeof(char *))) == NULL) {
logerror("Cannot allocate memory for message parts table.");
#ifndef TESTING
if (getpid() != ppid)
kill(ppid, SIGTERM);
#endif
die(0);
}
for (i = 0; i < num_fds; ++i)
@ -532,17 +520,17 @@ int main(int argc, char *argv[])
logit("Starting.\n");
init();
#ifndef TESTING
if (Debug) {
logit("Debugging disabled, SIGUSR1 to turn on debugging.\n");
debugging_on = 0;
}
/*
* Send a signal to the parent to it can terminate.
*/
if (getpid() != ppid)
kill(ppid, SIGTERM);
#endif
/* Main loop begins here. */
for (;;) {
@ -552,7 +540,6 @@ int main(int argc, char *argv[])
FD_ZERO(&readfds);
maxfds = 0;
#ifndef TESTING
/*
* Add the Unix Domain Sockets to the list of read
* descriptors.
@ -579,13 +566,6 @@ int main(int argc, char *argv[])
}
logit("Listening on syslog UDP port.\n");
}
#else
FD_SET(fileno(stdin), &readfds);
if (fileno(stdin) > maxfds)
maxfds = fileno(stdin);
logit("Listening on stdin. Press Ctrl-C to interrupt.\n");
#endif
if (debugging_on) {
logit("Calling select, active file descriptors (max %d): ", maxfds);
@ -600,7 +580,7 @@ int main(int argc, char *argv[])
restart = 0;
logit("\nReceived SIGHUP, reloading syslogd.\n");
init();
#ifndef TESTING
if (check_pid(PidFile)) {
if (touch_pid(PidFile))
logerror("Not possible to touch pidfile");
@ -608,7 +588,6 @@ int main(int argc, char *argv[])
if (!write_pid(PidFile))
logerror("Failed to write pidfile");
}
#endif
continue;
}
@ -633,7 +612,6 @@ int main(int argc, char *argv[])
logit("\n");
}
#ifndef TESTING
for (i = 0; i < nfunix; i++) {
if ((fd = funix[i]) != -1 && FD_ISSET(fd, &readfds)) {
memset(line, 0, sizeof(line));
@ -680,26 +658,6 @@ int main(int argc, char *argv[])
}
}
}
#else
if (FD_ISSET(fileno(stdin), &readfds)) {
logit("Message from stdin.\n");
memset(line, 0, sizeof(line));
line[0] = '.';
parts[fileno(stdin)] = NULL;
i = read(fileno(stdin), line, MAXLINE);
logit("Message len: %d line: '%s'\n", i, line);
if (i > 0) {
parsemsg(LocalHostName, line);
} else if (i < 0) {
if (errno != EINTR)
logerror("stdin");
} else {
logit("EOF\n");
exit(0);
}
}
#endif
}
}
@ -2261,21 +2219,18 @@ void die(int signo)
for (i = 0; i < nfunix; i++)
if (funixn[i] && funix[i] != -1)
(void)unlink(funixn[i]);
#ifndef TESTING
(void)remove_pid(PidFile);
#endif
exit(0);
}
/*
* Signal handler to terminate the parent process.
*/
#ifndef TESTING
void doexit(int signo)
{
exit(0);
}
#endif
/*
* INIT -- Initialize syslogd from configuration table
@ -2371,12 +2326,7 @@ void init(void)
if ((cf = fopen(ConfFile, "r")) == NULL) {
logit("cannot open %s.\n", ConfFile);
#ifndef TESTING
cfline("*.err\t" _PATH_CONSOLE, f);
#else
snprintf(cbuf, sizeof(cbuf), "*.*\t%s", ttyname(0));
cfline(cbuf, f);
#endif
*nextp = calloc(1, sizeof(*f));
if (!*nextp) {