Support for building the project w/o separate klogd (default)

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-11-12 15:51:33 +01:00
parent 0455da805f
commit 823bb4cf2a
6 changed files with 140 additions and 23 deletions

View File

@ -49,14 +49,18 @@ AC_CONFIG_LIBOBJ_DIR([lib])
AC_CHECK_FUNCS([getprogname strtobytes])
# Command line options
AC_ARG_WITH(klogd,
AS_HELP_STRING([--with-klogd], [Build a separate klogd, default: disabled]),
[klogd=$withval], [klogd='no'])
AC_ARG_WITH(klogd-delay,
AS_HELP_STRING([--with-klogd-delay=SEC], [When klogd is started at the same time as syslogd, default: 0]),
[klogd_delay=$withval], [klogd_delay='no'])
AC_ARG_WITH(suspend-time,
AS_HELP_STRING([--with-suspend-time=SEC], [Retry timeout for remote syslogd servers, default: 180]),
[suspend_time=$withval], [suspend_time='no'])
AC_ARG_WITH(klogd-delay,
AS_HELP_STRING([--with-klogd-delay=SEC], [when started at the same time as syslogd, default: 0]),
[klogd_delay=$withval], [klogd_delay='no'])
AC_ARG_WITH(syslogd-pidfile,
AS_HELP_STRING([--with-syslogd-pidfile=FILE], [custom PID file, default: syslogd.pid]),
[syslogd_pidfile=$withval], [syslogd_pidfile='no'])
@ -65,23 +69,32 @@ AC_ARG_WITH(systemd,
[AS_HELP_STRING([--with-systemd=DIR], [Directory for systemd service files])],,
[with_systemd=auto])
AS_IF([test "x$suspend_time" != "xno"],[
AS_IF([test "x$suspend_time" = "xyes"],[
AC_MSG_ERROR([Must supply argument])])
]
AC_DEFINE_UNQUOTED(INET_SUSPEND_TIME, $suspend_time, [Retry timeout for remote syslgod servers, default: 180]))
AS_IF([test "x$klogd" != "xno"],
with_klogd="yes"
AC_DEFINE(KLOGD, 1, [Build with klogd, default: built-in /dev/kmsg support in syslogd]),
with_klogd="no")
AM_CONDITIONAL([ENABLE_KLOGD], [test "x$with_klogd" != "xno"])
AS_IF([test "x$klogd_delay" != "xno"],[
AS_IF([test "x$klogd_delay" = "xyes"],[
AC_MSG_ERROR([Must supply argument])])
]
AC_DEFINE_UNQUOTED(KLOGD_DELAY, $klogd_delay, [Delay klogd startup N seconds, default: 0]))
AC_DEFINE_UNQUOTED(KLOGD_DELAY, $klogd_delay, [Delay klogd startup N seconds, default: 0]),
klogd_delay=0)
AS_IF([test "x$suspend_time" != "xno"],[
AS_IF([test "x$suspend_time" = "xyes"],[
AC_MSG_ERROR([Must supply argument])])
]
AC_DEFINE_UNQUOTED(INET_SUSPEND_TIME, $suspend_time, [Retry timeout for remote syslgod servers, default: 180]),
suspend_time=180)
AS_IF([test "x$syslogd_pidfile" != "xno"],[
AS_IF([test "x$syslogd_pidfile" = "xyes"],[
AC_MSG_ERROR([Must supply argument])])
]
AC_DEFINE_UNQUOTED(SYSLOGD_PIDNAME, "$syslogd_pidfile", [Custom syslogd PID file]))
AC_DEFINE_UNQUOTED(SYSLOGD_PIDNAME, "$syslogd_pidfile", [Custom syslogd PID file]),
syslogd_pidfile="syslogd.pid")
# Check where to install the systemd .service file
AS_IF([test "x$with_systemd" = "xyes" -o "x$with_systemd" = "xauto"], [
@ -105,3 +118,28 @@ SBINDIR=`eval echo $SBINDIR`
AC_SUBST(SBINDIR)
AC_OUTPUT
cat <<EOF
------------------ Summary ------------------
$PACKAGE_NAME version $PACKAGE_VERSION
Prefix.........: $prefix
Sysconfdir.....: `eval echo $sysconfdir`
Localstatedir..: `eval echo $localstatedir`
C Compiler.....: $CC $CFLAGS $CPPFLAGS $LDFLAGS $LIBS
Optional features:
klogd..........: $with_klogd
klogd delay....: $klogd_delay sec
suspend time...: $suspend_time sec
pid file.......: /var/run/$syslogd_pidfile
systemd........: $with_systemd
------------- Compiler version --------------
$($CC --version || true)
---------------------------------------------
Check the above options and compile with:
${MAKE-make}
EOF

View File

@ -1,4 +1,8 @@
dist_man1_MANS = logger.1
dist_man3_MANS = syslogp.3
dist_man5_MANS = syslog.conf.5
dist_man8_MANS = syslogd.8 klogd.8
dist_man8_MANS = syslogd.8
if ENABLE_KLOGD
dist_man8_MANS += klogd.8
endif

View File

@ -16,11 +16,15 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bin_PROGRAMS = logger
sbin_PROGRAMS = syslogd klogd
bin_PROGRAMS = logger
sbin_PROGRAMS = syslogd
lib_LTLIBRARIES = libsyslog.la
noinst_LTLIBRARIES = libcompat.la
if ENABLE_KLOGD
sbin_PROGRAMS += klogd
endif
AM_CFLAGS = -W -Wall -Wextra
AM_CFLAGS += -Wno-unused-result -Wno-unused-parameter -fno-strict-aliasing
AM_CPPFLAGS = -DSYSCONFDIR=\"@sysconfdir@\" -DLOCALSTATEDIR=\"@localstatedir@\"

View File

@ -72,16 +72,18 @@ int socket_register(int sd, struct addrinfo *ai, void (*cb)(int, void *), void *
{
struct sock *entry = NULL;
entry = malloc(sizeof(*entry));
entry = calloc(1, sizeof(*entry));
if (!entry)
goto err;
entry->ai.ai_addr = calloc(1, sizeof(struct sockaddr_un));
if (!entry->ai.ai_addr)
goto eaddr;
if (ai) {
entry->ai.ai_addr = calloc(1, sizeof(struct sockaddr_un));
if (!entry->ai.ai_addr)
goto eaddr;
entry->ai = *ai;
*entry->ai.ai_addr = *ai->ai_addr;
entry->ai = *ai;
*entry->ai.ai_addr = *ai->ai_addr;
}
entry->sd = sd;
entry->cb = cb;

View File

@ -155,7 +155,10 @@ static SIMPLEQ_HEAD(, peer) pqueue = SIMPLEQ_HEAD_INITIALIZER(pqueue);
/* Function prototypes. */
void untty(void);
static void parsemsg(const char *from, char *msg);
void printsys(char *msg);
#ifndef KLOGD
static int opensys(const char *file);
static void printsys(char *msg);
#endif
static void logmsg(struct buf_msg *buffer);
static void fprintlog(struct filed *f, struct buf_msg *buffer);
void endtty();
@ -237,7 +240,7 @@ int main(int argc, char *argv[])
int pflag = 0, bflag = 0;
int ch;
#ifndef WITHOUT_KLOGD
#ifdef KLOGD
/*
* When building with klogd enabled this works around filtering
* of LOG_KERN messages in parsemsg(). Otherwise it needs to be
@ -349,6 +352,12 @@ int main(int argc, char *argv[])
.pe_mode = 0666,
});
#ifndef KLOGD
/* Attempt to open kernel log pipe */
if (opensys(_PATH_KLOG))
err(1, "Faield opening %s", _PATH_KLOG);
#endif
if ((!Foreground) && (!Debug)) {
signal(SIGTERM, doexit);
chdir("/");
@ -456,6 +465,61 @@ int main(int argc, char *argv[])
}
}
#ifndef KLOGD
/*
* Read /dev/klog while data are available, split into lines.
*/
static void kernel_cb(int fd, void *arg)
{
char *p, *q, line[MAXLINE + 1];
int len, i;
len = 0;
for (;;) {
i = read(fd, line + len, MAXLINE - 1 - len);
if (i > 0) {
line[i + len] = '\0';
} else {
if (i < 0 && errno != EINTR && errno != EAGAIN) {
ERR("klog");
socket_close(fd);
}
break;
}
for (p = line; (q = strchr(p, '\n')) != NULL; p = q + 1) {
*q = '\0';
printsys(p);
}
len = strlen(p);
if (len >= MAXLINE - 1) {
printsys(p);
len = 0;
}
if (len > 0)
memmove(line, p, len + 1);
}
if (len > 0)
printsys(line);
}
static int opensys(const char *file)
{
int fd;
fd = open(file, O_RDONLY | O_NONBLOCK | O_CLOEXEC, 0);
if (fd < 0)
return 1;
if (socket_register(fd, NULL, kernel_cb, NULL) < 0) {
close(fd);
return 1;
}
return 0;
}
#endif
static void unix_cb(int sd, void *arg)
{
ssize_t msglen;
@ -995,7 +1059,8 @@ void printsys(char *msg)
lp = line;
for (p = msg; *p != '\0';) {
memset(&buffer, 0, sizeof(buffer));
buffer.app_name = "vmunix";
buffer.app_name = "kernel";
buffer.hostname = LocalHostName;
buffer.pri = DEFSPRI;
buffer.msg = line;

View File

@ -96,6 +96,10 @@
#define _PATH_LOG "/dev/log"
#endif
#ifndef _PATH_KLOG
#define _PATH_KLOG "/proc/kmsg"
#endif
#ifdef UT_NAMESIZE
#define UNAMESZ UT_NAMESIZE /* length of a login name */
#else