From b3a58380b93512b86fe02749425410d89a5655d4 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Sat, 5 Dec 2020 16:58:05 +0200 Subject: Remove the component.facility keyword. Update the docs. * NEWS: Update. * doc/pies.texi: Update. * src/pies.h (component): Remove the facility field. * src/comp.c: Likewise. * configure.ac: Select interface to use to close fds (imported from mailutils). * lib/closefds.c: New file (imported from mailutils). * lib/Makefile.am: Add closefds.c * lib/libpies.h (pies_close_fds): New proto. * src/pies.c: Use pies_close_fds * src/progman.c: Likewise. --- NEWS | 25 ++++++++++++++++++++++++- configure.ac | 32 ++++++++++++++++++++++++++++++++ doc/pies.texi | 55 ++++++++++++++++++++++++++++++------------------------- lib/Makefile.am | 1 + lib/libpies.h | 2 ++ src/comp.c | 2 -- src/pies.c | 15 +-------------- src/pies.h | 1 - src/progman.c | 25 +++---------------------- 9 files changed, 93 insertions(+), 65 deletions(-) diff --git a/NEWS b/NEWS index 73d2e07..775848e 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -GNU Pies NEWS -- history of user-visible changes. 2020-12-02 +GNU Pies NEWS -- history of user-visible changes. 2020-12-05 See the end of file for copying conditions. Please send Pies bug reports to or @@ -28,6 +28,29 @@ the shell. This flag is incompatible with the "shell" flag. When both are used, the preference is given to "shell" and a warning message to that effect is issued. + +* Component standard stream redirection rewritten from scratch + +In particular, redirecting stdout/stderr to syslog no longer require +starting an auxiliar process. + +* The component.facility configuration statement is withdrawn + +To specify a particular facility, use the fully qualified +facility.priority argument to the stdout or stderr statement, e.g.: + + stderr syslog local1.err; + +* New configuration statement syslog.dev + +The statement configures the socket to communicate with the syslog +daemon. Its argument is either the file name of the local socket +or the IP[:PORT] specification, e.g. + + syslog { + dev 172.31.255.252; + } + Version 1.4, 2019-07-02 diff --git a/configure.ac b/configure.ac index 9a2446d..2d66e24 100644 --- a/configure.ac +++ b/configure.ac @@ -155,6 +155,38 @@ AH_BOTTOM([ # endif ]) +# ################################# +# Select interface used to close file descriptors greater than or +# equal to the given one. +# +# Variants: +# 1. closefrom call (FreeBSD) +# 2. F_CLOSEM fcntl (NetBSD, AIX, IRIX) +# 3. proc_pidinfo call (Darwin) +# 4. /proc/self/fd filesystem (Linux) +# 5. Brute force +# +# The defines created here direct conditionalal compilation in +# lib/closefds.c + +AC_CHECK_FUNCS([closefrom]) +AC_CHECK_DECL([F_CLOSEM], + AC_DEFINE([HAVE_FCNTL_CLOSEM], [1], + [Use F_CLOSEM fcntl for mu_close_fds]), + [], + [#include + #include +]) + +AC_CHECK_HEADERS([libproc.h]) +AC_CHECK_FUNCS([proc_pidinfo]) + +if test -d "/proc/self/fd" ; then + AC_DEFINE([HAVE_PROC_SELF_FD], [1], [Define if you have /proc/self/fd]) +fi + +# ############################## + AC_SUBST([DEFAULT_PIES_CONTROL_URL],['unix:///tmp/$${PIES_INSTANCE}.ctl']) AC_ARG_VAR([DEFAULT_PIES_CONTROL_URL], [URL of the default control socket]) diff --git a/doc/pies.texi b/doc/pies.texi index 9871641..1d65cf4 100644 --- a/doc/pies.texi +++ b/doc/pies.texi @@ -1528,26 +1528,25 @@ stderr file /var/log/component/name.err; @end example @item syslog -Redirect to a syslog channel. The syslog priority is given by the -@var{channel} argument. Allowed values are: @samp{emerg}, -@samp{alert}, @samp{crit}, @samp{err}, @samp{warning}, @samp{notice}, -@samp{info}, @samp{debug}. The facility is inherited from the -@code{syslog} statement (@pxref{syslog}), or from the @code{facility} -statement (see below), if given. +Redirect to syslog. The @var{channel} parameter is either the syslog +facility and priority separated by dot or the priority alone, in which +case the facility will be taken from the @code{syslog} statement +(@pxref{syslog}). Example: @example +stdout syslog local1.info; stderr syslog err; @end example -@end table -@end deffn -@deffn {Config: component} facility @var{syslog-facility} -Specify the syslog facility to use in syslog redirectors. Allowed -@var{syslog-facility} values are: @samp{user}, @samp{daemon}, +Valid facilities are: @samp{user}, @samp{daemon}, @samp{auth}, @samp{authpriv}, @samp{mail}, @samp{cron}, @samp{local0} -through @samp{local7} (all names case-insensitive), or a facility number. +through @samp{local7} (all names case-insensitive). + +Valid priorities are: @samp{emerg}, @samp{alert}, @samp{crit}, +@samp{err}, @samp{warning}, @samp{notice}, @samp{info}, @samp{debug}. +@end table @end deffn @node Inetd-Style Components @@ -2073,8 +2072,6 @@ component @var{tag} @{ # @r{or:} acl @{ @dots{} @} - # @r{Override default syslog facility for this component.} - facility @var{facility}; # @r{Redirect program's standard output to the given} # @r{file or syslog priority.} # @xref{Output Redirectors}. @@ -2783,8 +2780,7 @@ syslog channel: include-meta1 /etc/meta1/meta1.conf component smtps @{ - facility local1; - stderr syslog debug; + stderr syslog local1.debug; @} @end example @@ -2796,20 +2792,30 @@ behavior as a whole. @anchor{syslog} @deffn {Config} syslog @{ @dots{} @} -This block statement configures logging via syslog. It has two +This block statement configures logging via syslog. It has the following substatements: @end deffn -@deffn {Config: syslog} tag @var{string} -Prefix syslog messages with this string. By default, the program name -is used. +@deffn {Config: syslog} dev @var{address} +Address of the socket the syslog daemon is listening on. By default, +@file{/dev/log} is used. + +The @var{address} argument is either the file name of the UNIX socket +file or IPv4 address of the syslog collector optionally followed by +the colon and port number (or symbolic service name). If the port +number is not supplied, the @samp{syslog} port (UDP) from +@file{/etc/services} is used. @end deffn @deffn {Config: syslog} facility @var{string} Set syslog facility to use. Allowed values are: @samp{user}, @samp{daemon}, @samp{auth}, @samp{authpriv}, @samp{mail}, @samp{cron}, -@samp{local0} through @samp{local7} (case-insensitive), or a facility -number. +@samp{local0} through @samp{local7} (case-insensitive). +@end deffn + +@deffn {Config: syslog} tag @var{string} +Prefix syslog messages with this string. By default, the program name +is used. @end deffn @deffn {Config} umask @var{number} @@ -4050,9 +4056,8 @@ output are redirected to the syslog facility @samp{mail}, priorities component pmult @{ command "/usr/local/sbin/pmult"; user meta1s; - facility mail; - stderr syslog err; - stdout syslog info; + stderr syslog mail.err; + stdout syslog mail.info; @} @end example diff --git a/lib/Makefile.am b/lib/Makefile.am index f3d8222..d3ddd21 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -21,6 +21,7 @@ noinst_HEADERS = libpies.h grecsasrt.h libpies_a_SOURCES=\ addrfmt.c\ arraymember.c\ + closefds.c\ envop.c\ envop.h\ grecsasrt.c\ diff --git a/lib/libpies.h b/lib/libpies.h index 34d3569..2bafb31 100644 --- a/lib/libpies.h +++ b/lib/libpies.h @@ -30,6 +30,8 @@ #else # define getmaxfd() 256 #endif + +void pies_close_fds (int minfd); void mf_proctitle_init (int argc, char *argv[], char *env[]); void mf_proctitle_format (const char *fmt, ...); diff --git a/src/comp.c b/src/comp.c index 5a2a139..4d6c9f7 100644 --- a/src/comp.c +++ b/src/comp.c @@ -154,7 +154,6 @@ component_create (const char *name) { comp = grecs_zalloc (sizeof (*comp)); comp->listidx = cur; - comp->facility = pies_log_facility; comp->redir[RETR_OUT].type = comp->redir[RETR_ERR].type = redir_null; comp->tag = grecs_strdup (name); comp->socket_type = SOCK_STREAM; @@ -293,7 +292,6 @@ component_match (struct component *comp, struct component *ref) EQ (pass_fd_timeout); FN (acl, pies_acl_cmp); FN (tcpmux, safe_strcmp); - EQ (facility); FNP (redir[0], redirector_cmp); FNP (redir[1], redirector_cmp); #undef MATCH diff --git a/src/pies.c b/src/pies.c index 355612f..8651193 100644 --- a/src/pies.c +++ b/src/pies.c @@ -1367,13 +1367,6 @@ struct grecs_keyword component_keywords[] = { NULL, offsetof (struct component, rmfile), NULL, }, - {"facility", - N_("arg"), - N_("Override default syslog facility for this component."), - grecs_type_string, GRECS_DFLT, - NULL, offsetof (struct component, facility), - cb_syslog_facility, - }, {"stdout", /* TRANSLATORS: file and syslog are keywords. Do not translate them. */ N_("type: {file | syslog}> minfd; i--) - close (i); - + pies_close_fds (2); signal_setup (SIG_DFL); - execv (pies_master_argv[0], pies_master_argv); } diff --git a/src/pies.h b/src/pies.h index 99169db..867f81d 100644 --- a/src/pies.h +++ b/src/pies.h @@ -270,7 +270,6 @@ struct component char *max_ip_connections_message; /* Redirectors: */ - int facility; /* Syslog facility. */ struct redirector redir[2]; /* Repeaters for stdout and stderr */ /* Actions to execute on various exit codes: */ struct grecs_list *act_list; diff --git a/src/progman.c b/src/progman.c index 81accfb..d808010 100644 --- a/src/progman.c +++ b/src/progman.c @@ -434,19 +434,6 @@ redirect_to_syslog (struct prog *master, int stream, int *fd) return p[1]; } -static void -close_fds (fd_set *fdset) -{ - int i; - - for (i = FD_SETSIZE-1; i >= 0; i--) - { - if (fdset && FD_ISSET (i, fdset)) - continue; - close (i); - } -} - void free_redirector (struct redirector *rp) { @@ -939,7 +926,6 @@ prog_start (struct prog *prog) { pid_t pid; int redir[2]; - fd_set fdset; if (prog->pid > 0 || !IS_COMPONENT (prog)) return; @@ -1106,13 +1092,8 @@ prog_start (struct prog *prog) } /* Close unneeded descripitors */ - FD_ZERO (&fdset); - FD_SET (0, &fdset); - FD_SET (1, &fdset); - FD_SET (2, &fdset); - if (prog->v.p.comp->mode == pies_comp_pass_fd) - FD_SET (prog->v.p.socket, &fdset); - close_fds (&fdset); + pies_close_fds (prog->v.p.comp->mode == pies_comp_pass_fd + ? prog->v.p.socket : 2); prog_execute (prog); @@ -2047,7 +2028,7 @@ run_command (struct action *act, struct prog *prog, unsigned retcode, else setenv ("PIES_STATUS", umaxtostr (STATUS_CODE (retcode), buf), 1); - close_fds (NULL); + pies_close_fds (2); argv[0] = "/bin/sh"; argv[1] = "-c"; -- cgit v1.2.1