mirror of
https://passt.top/passt
synced 2025-06-10 17:45:34 +02:00
conf: Add -P, --pid, to specify a file where own PID is written to
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
1cbd2c8c6b
commit
54a19002df
4 changed files with 48 additions and 3 deletions
25
passt.c
25
passt.c
|
@ -227,6 +227,27 @@ static void drop_caps(void)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pid_file() - Write own PID to file, if configured
|
||||
* @c: Execution context
|
||||
*/
|
||||
static void pid_file(struct ctx *c) {
|
||||
char pid_buf[12];
|
||||
int pid_fd, n;
|
||||
|
||||
if (!c->pid_file)
|
||||
return;
|
||||
|
||||
pid_fd = open(c->pid_file, O_CREAT | O_WRONLY);
|
||||
if (pid_fd < 0)
|
||||
return;
|
||||
|
||||
n = snprintf(pid_buf, sizeof(pid_buf), "%i\n", getpid());
|
||||
|
||||
write(pid_fd, pid_buf, n);
|
||||
close(pid_fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* main() - Entry point and main loop
|
||||
* @argc: Argument count
|
||||
|
@ -237,7 +258,7 @@ static void drop_caps(void)
|
|||
* #syscalls read write open close fork dup2 exit chdir ioctl writev syslog
|
||||
* #syscalls prlimit64 epoll_ctl epoll_create1 epoll_wait accept4 accept listen
|
||||
* #syscalls socket bind connect getsockopt setsockopt recvfrom sendto shutdown
|
||||
* #syscalls openat fstat fcntl lseek clone setsid exit_group
|
||||
* #syscalls openat fstat fcntl lseek clone setsid exit_group getpid
|
||||
* #syscalls:pasta rt_sigreturn
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
|
@ -327,6 +348,8 @@ int main(int argc, char **argv)
|
|||
if (isatty(fileno(stdout)) && !c.foreground)
|
||||
daemon(0, 0);
|
||||
|
||||
pid_file(&c);
|
||||
|
||||
timer_init(&c, &now);
|
||||
loop:
|
||||
nfds = epoll_wait(c.epollfd, events, EPOLL_EVENTS, TIMER_INTERVAL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue