mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-24 17:33:46 +00:00
Merge pull request #1922 from ksqsf/master
Search XDG_CONFIG_HOME for user-specific config
This commit is contained in:
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user