174dcdbcc13ef4cc22d4515198bfcfe1644fb5ab
[feed/packages.git] / net / shadowsocks-libev / patches / 0001-decouple-use_syslog-from-pid_flags.patch
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
5
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,
8 stderr output
9 ---
10 src/jconf.c | 6 ++++++
11 src/local.c | 2 +-
12 src/manager.c | 2 +-
13 src/redir.c | 2 +-
14 src/server.c | 2 +-
15 src/tunnel.c | 2 +-
16 src/utils.h | 18 +++++++++++-------
17 7 files changed, 22 insertions(+), 12 deletions(-)
18
19 diff --git a/src/jconf.c b/src/jconf.c
20 index 3c58148..05445c3 100644
21 --- a/src/jconf.c
22 +++ b/src/jconf.c
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;
27 +#ifdef HAS_SYSLOG
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;
32 +#endif
33 }
34 }
35 } else {
36 diff --git a/src/local.c b/src/local.c
37 index 78f6d29..e4bd477 100644
38 --- a/src/local.c
39 +++ b/src/local.c
40 @@ -1522,8 +1522,8 @@ main(int argc, char **argv)
41 local_addr = "127.0.0.1";
42 }
43
44 + USE_SYSLOG(argv[0], pid_flags);
45 if (pid_flags) {
46 - USE_SYSLOG(argv[0]);
47 daemonize(pid_path);
48 }
49
50 diff --git a/src/manager.c b/src/manager.c
51 index 6e7197c..338ab85 100644
52 --- a/src/manager.c
53 +++ b/src/manager.c
54 @@ -1149,8 +1149,8 @@ main(int argc, char **argv)
55 timeout = "60";
56 }
57
58 + USE_SYSLOG(argv[0], pid_flags);
59 if (pid_flags) {
60 - USE_SYSLOG(argv[0]);
61 daemonize(pid_path);
62 }
63
64 diff --git a/src/redir.c b/src/redir.c
65 index 3809411..fae8d54 100644
66 --- a/src/redir.c
67 +++ b/src/redir.c
68 @@ -1140,8 +1140,8 @@ main(int argc, char **argv)
69 #endif
70 }
71
72 + USE_SYSLOG(argv[0], pid_flags);
73 if (pid_flags) {
74 - USE_SYSLOG(argv[0]);
75 daemonize(pid_path);
76 }
77
78 diff --git a/src/server.c b/src/server.c
79 index 534dbd8..1c25c74 100644
80 --- a/src/server.c
81 +++ b/src/server.c
82 @@ -1726,8 +1726,8 @@ main(int argc, char **argv)
83 }
84 #endif
85
86 + USE_SYSLOG(argv[0], pid_flags);
87 if (pid_flags) {
88 - USE_SYSLOG(argv[0]);
89 daemonize(pid_path);
90 }
91
92 diff --git a/src/tunnel.c b/src/tunnel.c
93 index 77c7380..2419fa0 100644
94 --- a/src/tunnel.c
95 +++ b/src/tunnel.c
96 @@ -1022,8 +1022,8 @@ main(int argc, char **argv)
97 local_addr = "127.0.0.1";
98 }
99
100 + USE_SYSLOG(argv[0], pid_flags);
101 if (pid_flags) {
102 - USE_SYSLOG(argv[0]);
103 daemonize(pid_path);
104 }
105
106 diff --git a/src/utils.h b/src/utils.h
107 index 2603e85..53f3983 100644
108 --- a/src/utils.h
109 +++ b/src/utils.h
110 @@ -35,7 +35,7 @@
111
112 #include <android/log.h>
113 #define USE_TTY()
114 -#define USE_SYSLOG(ident)
115 +#define USE_SYSLOG(ident, _cond)
116 #define LOGI(...) \
117 ((void)__android_log_print(ANDROID_LOG_DEBUG, "shadowsocks", \
118 __VA_ARGS__))
119 @@ -53,7 +53,7 @@
120 extern FILE *logfile;
121 #define TIME_FORMAT "%Y-%m-%d %H:%M:%S"
122 #define USE_TTY()
123 -#define USE_SYSLOG(ident)
124 +#define USE_SYSLOG(ident, _cond)
125 #define USE_LOGFILE(ident) \
126 do { \
127 if (ident != NULL) { logfile = fopen(ident, "w+"); } } \
128 @@ -99,11 +99,15 @@ extern int use_syslog;
129 use_tty = isatty(STDERR_FILENO); \
130 } while (0)
131
132 -#define USE_SYSLOG(ident) \
133 - do { \
134 - use_syslog = 1; \
135 - openlog((ident), LOG_CONS | LOG_PID, 0); } \
136 - while (0)
137 +#define USE_SYSLOG(_ident, _cond) \
138 + do { \
139 + if (!use_syslog && (_cond)) { \
140 + use_syslog = 1; \
141 + } \
142 + if (use_syslog) { \
143 + openlog((_ident), LOG_CONS | LOG_PID, 0); \
144 + } \
145 + } while (0)
146
147 #define LOGI(format, ...) \
148 do { \
149 --
150 2.12.2
151