Browse Source
Merge pull request #1922 from ksqsf/master
Search XDG_CONFIG_HOME for user-specific config
pull/1929/head
Max Lv
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with
31 additions and
6 deletions
-
src/common.h
-
src/local.c
-
src/redir.c
-
src/server.c
-
src/tunnel.c
-
src/utils.c
-
src/utils.h
|
|
@ -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 |
|
|
|
|
|
@ -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) { |
|
|
|
|
|
@ -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(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -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(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -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(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -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 |