Browse Source

decouple use_syslog from pid_flags

Sometimes we need processes to run in the foreground to be supervised
and at the same time use syslog facility instead of logging its stdout,
stderr output
pull/1610/head
Yousong Zhou 7 years ago
committed by Max Lv
parent
commit
db1728c76d
7 changed files with 22 additions and 12 deletions
  1. 6
      src/jconf.c
  2. 2
      src/local.c
  3. 2
      src/manager.c
  4. 2
      src/redir.c
  5. 2
      src/server.c
  6. 2
      src/tunnel.c
  7. 18
      src/utils.h

6
src/jconf.c

@ -313,6 +313,12 @@ read_jconf(const char *file)
check_json_value_type(value, json_boolean,
"invalid config file: option 'ipv6_first' must be a boolean");
conf.ipv6_first = value->u.boolean;
#ifdef HAS_SYSLOG
} else if (strcmp(name, "use_syslog") == 0) {
check_json_value_type(value, json_boolean,
"invalid config file: option 'use_syslog' must be a boolean");
use_syslog = value->u.boolean;
#endif
}
}
} else {

2
src/local.c

@ -1522,8 +1522,8 @@ main(int argc, char **argv)
local_addr = "127.0.0.1";
}
USE_SYSLOG(argv[0], pid_flags);
if (pid_flags) {
USE_SYSLOG(argv[0]);
daemonize(pid_path);
}

2
src/manager.c

@ -1149,8 +1149,8 @@ main(int argc, char **argv)
timeout = "60";
}
USE_SYSLOG(argv[0], pid_flags);
if (pid_flags) {
USE_SYSLOG(argv[0]);
daemonize(pid_path);
}

2
src/redir.c

@ -1140,8 +1140,8 @@ main(int argc, char **argv)
#endif
}
USE_SYSLOG(argv[0], pid_flags);
if (pid_flags) {
USE_SYSLOG(argv[0]);
daemonize(pid_path);
}

2
src/server.c

@ -1726,8 +1726,8 @@ main(int argc, char **argv)
}
#endif
USE_SYSLOG(argv[0], pid_flags);
if (pid_flags) {
USE_SYSLOG(argv[0]);
daemonize(pid_path);
}

2
src/tunnel.c

@ -1022,8 +1022,8 @@ main(int argc, char **argv)
local_addr = "127.0.0.1";
}
USE_SYSLOG(argv[0], pid_flags);
if (pid_flags) {
USE_SYSLOG(argv[0]);
daemonize(pid_path);
}

18
src/utils.h

@ -35,7 +35,7 @@
#include <android/log.h>
#define USE_TTY()
#define USE_SYSLOG(ident)
#define USE_SYSLOG(ident, _cond)
#define LOGI(...) \
((void)__android_log_print(ANDROID_LOG_DEBUG, "shadowsocks", \
__VA_ARGS__))
@ -53,7 +53,7 @@
extern FILE *logfile;
#define TIME_FORMAT "%Y-%m-%d %H:%M:%S"
#define USE_TTY()
#define USE_SYSLOG(ident)
#define USE_SYSLOG(ident, _cond)
#define USE_LOGFILE(ident) \
do { \
if (ident != NULL) { logfile = fopen(ident, "w+"); } } \
@ -99,11 +99,15 @@ extern int use_syslog;
use_tty = isatty(STDERR_FILENO); \
} while (0)
#define USE_SYSLOG(ident) \
do { \
use_syslog = 1; \
openlog((ident), LOG_CONS | LOG_PID, 0); } \
while (0)
#define USE_SYSLOG(_ident, _cond) \
do { \
if (!use_syslog && (_cond)) { \
use_syslog = 1; \
} \
if (use_syslog) { \
openlog((_ident), LOG_CONS | LOG_PID, 0); \
} \
} while (0)
#define LOGI(format, ...) \
do { \

Loading…
Cancel
Save