diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-12-07 15:44:05 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-12-07 15:49:01 +0200 |
commit | 1f528cbd617b49d20bbfc30c16e3dd810849b136 (patch) | |
tree | 6d248f1c079d4c62eb1e84ce5dd7cc03490b31d4 | |
parent | 5c0938830468b5829d3106a34456e85896201d1a (diff) | |
download | pies-1f528cbd617b49d20bbfc30c16e3dd810849b136.tar.gz pies-1f528cbd617b49d20bbfc30c16e3dd810849b136.tar.bz2 |
Fix changing of the syslog dev. Fix bugs in closing unnecessary fds. Version 1.4.96
* lib/closefds.c [HAVE_FUNC_PROC_PIDINFO] (close_fds_sys): Fix
algorithm.
* src/pies.c (cb_syslog_dev): New callback. Handle "dev" using it.
(main): Don't close fd 2 before restarting.
* src/pies_syslog.h (pies_syslog_set_dev): New proto.
* src/progman.c (prog_start,run_command): Don't close necessary fds.
* src/syslog.c (pies_log_dev): Mark as static.
(pies_syslog_set_dev): New function.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | lib/closefds.c | 5 | ||||
-rw-r--r-- | src/pies.c | 18 | ||||
-rw-r--r-- | src/pies_syslog.h | 2 | ||||
-rw-r--r-- | src/progman.c | 6 | ||||
-rw-r--r-- | src/syslog.c | 13 |
7 files changed, 36 insertions, 12 deletions
@@ -4,7 +4,7 @@ See the end of file for copying conditions. Please send Pies bug reports to <bug-pies@gnu.org> or <bug-pies@gnu.org.ua> -Version 1.4.95 (git) +Version 1.4.96 (git) * Detect if pies is started from docker diff --git a/configure.ac b/configure.ac index c1cddfd..257c513 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ # along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. AC_PREREQ([2.63]) -AC_INIT([GNU Pies], [1.4.95], [bug-pies@gnu.org.ua]) +AC_INIT([GNU Pies], [1.4.96], [bug-pies@gnu.org.ua]) AC_CONFIG_SRCDIR([src/pies.h]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_HEADERS([config.h]) diff --git a/lib/closefds.c b/lib/closefds.c index 50e8bfa..6fa227d 100644 --- a/lib/closefds.c +++ b/lib/closefds.c @@ -68,9 +68,10 @@ close_fds_sys (int minfd) n /= PROC_PIDLISTFD_SIZE; - for (i = minfd; i < n; i++) + for (i = 0; i < n; i++) { - close (fdinfo_buf[i].proc_fd); + if (fdinfo_buf[i].proc_fd >= minfd) + close (fdinfo_buf[i].proc_fd); } free (fdinfo); @@ -943,6 +943,18 @@ string_to_syslog_fp (const char *str, grecs_locus_t *locus, int *pres) } static int +cb_syslog_dev (enum grecs_callback_command cmd, + grecs_node_t *node, + void *varptr, void *cb_data) +{ + grecs_value_t *value = node->v.value; + + if (grecs_assert_node_value_type (cmd, node, GRECS_TYPE_STRING)) + return 1; + return pies_syslog_set_dev (value->v.string); +} + +static int cb_syslog_facility (enum grecs_callback_command cmd, grecs_node_t *node, void *varptr, void *cb_data) @@ -1556,8 +1568,8 @@ static struct grecs_keyword syslog_kw[] = { N_("name"), N_("Syslog device: either absolute pathname of the socket file, " "or an IPv4 address and optional port, separated with a colon"), - grecs_type_string, GRECS_DFLT, - &pies_log_dev}, + grecs_type_string, GRECS_CONST, + NULL, 0, cb_syslog_dev }, {"facility", N_("name"), N_("Set syslog facility. Arg is one of the following: user, daemon, " @@ -2627,7 +2639,7 @@ main (int argc, char **argv) if (action == ACTION_RESTART) { - pies_close_fds (2); + pies_close_fds (3); signal_setup (SIG_DFL); execv (pies_master_argv[0], pies_master_argv); } diff --git a/src/pies_syslog.h b/src/pies_syslog.h index bf83714..1b79b8b 100644 --- a/src/pies_syslog.h +++ b/src/pies_syslog.h @@ -18,6 +18,7 @@ #define PIES_LOG_DEV "/dev/log" #define PIES_LOG_MAX_QUEUE 64 +int pies_syslog_set_dev (char const *dev); int pies_syslog_open (void); void pies_syslog_close (void); void pies_syslog (int pri, char const *fmt, ...); @@ -26,7 +27,6 @@ void pies_syslog_flush (void); void pies_syslog_message (int prio, char const *text, char const *tag, pid_t pid); extern char *pies_fallback_file; -extern char *pies_log_dev; extern char *pies_log_tag; extern int pies_log_facility; extern size_t pies_log_max_queue; diff --git a/src/progman.c b/src/progman.c index e71d86d..c376615 100644 --- a/src/progman.c +++ b/src/progman.c @@ -1093,8 +1093,8 @@ prog_start (struct prog *prog) } /* Close unneeded descripitors */ - pies_close_fds (prog->v.p.comp->mode == pies_comp_pass_fd - ? prog->v.p.socket : 2); + pies_close_fds ((prog->v.p.comp->mode == pies_comp_pass_fd + ? prog->v.p.socket : 2) + 1); prog_execute (prog); @@ -2029,7 +2029,7 @@ run_command (struct action *act, struct prog *prog, unsigned retcode, else setenv ("PIES_STATUS", umaxtostr (STATUS_CODE (retcode), buf), 1); - pies_close_fds (2); + pies_close_fds (3); argv[0] = "/bin/sh"; argv[1] = "-c"; diff --git a/src/syslog.c b/src/syslog.c index 36f9473..38754a7 100644 --- a/src/syslog.c +++ b/src/syslog.c @@ -55,7 +55,7 @@ char *pies_fallback_file = "/tmp/pies_logger.log"; to be a UNIX socket name. Otherwise, it is assumed to be a host name or IPv4 address of the syslog daemon, optionally followed by a colon and port number or service name. */ -char *pies_log_dev = PIES_LOG_DEV; +static char *pies_log_dev = PIES_LOG_DEV; /* Log tag */ char *pies_log_tag = "pies"; /* Log facility */ @@ -462,3 +462,14 @@ pies_syslog_message (int prio, char const *text, char const *tag, pid_t pid) { log_message_enqueue (log_message_create (prio, text, tag, pid)); } + +int +pies_syslog_set_dev (char const *dev) +{ + char *p = strdup (dev); + if (!p) + return -1; + pies_log_dev = p; + pies_syslog_close (); + log_salen = 0; +} |