aboutgitcodebugslistschat
path: root/passt.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-10-14 12:17:47 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-10-14 13:20:34 +0200
commit54a19002df18d2f19fc455c9b1ef9f88b96b7bd1 (patch)
tree20bba67589f85a708f626273979dae26a8530774 /passt.c
parent1cbd2c8c6b3a564aba84abcd20f05c5c646d2fb4 (diff)
downloadpasst-54a19002df18d2f19fc455c9b1ef9f88b96b7bd1.tar
passt-54a19002df18d2f19fc455c9b1ef9f88b96b7bd1.tar.gz
passt-54a19002df18d2f19fc455c9b1ef9f88b96b7bd1.tar.bz2
passt-54a19002df18d2f19fc455c9b1ef9f88b96b7bd1.tar.lz
passt-54a19002df18d2f19fc455c9b1ef9f88b96b7bd1.tar.xz
passt-54a19002df18d2f19fc455c9b1ef9f88b96b7bd1.tar.zst
passt-54a19002df18d2f19fc455c9b1ef9f88b96b7bd1.zip
conf: Add -P, --pid, to specify a file where own PID is written to
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'passt.c')
-rw-r--r--passt.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/passt.c b/passt.c
index 48c2649..2217dd7 100644
--- a/passt.c
+++ b/passt.c
@@ -228,6 +228,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
* @argv: Options, plus optional target PID for pasta mode
@@ -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);