1 From a91d70dd37e9555d104629538890d44ef355c772 Mon Sep 17 00:00:00 2001
2 From: Yousong Zhou <yszhou4tech@gmail.com>
3 Date: Mon, 26 Jun 2017 14:49:36 +0800
4 Subject: [PATCH 1/2] decouple use_syslog from pid_flags
6 Sometimes we need processes to run in the foreground to be supervised
7 and at the same time use syslog facility instead of logging its stdout,
10 src/jconf.c | 6 ++++++
16 src/utils.h | 18 +++++++++++-------
17 7 files changed, 22 insertions(+), 12 deletions(-)
19 diff --git a/src/jconf.c b/src/jconf.c
20 index 3c58148..05445c3 100644
23 @@ -313,6 +313,12 @@ read_jconf(const char *file)
24 check_json_value_type(value, json_boolean,
25 "invalid config file: option 'ipv6_first' must be a boolean");
26 conf.ipv6_first = value->u.boolean;
28 + } else if (strcmp(name, "use_syslog") == 0) {
29 + check_json_value_type(value, json_boolean,
30 + "invalid config file: option 'use_syslog' must be a boolean");
31 + use_syslog = value->u.boolean;
36 diff --git a/src/local.c b/src/local.c
37 index 78f6d29..e4bd477 100644
40 @@ -1522,8 +1522,8 @@ main(int argc, char **argv)
41 local_addr = "127.0.0.1";
44 + USE_SYSLOG(argv[0], pid_flags);
46 - USE_SYSLOG(argv[0]);
50 diff --git a/src/manager.c b/src/manager.c
51 index 6e7197c..338ab85 100644
54 @@ -1149,8 +1149,8 @@ main(int argc, char **argv)
58 + USE_SYSLOG(argv[0], pid_flags);
60 - USE_SYSLOG(argv[0]);
64 diff --git a/src/redir.c b/src/redir.c
65 index 3809411..fae8d54 100644
68 @@ -1140,8 +1140,8 @@ main(int argc, char **argv)
72 + USE_SYSLOG(argv[0], pid_flags);
74 - USE_SYSLOG(argv[0]);
78 diff --git a/src/server.c b/src/server.c
79 index 534dbd8..1c25c74 100644
82 @@ -1726,8 +1726,8 @@ main(int argc, char **argv)
86 + USE_SYSLOG(argv[0], pid_flags);
88 - USE_SYSLOG(argv[0]);
92 diff --git a/src/tunnel.c b/src/tunnel.c
93 index 77c7380..2419fa0 100644
96 @@ -1022,8 +1022,8 @@ main(int argc, char **argv)
97 local_addr = "127.0.0.1";
100 + USE_SYSLOG(argv[0], pid_flags);
102 - USE_SYSLOG(argv[0]);
106 diff --git a/src/utils.h b/src/utils.h
107 index 2603e85..53f3983 100644
112 #include <android/log.h>
114 -#define USE_SYSLOG(ident)
115 +#define USE_SYSLOG(ident, _cond)
117 ((void)__android_log_print(ANDROID_LOG_DEBUG, "shadowsocks", \
120 extern FILE *logfile;
121 #define TIME_FORMAT "%Y-%m-%d %H:%M:%S"
123 -#define USE_SYSLOG(ident)
124 +#define USE_SYSLOG(ident, _cond)
125 #define USE_LOGFILE(ident) \
127 if (ident != NULL) { logfile = fopen(ident, "w+"); } } \
128 @@ -99,11 +99,15 @@ extern int use_syslog;
129 use_tty = isatty(STDERR_FILENO); \
132 -#define USE_SYSLOG(ident) \
135 - openlog((ident), LOG_CONS | LOG_PID, 0); } \
137 +#define USE_SYSLOG(_ident, _cond) \
139 + if (!use_syslog && (_cond)) { \
142 + if (use_syslog) { \
143 + openlog((_ident), LOG_CONS | LOG_PID, 0); \
147 #define LOGI(format, ...) \