From ae24bac0bc9cea34862920000a6f812ee4e47b50 Mon Sep 17 00:00:00 2001 From: Henk Kalkwater Date: Tue, 8 Dec 2020 08:19:20 +0100 Subject: [PATCH] Install and write pidfile --- CMakeLists.txt | 1 + src/kerstezel.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a0e6656..3c9c66d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/kerstezel.c b/src/kerstezel.c index 7726afb..9a3e9af 100644 --- a/src/kerstezel.c +++ b/src/kerstezel.c @@ -7,8 +7,10 @@ #include #include +#include #include #include +#include #include #include @@ -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);