Merge pull request #1922 from ksqsf/master

Search XDG_CONFIG_HOME for user-specific config
This commit is contained in:
Max Lv
2018-02-11 08:17:59 +08:00
committed by GitHub
7 changed files with 31 additions and 6 deletions
-2
View File
@@ -22,8 +22,6 @@
#ifndef _COMMON_H
#define _COMMON_H
#define DEFAULT_CONF_PATH "/etc/shadowsocks-libev/config.json"
#ifndef SOL_TCP
#define SOL_TCP IPPROTO_TCP
#endif
+1 -1
View File
@@ -1424,7 +1424,7 @@ main(int argc, char **argv)
if (argc == 1) {
if (conf_path == NULL) {
conf_path = DEFAULT_CONF_PATH;
conf_path = get_default_conf();
}
}
if (conf_path != NULL) {
+1 -1
View File
@@ -989,7 +989,7 @@ main(int argc, char **argv)
if (argc == 1) {
if (conf_path == NULL) {
conf_path = DEFAULT_CONF_PATH;
conf_path = get_default_conf();
}
}
+1 -1
View File
@@ -1636,7 +1636,7 @@ main(int argc, char **argv)
if (argc == 1) {
if (conf_path == NULL) {
conf_path = DEFAULT_CONF_PATH;
conf_path = get_default_conf();
}
}
+1 -1
View File
@@ -921,7 +921,7 @@ main(int argc, char **argv)
if (argc == 1) {
if (conf_path == NULL) {
conf_path = DEFAULT_CONF_PATH;
conf_path = get_default_conf();
}
}
+25
View File
@@ -474,3 +474,28 @@ set_nofile(int nofile)
}
#endif
char *
get_default_conf(void)
{
static char sysconf[] = "/etc/shadowsocks-libev/config.json";
static char userconf[PATH_MAX] = { 0 };
char *conf_home;
conf_home = getenv("XDG_CONFIG_HOME");
if (!conf_home) {
strcpy(userconf, getenv("HOME"));
strcat(userconf, "/.config/shadowsocks-libev/config.json");
} else {
strcpy(userconf, conf_home);
strcat(userconf, "/shadowsocks-libev/config.json");
}
// Check if the user-specific config exists.
if (access(userconf, F_OK) != -1)
return userconf;
// If not, fall back to the system-wide config.
return sysconf;
}
+2
View File
@@ -173,4 +173,6 @@ void *ss_realloc(void *ptr, size_t new_size);
ptr = NULL; \
} while (0)
char *get_default_conf(void);
#endif // _UTILS_H