aboutsummaryrefslogtreecommitdiffstats
path: root/libcoopgamma_get_socket_file.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-02-10 17:50:58 +0100
committerMattias Andrée <m@maandree.se>2025-02-10 17:52:46 +0100
commitec1bcdcd0dd6e196303e8d9a30b3b2740e32c502 (patch)
treedcc759aaf897c915827659e00644f12503cf1268 /libcoopgamma_get_socket_file.c
parentImprove makefile (diff)
downloadlibcoopgamma-ec1bcdcd0dd6e196303e8d9a30b3b2740e32c502.tar.gz
libcoopgamma-ec1bcdcd0dd6e196303e8d9a30b3b2740e32c502.tar.bz2
libcoopgamma-ec1bcdcd0dd6e196303e8d9a30b3b2740e32c502.tar.xz
Minor code improvements and split into multiple c files
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'libcoopgamma_get_socket_file.c')
-rw-r--r--libcoopgamma_get_socket_file.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/libcoopgamma_get_socket_file.c b/libcoopgamma_get_socket_file.c
new file mode 100644
index 0000000..3ac9a2b
--- /dev/null
+++ b/libcoopgamma_get_socket_file.c
@@ -0,0 +1,43 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+/**
+ * Get the socket 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 socket, `NULL` on error
+ * or if there server does have its own socket. The later
+ * case is detected by checking that `errno` is set to 0,
+ * and is the case when communicating with a server in a
+ * multi-server display server like mds.
+ */
+char *
+libcoopgamma_get_socket_file(const char *restrict method, const char *restrict site)
+{
+ char *raw;
+ char *p;
+
+ raw = libcoopgamma_query__(method, site, "-qq");
+ if (!raw)
+ return NULL;
+
+ p = &strchr(raw, '\0')[-1];
+ if (p < raw || *p != '\n') {
+ errno = EBADMSG;
+ goto fail;
+ }
+ *p = '\0';
+ if (!*raw) {
+ errno = EBADMSG;
+ goto fail;
+ }
+
+ return raw;
+fail:
+ free(raw);
+ return NULL;
+}