From 00c2eb503ec6b6203418f87f0916c47b8127fe62 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 11 Jul 2016 12:06:59 +0200 Subject: Add get_pidfile_pathname MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/gammad.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gammad.c b/src/gammad.c index 7ec7fcf..28411cf 100644 --- a/src/gammad.c +++ b/src/gammad.c @@ -48,12 +48,13 @@ size_t outputs_n = 0; /** - * Get the pathname of the socket + * Get the pathname of the runtime file * - * @param site The site - * @return The pathname of the socket, `NULL` on error + * @param site The site + * @param suffix The suffix for the file + * @return The pathname of the file, `NULL` on error */ -static char* get_socket_pathname(libgamma_site_state_t* site) +static char* get_pathname(libgamma_site_state_t* site, const char* suffix) { const char* rundir = getenv("XDG_RUNTIME_DIR"); const char* username = ""; @@ -94,12 +95,12 @@ static char* get_socket_pathname(libgamma_site_state_t* site) if ((pw = getpwuid(getuid()))) username = pw->pw_name ? pw->pw_name : ""; - n = sizeof("/.gammad/~/..socket") + 3 * sizeof(int); - n += strlen(rundir) + strlen(username) + strlen(name); + n = sizeof("/.gammad/~/.") + 3 * sizeof(int); + n += strlen(rundir) + strlen(username) + strlen(name) + strlen(suffix); if (!(rc = malloc(n))) goto fail; - sprintf(rc, "%s/.gammad/~%s/%i%s%s.socket", - rundir, username, site->method, name ? "." : "", name ? name : ""); + sprintf(rc, "%s/.gammad/~%s/%i%s%s%s", + rundir, username, site->method, name ? "." : "", name ? name : "", suffix); return rc; fail: @@ -108,6 +109,30 @@ static char* get_socket_pathname(libgamma_site_state_t* site) } +/** + * Get the pathname of the socket + * + * @param site The site + * @return The pathname of the socket, `NULL` on error + */ +static inline char* get_socket_pathname(libgamma_site_state_t* site) +{ + return get_pathname(site, ".socket"); +} + + +/** + * Get the pathname of the PID file + * + * @param site The site + * @return The pathname of the PID file, `NULL` on error + */ +static inline char* get_pidfile_pathname(libgamma_site_state_t* site) +{ + return get_pathname(site, ".pid"); +} + + /** * Parse adjustment method name (or stringised number) * -- cgit v1.2.3-70-g09d2