aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/config-ini.c78
-rw-r--r--src/redshift-gtk/statusicon.py3
-rw-r--r--src/redshift-gtk/utils.py14
-rw-r--r--src/redshift.c2
4 files changed, 86 insertions, 11 deletions
diff --git a/src/config-ini.c b/src/config-ini.c
index 4541a0f..65751dd 100644
--- a/src/config-ini.c
+++ b/src/config-ini.c
@@ -22,6 +22,12 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#ifndef _WIN32
+# include <pwd.h>
+#endif
#include "config-ini.h"
@@ -41,33 +47,79 @@ open_config_file(const char *filepath)
{
FILE *f = NULL;
+ /* If a path is not specified (filepath is NULL) then
+ the configuration file is searched for in the directories
+ specified by the XDG Base Directory Specification
+ <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>.
+
+ If HOME is not set, getpwuid() is consulted for the home directory. On
+ windows platforms the %localappdata% is used in place of XDG_CONFIG_HOME.
+ */
+
if (filepath == NULL) {
+ FILE *f = NULL;
char cp[MAX_CONFIG_PATH];
char *env;
- if ((env = getenv("XDG_CONFIG_HOME")) != NULL &&
+ if (f == NULL && (env = getenv("XDG_CONFIG_HOME")) != NULL &&
env[0] != '\0') {
snprintf(cp, sizeof(cp), "%s/redshift.conf", env);
- filepath = cp;
+ f = fopen(cp, "r");
+ }
+
#ifdef _WIN32
- } else if ((env = getenv("localappdata")) != NULL && env[0] != '\0') {
+ if (f == NULL && (env = getenv("localappdata")) != NULL &&
+ env[0] != '\0') {
snprintf(cp, sizeof(cp),
"%s\\redshift.conf", env);
- filepath = cp;
+ f = fopen(cp, "r");
+ }
#endif
- } else if ((env = getenv("HOME")) != NULL && env[0] != '\0') {
+ if (f == NULL && (env = getenv("HOME")) != NULL &&
+ env[0] != '\0') {
snprintf(cp, sizeof(cp),
"%s/.config/redshift.conf", env);
- filepath = cp;
+ f = fopen(cp, "r");
}
+#ifndef _WIN32
- if (filepath != NULL) {
- f = fopen(filepath, "r");
- if (f != NULL) return f;
- else if (f == NULL && errno != ENOENT) return NULL;
+ if (f == NULL) {
+ struct passwd *pwd = getpwuid(getuid());
+ char *home = pwd->pw_dir;
+ snprintf(cp, sizeof(cp),
+ "%s/.config/redshift.conf", home);
+ f = fopen(cp, "r");
}
- /* TODO look in getenv("XDG_CONFIG_DIRS") */
+ if (f == NULL && (env = getenv("XDG_CONFIG_DIRS")) != NULL &&
+ env[0] != '\0') {
+ char *begin = env;
+ while (1) {
+ char *end = strchr(begin, ':');
+ if (end == NULL) end = strchr(begin, '\0');
+
+ int len = end - begin;
+ if (len > 0) {
+ snprintf(cp, sizeof(cp),
+ "%.*s/redshift.conf", len, begin);
+
+ f = fopen(cp, "r");
+ if (f != NULL) break;
+ }
+
+ if (end[0] == '\0') break;
+ begin = end + 1;
+ }
+ }
+
+ if (f == NULL) {
+ snprintf(cp, sizeof(cp),
+ "%s/redshift.conf", "/etc");
+ f = fopen(cp, "r");
+ }
+#endif
+
+ return f;
} else {
f = fopen(filepath, "r");
if (f == NULL) {
@@ -216,15 +268,19 @@ config_ini_free(config_ini_state_t *state)
while (section != NULL) {
config_ini_setting_t *setting = section->settings;
+ config_ini_section_t *section_prev = section;
while (setting != NULL) {
+ config_ini_setting_t *setting_prev = setting;
free(setting->name);
free(setting->value);
setting = setting->next;
+ free(setting_prev);
}
free(section->name);
section = section->next;
+ free(section_prev);
}
}
diff --git a/src/redshift-gtk/statusicon.py b/src/redshift-gtk/statusicon.py
index 6174aec..6877eac 100644
--- a/src/redshift-gtk/statusicon.py
+++ b/src/redshift-gtk/statusicon.py
@@ -316,7 +316,10 @@ class RedshiftStatusIcon(object):
os.kill(self.process[0], signal.SIGINT)
os.waitpid(self.process[0], 0)
+
def run():
+ utils.setproctitle('redshift-gtk')
+
# Internationalisation
gettext.bindtextdomain('redshift', defs.LOCALEDIR)
gettext.textdomain('redshift')
diff --git a/src/redshift-gtk/utils.py b/src/redshift-gtk/utils.py
index 723d4d8..4d3b619 100644
--- a/src/redshift-gtk/utils.py
+++ b/src/redshift-gtk/utils.py
@@ -17,7 +17,9 @@
# Copyright (c) 2010 Francesco Marella <francesco.marella@gmail.com>
# Copyright (c) 2011 Jon Lund Steffensen <jonlst@gmail.com>
+import ctypes
import os
+import sys
from xdg import BaseDirectory as base
from xdg import DesktopEntry as desktop
@@ -62,3 +64,15 @@ def set_autostart(active):
for key, values in AUTOSTART_KEYS:
dfile.set(key, values[active])
dfile.write(filename=path)
+
+
+def setproctitle(title):
+ try:
+ libc = ctypes.cdll.LoadLibrary("libc.so.6")
+ except OSError:
+ return
+ buf = ctypes.create_string_buffer(title.encode(sys.getdefaultencoding()))
+ try:
+ libc.prctl(15, ctypes.byref(buf), 0, 0, 0)
+ except AttributeError:
+ return # Strange libc, just skip this
diff --git a/src/redshift.c b/src/redshift.c
index af76e67..e4143fc 100644
--- a/src/redshift.c
+++ b/src/redshift.c
@@ -1089,6 +1089,8 @@ main(int argc, char *argv[])
}
}
+ config_ini_free(&config_state);
+
switch (mode) {
case PROGRAM_MODE_ONE_SHOT:
case PROGRAM_MODE_PRINT: