From 056d3c8e6481088b8e5d9791d8c1762a3c8d1a83 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 22 Jul 2018 17:57:13 +0200 Subject: Add output truncation flag This commit adds a "truncate" flag that can be added to a service description between the "tty" keyword and the path string. If the flag is set, the output file is truncated to 0 after opening. This probably requires some remodeling in the future as the tty keyword no longer deals with just tty devices. Signed-off-by: David Oberhollenzer --- cmd/runsvc/runsvc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'cmd/runsvc/runsvc.c') diff --git a/cmd/runsvc/runsvc.c b/cmd/runsvc/runsvc.c index a8e5bb2..9e646e7 100644 --- a/cmd/runsvc/runsvc.c +++ b/cmd/runsvc/runsvc.c @@ -17,17 +17,20 @@ */ #include "runsvc.h" -static int setup_tty(const char *ctty) +static int setup_tty(service_t *svc) { int fd; - if (ctty != NULL) { - fd = open(ctty, O_RDWR); + if (svc->ctty != NULL) { + fd = open(svc->ctty, O_RDWR); if (fd < 0) { - perror(ctty); + perror(svc->ctty); return -1; } + if (svc->flags & SVC_FLAG_TRUNCATE_OUT) + ftruncate(fd, 0); + close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); @@ -125,7 +128,7 @@ int main(int argc, char **argv) if (initenv()) goto out; - if (setup_tty(svc->ctty)) + if (setup_tty(svc)) goto out; if (svc->exec->next == NULL) -- cgit v1.2.3