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
parent
commit
70daa77c90
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 6 deletions
  1. 2
      src/common.h
  2. 2
      src/local.c
  3. 2
      src/redir.c
  4. 2
      src/server.c
  5. 2
      src/tunnel.c
  6. 25
      src/utils.c
  7. 2
      src/utils.h

2
src/common.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

2
src/local.c

@ -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) {

2
src/redir.c

@ -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();
}
}

2
src/server.c

@ -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();
}
}

2
src/tunnel.c

@ -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
src/utils.c

@ -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
src/utils.h

@ -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
Loading…
Cancel
Save