Install and write pidfile

This commit is contained in:
Chris Josten 2020-12-08 08:19:20 +01:00
parent 9a1a9f35fd
commit ae24bac0bc
2 changed files with 12 additions and 0 deletions

View file

@ -12,3 +12,4 @@ set(KERSTEZEL_SOURCES src/kerstezel.c)
set(KERSTEZEL_HEADERS src/kerstezel.h)
add_executable(kerstezel ${KERSTEZEL_SOURCES} ${KERSTEZEL_HEADERS})
install(TARGETS kerstezel DESTINATION sbin)

View file

@ -7,8 +7,10 @@
#include <stdio.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/prctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <unistd.h>
#include <linux/seccomp.h>
@ -36,6 +38,7 @@ typedef struct mbuf {
} mbuf_t;
const char *pid_path = "/run/kerstezel.pid";
const char *log_path = "/var/log/kerstman.log";
FILE *log_file = NULL;
@ -196,6 +199,14 @@ int main(int argc, char *argv[]) {
// Kan niet loggen lol
exit(EXIT_FAILURE);
}
// WRITE PIDFILE
FILE *fd = fopen(pid_path, "w");
if (fd != NULL) {
fprintf(fd, "%d", getpid());
fclose(fd);
}
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);