mirror of
https://github.com/pygos/init.git
synced 2024-11-22 03:09:46 +01:00
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>
This commit is contained in:
parent
8718c31928
commit
056d3c8e64
3 changed files with 22 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -51,6 +51,11 @@ enum {
|
|||
RDSVC_NO_DEPS = 0x08, /* do not store dependencies */
|
||||
};
|
||||
|
||||
enum {
|
||||
/* truncate stdout */
|
||||
SVC_FLAG_TRUNCATE_OUT = 0x01,
|
||||
};
|
||||
|
||||
typedef struct exec_t {
|
||||
struct exec_t *next;
|
||||
int argc; /* number of elements in argument vector */
|
||||
|
@ -67,6 +72,7 @@ typedef struct service_t {
|
|||
char *desc; /* description string */
|
||||
char *ctty; /* controlling tty or log file */
|
||||
int rspwn_limit; /* maximum respawn count */
|
||||
unsigned int flags; /* SVC_FLAG_* bit field */
|
||||
|
||||
/* linked list of command lines to execute */
|
||||
exec_t *exec;
|
||||
|
|
|
@ -70,8 +70,16 @@ static int svc_desc(service_t *svc, char *arg, rdline_t *rd)
|
|||
|
||||
static int svc_tty(service_t *svc, char *arg, rdline_t *rd)
|
||||
{
|
||||
if (strncmp(arg, "truncate", 8) == 0 && isspace(arg[8])) {
|
||||
svc->flags |= SVC_FLAG_TRUNCATE_OUT;
|
||||
arg += 8;
|
||||
while (isspace(*arg))
|
||||
++arg;
|
||||
}
|
||||
|
||||
if (try_unescape(arg, rd))
|
||||
return -1;
|
||||
|
||||
svc->ctty = try_strdup(arg, rd);
|
||||
return svc->ctty == NULL ? -1 : 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue