about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2018-06-22 16:13:51 +0200
committerDuncaen <mail@duncano.de>2018-06-22 16:53:50 +0200
commit895727940f54d7eaa72765cfdb28d4d1fa652651 (patch)
treeab973cbc478557aeab03b99226a5cde884f09bee
parent999b1ba166f508aa950adbe0445b0ac847971173 (diff)
downloadrunit-void-895727940f54d7eaa72765cfdb28d4d1fa652651.tar.gz
runit-void-895727940f54d7eaa72765cfdb28d4d1fa652651.tar.xz
runit-void-895727940f54d7eaa72765cfdb28d4d1fa652651.zip
vlogger: use static buffer and add -f flag
-rw-r--r--vlogger.833
-rw-r--r--vlogger.c22
2 files changed, 30 insertions, 25 deletions
diff --git a/vlogger.8 b/vlogger.8
index aa7780f..4a9b19d 100644
--- a/vlogger.8
+++ b/vlogger.8
@@ -7,6 +7,7 @@
 .Sh SYNOPSIS
 .Nm vlogger
 .Op Fl isS
+.Op Fl f Ar file
 .Op Fl p Ar pri
 .Op Fl t Ar tag
 .Sh DESCRIPTION
@@ -40,20 +41,10 @@ as default
 .Pp
 The options are as follows:
 .Bl -tag -width indent
-.It Fl S
-Force
-.Nm
-to use
-.Xr syslog 3
-even if
-.Pa /etc/vlogger
-exists.
-.It Fl s
-Output the message to standard error, as well as
-.Xr syslog 3 .
-Only supported if
-.Xr syslog 3
-is used.
+.It Fl f Ar file
+Read lines from the specified
+.Ar file .
+This
 .It Fl i
 Log the PID of the
 .Nm
@@ -75,6 +66,20 @@ or
 .Xr syslog 3 .
 The default is
 .Pa daemon.info .
+.It Fl S
+Force
+.Nm
+to use
+.Xr syslog 3
+even if
+.Pa /etc/vlogger
+exists.
+.It Fl s
+Output the message to standard error, as well as
+.Xr syslog 3 .
+Only supported if
+.Xr syslog 3
+is used.
 .It Fl t Ar tag
 Defines the
 .Xr openlog 3
diff --git a/vlogger.c b/vlogger.c
index e3a548e..aaf569b 100644
--- a/vlogger.c
+++ b/vlogger.c
@@ -76,6 +76,7 @@ strpriority(char *s, int *facility, int *level)
 int
 main(int argc, char *argv[])
 {
+	char buf[1024];
 	char *p, *argv0;
 	char *tag = "vlogger";
 	int c;
@@ -98,16 +99,21 @@ main(int argc, char *argv[])
 		}
 	}
 
-	while ((c = getopt(argc, argv, "ip:Sst:")) != -1)
+	while ((c = getopt(argc, argv, "f:ip:Sst:")) != -1)
 		switch (c) {
+		case 'f':
+			if (freopen(optarg, "r", stdin) == NULL) {
+				fprintf(stderr, "vlogger: %s: %s\n", optarg, strerror(errno));
+				return 1;
+			}
+			break;
 		case 'i': logflags |= LOG_PID; break;
 		case 'p': strpriority(optarg, &facility, &level); break;
 		case 'S': Sflag++; break;
 		case 's': logflags |= LOG_PERROR; break;
 		case 't': tag = optarg; break;
 		default:
-usage:
-			fprintf(stderr, "usage: vlogger [-isS] [-p pri] [-t tag]\n");
+			fprintf(stderr, "usage: vlogger [-isS] [-f file] [-p pri] [-t tag]\n");
 			exit(1);
 		}
 
@@ -129,14 +135,8 @@ usage:
 
 	openlog(tag, logflags, facility);
 
-	char *line = NULL;
-	size_t linelen = 0;
-	ssize_t rd;
-	while ((rd = getline(&line, &linelen, stdin)) != -1) {
-		if (line[rd-1] == '\n')
-			line[rd-1] = '\0';
-		syslog(level|facility, "%s", line);
-	}
+	while (fgets(buf, sizeof buf, stdin) != NULL)
+		syslog(level|facility, "%s", buf);
 
 	return 1;
 }