aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-05-13 07:16:02 +0300
committerSergey Poznyakoff <gray@gnu.org>2021-05-13 07:16:02 +0300
commit6a36a2c2424022a6a0ac3be1a2ead8270eec9358 (patch)
tree0794ade382a256982419f0c021dbf4b4fc18142e
parent17abf051c711288e43b1646419c2b35cdafe86b9 (diff)
downloadrpipe-6a36a2c2424022a6a0ac3be1a2ead8270eec9358.tar.gz
rpipe-6a36a2c2424022a6a0ac3be1a2ead8270eec9358.tar.bz2
Syslog logging
* src/rpipe.c (verror_stderr,verror_syslog): New functions. (verror): Change type to a function pointer. (main): Support for the -S option. * src/rpipe.1: Document the -S option. * NEWS: Update.
-rw-r--r--NEWS10
-rw-r--r--src/rpipe.121
-rw-r--r--src/rpipe.c84
3 files changed, 110 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index e8d2497..f7ead0e 100644
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,16 @@
-rpipe -- history of user-visible changes. 2021-05-12
+rpipe -- history of user-visible changes. 2021-05-13
See the end of file for copying conditions.
Please send rpipe bug reports to <gray@gnu.org>
+Version 1.7.90 (git)
+
+* Syslog support
+
+New option '-S FACILITY' switches diagnostic output to the given
+syslog facility.
+
+
Version 1.7, 2021-05-12
* Fix handling of hangup on program output stream.
diff --git a/src/rpipe.1 b/src/rpipe.1
index 1d615a4..83419b7 100644
--- a/src/rpipe.1
+++ b/src/rpipe.1
@@ -13,7 +13,7 @@
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with rpipe. If not, see <http://www.gnu.org/licenses/>.
-.TH RPIPE 1 "April 21, 2021" "RPIPE"
+.TH RPIPE 1 "May 12, 2021" "RPIPE"
.SH NAME
rpipe \- remote pipe multiplexer
.SH SYNOPSIS
@@ -25,6 +25,7 @@ rpipe \- remote pipe multiplexer
[\fB\-g \fIGROUP\fR[,\fIGROUP\fR...]]\
[\fB\-n \fINUMBER\fR]\
[\fB\-p \fIFILE\fR]\
+ [\fB\-S \fIFACILITY\fR]\
[\fB\-u \fIUSER\fR]\
\fIARG\fR...
.sp
@@ -158,6 +159,24 @@ line obtained from the client is looked up in that file. If found, the
rest of fields gives the privileges to run the constructed command
with. If not found, user and group supplied by \fB\-u\fR and \fB\-g\fR
options (if given) will be used.
+.TP
+\fB\-S \fIFACILITY\fR
+Log messages to the given syslog facility. \fIFACILITY\fR is one of
+.BR auth ,
+.BR authpriv ,
+.BR cron ,
+.BR daemon ,
+.BR ftp ,
+.BR kern ,
+.BR lpr ,
+.BR mail ,
+.BR news ,
+.BR user ,
+.BR uucp ,
+.BR local0 " through " local7 ,
+or a decimal facility number.
+.sp
+By default all messages are written to stderr.
.TP
.B \-s
Enable server mode.
diff --git a/src/rpipe.c b/src/rpipe.c
index decdcdb..c0b293e 100644
--- a/src/rpipe.c
+++ b/src/rpipe.c
@@ -17,6 +17,8 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
+#include <syslog.h>
+#include <limits.h>
#include "rpipe.h"
int verbose;
@@ -34,7 +36,7 @@ setprogname(char *arg0)
}
void
-verror(char const *fmt, int err, va_list ap)
+verror_stderr(char const *fmt, int err, va_list ap)
{
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, fmt, ap);
@@ -44,6 +46,26 @@ verror(char const *fmt, int err, va_list ap)
}
void
+verror_syslog(char const *fmt, int err, va_list ap)
+{
+ if (err) {
+ static char fmtbuf[1024];
+#define SUFFIX ": %m"
+ size_t flen = strlen(fmt) + sizeof(SUFFIX);
+ if (flen < sizeof(fmtbuf)) {
+ int saved_errno = errno;
+ strcat(strcpy(fmtbuf, fmt), SUFFIX);
+ errno = err;
+ vsyslog(LOG_ERR, fmtbuf, ap);
+ errno = saved_errno;
+ }
+ } else
+ vsyslog(LOG_ERR, fmt, ap);
+}
+
+void (*verror)(char const *fmt, int err, va_list ap) = verror_stderr;
+
+void
error(int status, int err, char const *fmt, ...)
{
va_list ap;
@@ -93,6 +115,7 @@ usage(void)
printf(" connections.\n");
printf(" -p FILE (Server only) Read per-command user run-time\n");
printf(" privileges from FILE.\n");
+ printf(" -S FACILITY Log to the syslog FACILITY.\n");
printf(" -s Enable server mode.\n");
printf(" -T Enable test mode.\n");
printf(" -u USER (Server only) Run with that USER privileges\n");
@@ -115,7 +138,7 @@ License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.\
This is free software: you are free to change and redistribute it.\n\
There is NO WARRANTY, to the extent permitted by law.\n");
}
-
+
static inline char const *
default_address(char const *address, char const *dfl)
{
@@ -125,6 +148,57 @@ default_address(char const *address, char const *dfl)
return address;
}
+static struct {
+ char const *name;
+ int fac;
+} syslog_facilities[] = {
+ { "auth", LOG_AUTH },
+#ifdef LOG_AUTHPRIV
+ { "authpriv", LOG_AUTHPRIV },
+#endif
+ { "cron", LOG_CRON },
+ { "daemon", LOG_DAEMON },
+ { "ftp", LOG_FTP },
+ { "kern", LOG_KERN },
+ { "lpr", LOG_LPR },
+ { "mail", LOG_MAIL },
+ { "news", LOG_NEWS },
+ { "user", LOG_USER },
+ { "uucp", LOG_UUCP },
+ { "local0", LOG_LOCAL0 },
+ { "local1", LOG_LOCAL1 },
+ { "local2", LOG_LOCAL2 },
+ { "local3", LOG_LOCAL3 },
+ { "local4", LOG_LOCAL4 },
+ { "local5", LOG_LOCAL5 },
+ { "local6", LOG_LOCAL6 },
+ { "local7", LOG_LOCAL7 },
+ { NULL }
+};
+
+static int
+syslog_facility(char const *s)
+{
+ int i;
+ char *p;
+ unsigned long n;
+
+ for (i = 0; syslog_facilities[i].name; i++) {
+ if (strcasecmp(syslog_facilities[i].name, s) == 0)
+ return syslog_facilities[i].fac;
+ }
+
+ errno = 0;
+ n = strtoul(s, &p, 10);
+ if (errno || *p)
+ error(EX_USAGE, 0, "invalid syslog facility %s", s);
+ if ((INT_MAX >> 3) < n)
+ error(EX_USAGE, 0, "numeric facility out of allowed range: %s",
+ s);
+ return n;
+}
+
+
int
main(int argc, char **argv)
{
@@ -136,7 +210,7 @@ main(int argc, char **argv)
char const *group = NULL;
setprogname(argv[0]);
- while ((c = getopt(argc, argv, "+a:g:hn:sp:Tu:Vv")) != EOF) {
+ while ((c = getopt(argc, argv, "+a:g:hn:S:sp:Tu:Vv")) != EOF) {
switch (c) {
case 'a':
address = optarg;
@@ -162,6 +236,10 @@ main(int argc, char **argv)
*/
mode = RPIPE_TEST;
break;
+ case 'S':
+ openlog(progname, LOG_PID, syslog_facility(optarg));
+ verror = verror_syslog;
+ break;
case 's':
mode = RPIPE_SERVER;
break;

Return to:

Send suggestions and report system problems to the System administrator.