From ec1bcdcd0dd6e196303e8d9a30b3b2740e32c502 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 10 Feb 2025 17:50:58 +0100 Subject: Minor code improvements and split into multiple c files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libcoopgamma_get_pid_file.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 libcoopgamma_get_pid_file.c (limited to 'libcoopgamma_get_pid_file.c') diff --git a/libcoopgamma_get_pid_file.c b/libcoopgamma_get_pid_file.c new file mode 100644 index 0000000..45afd1b --- /dev/null +++ b/libcoopgamma_get_pid_file.c @@ -0,0 +1,35 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +/** + * Get the PID file of the coopgamma server + * + * SIGCHLD must not be ignored or blocked + * + * @param method The adjustment method, `NULL` for automatic + * @param site The site, `NULL` for automatic + * @return The pathname of the server's PID file, `NULL` on error + * or if there server does not use PID files. The later + * case is detected by checking that `errno` is set to 0. + */ +char * +libcoopgamma_get_pid_file(const char *restrict method, const char *restrict site) +{ + char *path; + size_t n; + + path = libcoopgamma_get_socket_file(method, site); + if (!path) + return NULL; + + n = strlen(path); + if (n < 7U || strcmp(&path[n - 7U], ".socket")) { + free(path); + errno = EBADMSG; + return NULL; + } + + stpcpy(&path[n - 7U], ".pid"); + return path; +} -- cgit v1.2.3-70-g09d2