aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-10 22:58:48 +0200
committerMattias Andrée <maandree@kth.se>2016-07-10 22:58:51 +0200
commit9d69ef256acf195de064859a65aa033fcf06295d (patch)
tree5cee2e1bc8eb89521603d0135e51fb4f98f94a54 /src
parentFix warnings (and two errors) (diff)
downloadcoopgammad-9d69ef256acf195de064859a65aa033fcf06295d.tar.gz
coopgammad-9d69ef256acf195de064859a65aa033fcf06295d.tar.bz2
coopgammad-9d69ef256acf195de064859a65aa033fcf06295d.tar.xz
Get the pathname of the socket
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r--src/gammad.c70
-rw-r--r--src/ramps.c2
2 files changed, 68 insertions, 4 deletions
diff --git a/src/gammad.c b/src/gammad.c
index 78318f6..7edc119 100644
--- a/src/gammad.c
+++ b/src/gammad.c
@@ -18,29 +18,93 @@
#include <libgamma.h>
#include <errno.h>
+#include <pwd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include "output.h"
+#include "util.h"
/**
* The name of the process
*/
-char* argv0;
+const char* argv0;
/**
+ * Get the pathname of the socket
+ *
+ * @param site The site
+ * @return The pathname of the socket
+ */
+static char* get_socket_pathname(libgamma_site_state_t* site)
+{
+ const char* rundir = getenv("XDG_RUNTIME_DIR");
+ const char* username = "";
+ char* name = NULL;
+ char* p;
+ char* rc;
+ struct passwd* pw;
+ size_t n;
+
+ if (site->site)
+ {
+ name = memdup(site->site, strlen(site->site) + 1);
+ if (name == NULL)
+ goto fail;
+ }
+ else if ((name = libgamma_method_default_site(site->method)))
+ {
+ name = memdup(name, strlen(name) + 1);
+ if (name == NULL)
+ goto fail;
+ }
+
+ if (name != NULL)
+ switch (site->method)
+ {
+ case LIBGAMMA_METHOD_X_RANDR:
+ case LIBGAMMA_METHOD_X_VIDMODE:
+ if ((p = strrchr(name, ':')))
+ if ((p = strchr(p, '.')))
+ *p = '\0';
+ default:
+ break;
+ }
+
+ if (!rundir || !*rundir)
+ rundir = "/tmp";
+
+ if ((pw = getpwuid(getuid())))
+ username = pw->pw_name ? pw->pw_name : "";
+
+ n = sizeof("%s/.gammad/~%s/%i%s%s") + 3 * sizeof(int);
+ n += strlen(rundir) + strlen(username) + strlen(name);
+ if (!(rc = malloc(n)))
+ goto fail;
+ sprintf(rc, "%s/.gammad/~%s/%i%s%s",
+ rundir, username, site->method, name ? "." : "", name ? name : "");
+ return rc;
+
+ fail:
+ free(name);
+ return NULL;
+}
+
+
+/**
* Get the name of a CRTC
*
* @param info Information about the CRTC
* @param crtc libgamma's state for the CRTC
* @return The name of the CRTC, `NULL` on error
*/
-static char* get_name(libgamma_crtc_information_t* info, libgamma_crtc_state_t* crtc)
+static char* get_crtc_name(libgamma_crtc_information_t* info, libgamma_crtc_state_t* crtc)
{
if ((info->edid_error == 0) && (info->edid != NULL))
return libgamma_behex_edid(info->edid, info->edid_length);
@@ -125,7 +189,7 @@ int main(int argc, char** argv)
outputs[i].green_size == 0 ||
outputs[i].blue_size == 0)
outputs[i].supported = 0;
- outputs[i].name = get_name(&info, crtcs + i);
+ outputs[i].name = get_crtc_name(&info, crtcs + i);
saved_errno = errno;
outputs[i].crtc = crtcs + i;
libgamma_crtc_information_destroy(&info);
diff --git a/src/ramps.c b/src/ramps.c
index 2c24b52..0bd2b78 100644
--- a/src/ramps.c
+++ b/src/ramps.c
@@ -26,7 +26,7 @@
/**
* The name of the process
*/
-extern char* argv0;
+extern const char* argv0;