aboutsummaryrefslogtreecommitdiffstats
path: root/src/gammad.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-11 12:06:59 +0200
committerMattias Andrée <maandree@kth.se>2016-07-11 12:06:59 +0200
commit00c2eb503ec6b6203418f87f0916c47b8127fe62 (patch)
tree6d5f44a66ab88578386d51d56756fd30598a6e6e /src/gammad.c
parentm (diff)
downloadcoopgammad-00c2eb503ec6b6203418f87f0916c47b8127fe62.tar.gz
coopgammad-00c2eb503ec6b6203418f87f0916c47b8127fe62.tar.bz2
coopgammad-00c2eb503ec6b6203418f87f0916c47b8127fe62.tar.xz
Add get_pidfile_pathname
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/gammad.c')
-rw-r--r--src/gammad.c41
1 files changed, 33 insertions, 8 deletions
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:
@@ -109,6 +110,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)
*
* @param arg The adjustment method name (or stringised number)