summaryrefslogtreecommitdiff
path: root/cmd/runsvc/runsvc.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-07-22 17:57:13 +0200
committerDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-07-22 17:57:20 +0200
commit056d3c8e6481088b8e5d9791d8c1762a3c8d1a83 (patch)
tree0b4ad3c59f25171c618e3dca7850544e2d619549 /cmd/runsvc/runsvc.c
parent8718c31928792c5d092eeca3d656924874a38aa1 (diff)
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 <david.oberhollenzer@tele2.at>
Diffstat (limited to 'cmd/runsvc/runsvc.c')
-rw-r--r--cmd/runsvc/runsvc.c13
1 files changed, 8 insertions, 5 deletions
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)