aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-12-08 09:29:50 +0200
committerSergey Poznyakoff <gray@gnu.org>2020-12-08 09:29:50 +0200
commit83513bddf4bd6c3ea5d42035bda4aaeae8086628 (patch)
treec4c18cad6150c42d6741325ec47b81baf551b645
parent261b55da70c1ab22c3729b823012ae30963f93d4 (diff)
downloadpies-83513bddf4bd6c3ea5d42035bda4aaeae8086628.tar.gz
pies-83513bddf4bd6c3ea5d42035bda4aaeae8086628.tar.bz2
Improve syslog redirection
* NEWS: Change wording a bit. * src/progman.c (redirect_to_file): Close and deregister the descriptor on error and EOF. * src/syslog.c (pies_log_tag): Rename to log_tag. (reopen_logger): Use PIES_LOG_DEV if log_dev is NULL. (pies_syslog_set_dev): Free previously allocated log_tag (if any).
-rw-r--r--NEWS2
-rw-r--r--src/progman.c34
-rw-r--r--src/syslog.c29
3 files changed, 43 insertions, 22 deletions
diff --git a/NEWS b/NEWS
index 951dd6b..c49ae72 100644
--- a/NEWS
+++ b/NEWS
@@ -53,7 +53,7 @@ or the IP[:PORT] specification, e.g.
* New control endpoint /alive
-A GET requets to /alive/PROG reflects the current state of the
+HTTP response to GET /alive/PROG reflects the current state of the
component PROG: 200 if it is running, 503 if not, and 404 if there's
no such component.
diff --git a/src/progman.c b/src/progman.c
index c376615..02034ef 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -205,7 +205,7 @@ find_prog_ref (struct component *comp)
{
comp = comp->prev;
if (!comp)
- return NULL; /* FIXME: Skip redirectors? */
+ return NULL;
}
if (comp->prog)
@@ -312,12 +312,6 @@ progman_waiting_p (void)
return 0;
}
-RETSIGTYPE
-redir_exit (int sig)
-{
- _exit (0);
-}
-
int
redirect_to_file (struct prog *master, int stream)
{
@@ -370,11 +364,33 @@ redirect_read (int fd, void *data)
char const *tag = prog_tag (rb->master);
pid_t pid = rb->master->pid;
char *p;
+ static char *retr_stream_name[] = {
+ [RETR_OUT] = "stdout",
+ [RETR_ERR] = "stderr"
+ };
n = read (fd, rb->text + rb->len, sizeof (rb->text) - rb->len);
if (n == -1)
- return -1;
- if (n > 0)
+ {
+ if (errno != EINTR)
+ {
+ logmsg (LOG_INFO, _("%s: %s while reading %s"),
+ tag, strerror (errno), retr_stream_name[rb->stream]);
+ rb->master->v.p.redir[rb->stream] = -1;
+ close (fd);
+ deregister_socket (fd);
+ return -1;
+ }
+ }
+ else if (n == 0)
+ {
+ logmsg (LOG_INFO, _("%s: EOF on %s"),
+ tag, retr_stream_name[rb->stream]);
+ rb->master->v.p.redir[rb->stream] = -1;
+ close (fd);
+ deregister_socket (fd);
+ }
+ else
{
rb->len += n;
diff --git a/src/syslog.c b/src/syslog.c
index a2a6482..6c7f5e7 100644
--- a/src/syslog.c
+++ b/src/syslog.c
@@ -51,11 +51,6 @@ struct log_message_in
/* Fallback log file is used to log critical messages when syslog
daemon is unavailable. If NULL, stderr will be used. */
char *pies_fallback_file = "/tmp/pies_logger.log";
-/* Name of the syslog device. If starts with a slash, it is assumed
- 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. */
-static char *pies_log_dev = PIES_LOG_DEV;
/* Log tag */
char *pies_log_tag = "pies";
/* Log facility */
@@ -63,6 +58,14 @@ int pies_log_facility = LOG_USER;
/* Maximum capacity of the log message queue */
size_t pies_log_max_queue = PIES_LOG_MAX_QUEUE;
+/* Name of the syslog device. If starts with a slash, it is assumed
+ 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.
+ If NULL, PIES_LOG_DEV is assumed.
+ The user can modify this value using the pies_syslog_set_dev call.
+*/
+static char *log_dev;
/* Log socket descriptor. */
static int log_fd = -1;
@@ -118,15 +121,16 @@ reopen_logger (void)
if (log_salen == 0)
{
- if (pies_log_dev[0] == '/')
+ char *dev = log_dev ? log_dev : PIES_LOG_DEV;
+ if (dev[0] == '/')
{
- size_t len = strlen (pies_log_dev);
+ size_t len = strlen (dev);
if (len >= sizeof log_sa.s_un.sun_path)
{
- fallback_log ("%s: UNIX socket name too long", pies_log_dev);
+ fallback_log ("%s: UNIX socket name too long", dev);
return -1;
}
- strcpy (log_sa.s_un.sun_path, pies_log_dev);
+ strcpy (log_sa.s_un.sun_path, dev);
log_sa.s_un.sun_family = AF_UNIX;
log_family = PF_UNIX;
log_salen = sizeof (log_sa.s_un);
@@ -139,7 +143,7 @@ reopen_logger (void)
char *node;
char *service;
- node = strdup (pies_log_dev);
+ node = strdup (dev);
if (!node)
return -1;
@@ -158,7 +162,7 @@ reopen_logger (void)
free(node);
if (rc)
{
- fallback_log ("%s: invalid socket address", pies_log_dev);
+ fallback_log ("%s: invalid socket address", dev);
return -1;
}
@@ -469,8 +473,9 @@ pies_syslog_set_dev (char const *dev)
char *p = strdup (dev);
if (!p)
return -1;
- pies_log_dev = p;
pies_syslog_close ();
+ free (log_dev);
+ log_dev = p;
log_salen = 0;
return 0;
}

Return to:

Send suggestions and report system problems to the System administrator.