diff options
Diffstat (limited to 'other/bootstrap_daemon')
-rw-r--r-- | other/bootstrap_daemon/Makefile.inc | 4 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/log.c | 2 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/log.h | 6 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/tox-bootstrapd.c | 164 |
4 files changed, 90 insertions, 86 deletions
diff --git a/other/bootstrap_daemon/Makefile.inc b/other/bootstrap_daemon/Makefile.inc index f274aba0..eb94f0e7 100644 --- a/other/bootstrap_daemon/Makefile.inc +++ b/other/bootstrap_daemon/Makefile.inc | |||
@@ -3,7 +3,9 @@ if BUILD_DHT_BOOTSTRAP_DAEMON | |||
3 | bin_PROGRAMS += tox-bootstrapd | 3 | bin_PROGRAMS += tox-bootstrapd |
4 | 4 | ||
5 | tox_bootstrapd_SOURCES = \ | 5 | tox_bootstrapd_SOURCES = \ |
6 | ../other/bootstrap_daemon/tox-bootstrapd.c | 6 | ../other/bootstrap_daemon/src/tox-bootstrapd.c \ |
7 | ../other/bootstrap_daemon/src/log.c \ | ||
8 | ../other/bootstrap_daemon/src/log.h | ||
7 | 9 | ||
8 | tox_bootstrapd_CFLAGS = \ | 10 | tox_bootstrapd_CFLAGS = \ |
9 | -I$(top_srcdir)/other/bootstrap_daemon \ | 11 | -I$(top_srcdir)/other/bootstrap_daemon \ |
diff --git a/other/bootstrap_daemon/src/log.c b/other/bootstrap_daemon/src/log.c index dff2dbad..b5f838fb 100644 --- a/other/bootstrap_daemon/src/log.c +++ b/other/bootstrap_daemon/src/log.c | |||
@@ -95,7 +95,7 @@ void log_stdout(LOG_LEVEL level, const char *format, va_list args) | |||
95 | vfprintf(level_stdout(level), format, args); | 95 | vfprintf(level_stdout(level), format, args); |
96 | } | 96 | } |
97 | 97 | ||
98 | bool log(LOG_LEVEL level, const char *format, ...) | 98 | bool write_log(LOG_LEVEL level, const char *format, ...) |
99 | { | 99 | { |
100 | va_list args; | 100 | va_list args; |
101 | va_start(args, format); | 101 | va_start(args, format); |
diff --git a/other/bootstrap_daemon/src/log.h b/other/bootstrap_daemon/src/log.h index 7e5dce99..b97d3733 100644 --- a/other/bootstrap_daemon/src/log.h +++ b/other/bootstrap_daemon/src/log.h | |||
@@ -24,6 +24,8 @@ | |||
24 | #ifndef LOG_H | 24 | #ifndef LOG_H |
25 | #define LOG_H | 25 | #define LOG_H |
26 | 26 | ||
27 | #include <stdbool.h> | ||
28 | |||
27 | typedef enum LOGGER_BACKEND { | 29 | typedef enum LOGGER_BACKEND { |
28 | LOGGER_BACKEND_SYSLOG, | 30 | LOGGER_BACKEND_SYSLOG, |
29 | LOGGER_BACKEND_STDOUT | 31 | LOGGER_BACKEND_STDOUT |
@@ -49,13 +51,13 @@ bool open_log(LOGGER_BACKEND backend); | |||
49 | bool close_log(); | 51 | bool close_log(); |
50 | 52 | ||
51 | /** | 53 | /** |
52 | * Logs a message. | 54 | * Writes a message to the log. |
53 | * @param level Log level to use. | 55 | * @param level Log level to use. |
54 | * @param format printf-like format string. | 56 | * @param format printf-like format string. |
55 | * @param ... Zero or more arguments, similar to printf function. | 57 | * @param ... Zero or more arguments, similar to printf function. |
56 | * @return true on success, flase if log is closed. | 58 | * @return true on success, flase if log is closed. |
57 | */ | 59 | */ |
58 | bool log(LOG_LEVEL level, const char *format, ...); | 60 | bool write_log(LOG_LEVEL level, const char *format, ...); |
59 | 61 | ||
60 | 62 | ||
61 | #endif // LOG_H | 63 | #endif // LOG_H |
diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 71b1386d..9a4ccf9f 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c | |||
@@ -51,9 +51,9 @@ | |||
51 | #include "../bootstrap_node_packets.c" | 51 | #include "../bootstrap_node_packets.c" |
52 | #include "../../testing/misc_tools.c" | 52 | #include "../../testing/misc_tools.c" |
53 | 53 | ||
54 | #include "global.h" | ||
55 | #include "log.h" | ||
54 | 56 | ||
55 | #define DAEMON_NAME "tox-bootstrapd" | ||
56 | #define DAEMON_VERSION_NUMBER 2014101200UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day | ||
57 | 57 | ||
58 | #define SLEEP_TIME_MILLISECONDS 30 | 58 | #define SLEEP_TIME_MILLISECONDS 30 |
59 | #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) | 59 | #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) |
@@ -136,15 +136,15 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
136 | config_setting_t *ports_array = config_lookup(cfg, NAME_TCP_RELAY_PORTS); | 136 | config_setting_t *ports_array = config_lookup(cfg, NAME_TCP_RELAY_PORTS); |
137 | 137 | ||
138 | if (ports_array == NULL) { | 138 | if (ports_array == NULL) { |
139 | syslog(LOG_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS); | 139 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS); |
140 | syslog(LOG_WARNING, "Using default '%s':\n", NAME_TCP_RELAY_PORTS); | 140 | write_log(LOG_LEVEL_WARNING, "Using default '%s':\n", NAME_TCP_RELAY_PORTS); |
141 | 141 | ||
142 | uint16_t default_ports[DEFAULT_TCP_RELAY_PORTS_COUNT] = {DEFAULT_TCP_RELAY_PORTS}; | 142 | uint16_t default_ports[DEFAULT_TCP_RELAY_PORTS_COUNT] = {DEFAULT_TCP_RELAY_PORTS}; |
143 | 143 | ||
144 | int i; | 144 | int i; |
145 | 145 | ||
146 | for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { | 146 | for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { |
147 | syslog(LOG_INFO, "Port #%d: %u\n", i, default_ports[i]); | 147 | write_log(LOG_LEVEL_INFO, "Port #%d: %u\n", i, default_ports[i]); |
148 | } | 148 | } |
149 | 149 | ||
150 | // similar procedure to the one of reading config file below | 150 | // similar procedure to the one of reading config file below |
@@ -156,7 +156,7 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
156 | 156 | ||
157 | if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT | 157 | if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT |
158 | || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { | 158 | || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { |
159 | syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, | 159 | write_log(LOG_LEVEL_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, |
160 | (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); | 160 | (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); |
161 | continue; | 161 | continue; |
162 | } | 162 | } |
@@ -176,7 +176,7 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
176 | } | 176 | } |
177 | 177 | ||
178 | if (config_setting_is_array(ports_array) == CONFIG_FALSE) { | 178 | if (config_setting_is_array(ports_array) == CONFIG_FALSE) { |
179 | syslog(LOG_ERR, "'%s' setting should be an array. Array syntax: 'setting = [value1, value2, ...]'.\n", | 179 | write_log(LOG_LEVEL_ERROR, "'%s' setting should be an array. Array syntax: 'setting = [value1, value2, ...]'.\n", |
180 | NAME_TCP_RELAY_PORTS); | 180 | NAME_TCP_RELAY_PORTS); |
181 | return; | 181 | return; |
182 | } | 182 | } |
@@ -184,7 +184,7 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
184 | int config_port_count = config_setting_length(ports_array); | 184 | int config_port_count = config_setting_length(ports_array); |
185 | 185 | ||
186 | if (config_port_count == 0) { | 186 | if (config_port_count == 0) { |
187 | syslog(LOG_ERR, "'%s' is empty.\n", NAME_TCP_RELAY_PORTS); | 187 | write_log(LOG_LEVEL_ERROR, "'%s' is empty.\n", NAME_TCP_RELAY_PORTS); |
188 | return; | 188 | return; |
189 | } | 189 | } |
190 | 190 | ||
@@ -197,12 +197,12 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
197 | 197 | ||
198 | if (elem == NULL) { | 198 | if (elem == NULL) { |
199 | // it's NULL if `ports_array` is not an array (we have that check earlier) or if `i` is out of range, which should not be | 199 | // it's NULL if `ports_array` is not an array (we have that check earlier) or if `i` is out of range, which should not be |
200 | syslog(LOG_WARNING, "Port #%d: Something went wrong while parsing the port. Stopping reading ports.\n", i); | 200 | write_log(LOG_LEVEL_WARNING, "Port #%d: Something went wrong while parsing the port. Stopping reading ports.\n", i); |
201 | break; | 201 | break; |
202 | } | 202 | } |
203 | 203 | ||
204 | if (config_setting_is_number(elem) == CONFIG_FALSE) { | 204 | if (config_setting_is_number(elem) == CONFIG_FALSE) { |
205 | syslog(LOG_WARNING, "Port #%d: Not a number. Skipping.\n", i); | 205 | write_log(LOG_LEVEL_WARNING, "Port #%d: Not a number. Skipping.\n", i); |
206 | continue; | 206 | continue; |
207 | } | 207 | } |
208 | 208 | ||
@@ -210,7 +210,7 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
210 | 210 | ||
211 | if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT | 211 | if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT |
212 | || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { | 212 | || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { |
213 | syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, | 213 | write_log(LOG_LEVEL_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, |
214 | (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); | 214 | (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); |
215 | continue; | 215 | continue; |
216 | } | 216 | } |
@@ -257,15 +257,15 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
257 | 257 | ||
258 | // Read the file. If there is an error, report it and exit. | 258 | // Read the file. If there is an error, report it and exit. |
259 | if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) { | 259 | if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) { |
260 | syslog(LOG_ERR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); | 260 | write_log(LOG_LEVEL_ERROR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); |
261 | config_destroy(&cfg); | 261 | config_destroy(&cfg); |
262 | return 0; | 262 | return 0; |
263 | } | 263 | } |
264 | 264 | ||
265 | // Get port | 265 | // Get port |
266 | if (config_lookup_int(&cfg, NAME_PORT, port) == CONFIG_FALSE) { | 266 | if (config_lookup_int(&cfg, NAME_PORT, port) == CONFIG_FALSE) { |
267 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_PORT); | 267 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_PORT); |
268 | syslog(LOG_WARNING, "Using default '%s': %d\n", NAME_PORT, DEFAULT_PORT); | 268 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %d\n", NAME_PORT, DEFAULT_PORT); |
269 | *port = DEFAULT_PORT; | 269 | *port = DEFAULT_PORT; |
270 | } | 270 | } |
271 | 271 | ||
@@ -273,8 +273,8 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
273 | const char *tmp_pid_file; | 273 | const char *tmp_pid_file; |
274 | 274 | ||
275 | if (config_lookup_string(&cfg, NAME_PID_FILE_PATH, &tmp_pid_file) == CONFIG_FALSE) { | 275 | if (config_lookup_string(&cfg, NAME_PID_FILE_PATH, &tmp_pid_file) == CONFIG_FALSE) { |
276 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_PID_FILE_PATH); | 276 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_PID_FILE_PATH); |
277 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_PID_FILE_PATH, DEFAULT_PID_FILE_PATH); | 277 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_PID_FILE_PATH, DEFAULT_PID_FILE_PATH); |
278 | tmp_pid_file = DEFAULT_PID_FILE_PATH; | 278 | tmp_pid_file = DEFAULT_PID_FILE_PATH; |
279 | } | 279 | } |
280 | 280 | ||
@@ -285,8 +285,8 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
285 | const char *tmp_keys_file; | 285 | const char *tmp_keys_file; |
286 | 286 | ||
287 | if (config_lookup_string(&cfg, NAME_KEYS_FILE_PATH, &tmp_keys_file) == CONFIG_FALSE) { | 287 | if (config_lookup_string(&cfg, NAME_KEYS_FILE_PATH, &tmp_keys_file) == CONFIG_FALSE) { |
288 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_KEYS_FILE_PATH); | 288 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_KEYS_FILE_PATH); |
289 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_KEYS_FILE_PATH, DEFAULT_KEYS_FILE_PATH); | 289 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_KEYS_FILE_PATH, DEFAULT_KEYS_FILE_PATH); |
290 | tmp_keys_file = DEFAULT_KEYS_FILE_PATH; | 290 | tmp_keys_file = DEFAULT_KEYS_FILE_PATH; |
291 | } | 291 | } |
292 | 292 | ||
@@ -295,31 +295,31 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
295 | 295 | ||
296 | // Get IPv6 option | 296 | // Get IPv6 option |
297 | if (config_lookup_bool(&cfg, NAME_ENABLE_IPV6, enable_ipv6) == CONFIG_FALSE) { | 297 | if (config_lookup_bool(&cfg, NAME_ENABLE_IPV6, enable_ipv6) == CONFIG_FALSE) { |
298 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV6); | 298 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV6); |
299 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV6, DEFAULT_ENABLE_IPV6 ? "true" : "false"); | 299 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV6, DEFAULT_ENABLE_IPV6 ? "true" : "false"); |
300 | *enable_ipv6 = DEFAULT_ENABLE_IPV6; | 300 | *enable_ipv6 = DEFAULT_ENABLE_IPV6; |
301 | } | 301 | } |
302 | 302 | ||
303 | // Get IPv4 fallback option | 303 | // Get IPv4 fallback option |
304 | if (config_lookup_bool(&cfg, NAME_ENABLE_IPV4_FALLBACK, enable_ipv4_fallback) == CONFIG_FALSE) { | 304 | if (config_lookup_bool(&cfg, NAME_ENABLE_IPV4_FALLBACK, enable_ipv4_fallback) == CONFIG_FALSE) { |
305 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV4_FALLBACK); | 305 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV4_FALLBACK); |
306 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, | 306 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, |
307 | DEFAULT_ENABLE_IPV4_FALLBACK ? "true" : "false"); | 307 | DEFAULT_ENABLE_IPV4_FALLBACK ? "true" : "false"); |
308 | *enable_ipv4_fallback = DEFAULT_ENABLE_IPV4_FALLBACK; | 308 | *enable_ipv4_fallback = DEFAULT_ENABLE_IPV4_FALLBACK; |
309 | } | 309 | } |
310 | 310 | ||
311 | // Get LAN discovery option | 311 | // Get LAN discovery option |
312 | if (config_lookup_bool(&cfg, NAME_ENABLE_LAN_DISCOVERY, enable_lan_discovery) == CONFIG_FALSE) { | 312 | if (config_lookup_bool(&cfg, NAME_ENABLE_LAN_DISCOVERY, enable_lan_discovery) == CONFIG_FALSE) { |
313 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_LAN_DISCOVERY); | 313 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_LAN_DISCOVERY); |
314 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, | 314 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, |
315 | DEFAULT_ENABLE_LAN_DISCOVERY ? "true" : "false"); | 315 | DEFAULT_ENABLE_LAN_DISCOVERY ? "true" : "false"); |
316 | *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY; | 316 | *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY; |
317 | } | 317 | } |
318 | 318 | ||
319 | // Get TCP relay option | 319 | // Get TCP relay option |
320 | if (config_lookup_bool(&cfg, NAME_ENABLE_TCP_RELAY, enable_tcp_relay) == CONFIG_FALSE) { | 320 | if (config_lookup_bool(&cfg, NAME_ENABLE_TCP_RELAY, enable_tcp_relay) == CONFIG_FALSE) { |
321 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_TCP_RELAY); | 321 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_TCP_RELAY); |
322 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_TCP_RELAY, | 322 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_TCP_RELAY, |
323 | DEFAULT_ENABLE_TCP_RELAY ? "true" : "false"); | 323 | DEFAULT_ENABLE_TCP_RELAY ? "true" : "false"); |
324 | *enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY; | 324 | *enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY; |
325 | } | 325 | } |
@@ -332,8 +332,8 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
332 | 332 | ||
333 | // Get MOTD option | 333 | // Get MOTD option |
334 | if (config_lookup_bool(&cfg, NAME_ENABLE_MOTD, enable_motd) == CONFIG_FALSE) { | 334 | if (config_lookup_bool(&cfg, NAME_ENABLE_MOTD, enable_motd) == CONFIG_FALSE) { |
335 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_MOTD); | 335 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_MOTD); |
336 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_MOTD, | 336 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_MOTD, |
337 | DEFAULT_ENABLE_MOTD ? "true" : "false"); | 337 | DEFAULT_ENABLE_MOTD ? "true" : "false"); |
338 | *enable_motd = DEFAULT_ENABLE_MOTD; | 338 | *enable_motd = DEFAULT_ENABLE_MOTD; |
339 | } | 339 | } |
@@ -343,8 +343,8 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
343 | const char *tmp_motd; | 343 | const char *tmp_motd; |
344 | 344 | ||
345 | if (config_lookup_string(&cfg, NAME_MOTD, &tmp_motd) == CONFIG_FALSE) { | 345 | if (config_lookup_string(&cfg, NAME_MOTD, &tmp_motd) == CONFIG_FALSE) { |
346 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_MOTD); | 346 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_MOTD); |
347 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_MOTD, DEFAULT_MOTD); | 347 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_MOTD, DEFAULT_MOTD); |
348 | tmp_motd = DEFAULT_MOTD; | 348 | tmp_motd = DEFAULT_MOTD; |
349 | } | 349 | } |
350 | 350 | ||
@@ -357,34 +357,34 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
357 | 357 | ||
358 | config_destroy(&cfg); | 358 | config_destroy(&cfg); |
359 | 359 | ||
360 | syslog(LOG_INFO, "Successfully read:\n"); | 360 | write_log(LOG_LEVEL_INFO, "Successfully read:\n"); |
361 | syslog(LOG_INFO, "'%s': %s\n", NAME_PID_FILE_PATH, *pid_file_path); | 361 | write_log(LOG_LEVEL_INFO, "'%s': %s\n", NAME_PID_FILE_PATH, *pid_file_path); |
362 | syslog(LOG_INFO, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path); | 362 | write_log(LOG_LEVEL_INFO, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path); |
363 | syslog(LOG_INFO, "'%s': %d\n", NAME_PORT, *port); | 363 | write_log(LOG_LEVEL_INFO, "'%s': %d\n", NAME_PORT, *port); |
364 | syslog(LOG_INFO, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); | 364 | write_log(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); |
365 | syslog(LOG_INFO, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback ? "true" : "false"); | 365 | write_log(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback ? "true" : "false"); |
366 | syslog(LOG_INFO, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); | 366 | write_log(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); |
367 | 367 | ||
368 | syslog(LOG_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false"); | 368 | write_log(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false"); |
369 | 369 | ||
370 | // show info about tcp ports only if tcp relay is enabled | 370 | // show info about tcp ports only if tcp relay is enabled |
371 | if (*enable_tcp_relay) { | 371 | if (*enable_tcp_relay) { |
372 | if (*tcp_relay_port_count == 0) { | 372 | if (*tcp_relay_port_count == 0) { |
373 | syslog(LOG_ERR, "No TCP ports could be read.\n"); | 373 | write_log(LOG_LEVEL_ERROR, "No TCP ports could be read.\n"); |
374 | } else { | 374 | } else { |
375 | syslog(LOG_INFO, "Read %d TCP ports:\n", *tcp_relay_port_count); | 375 | write_log(LOG_LEVEL_INFO, "Read %d TCP ports:\n", *tcp_relay_port_count); |
376 | int i; | 376 | int i; |
377 | 377 | ||
378 | for (i = 0; i < *tcp_relay_port_count; i ++) { | 378 | for (i = 0; i < *tcp_relay_port_count; i ++) { |
379 | syslog(LOG_INFO, "Port #%d: %u\n", i, (*tcp_relay_ports)[i]); | 379 | write_log(LOG_LEVEL_INFO, "Port #%d: %u\n", i, (*tcp_relay_ports)[i]); |
380 | } | 380 | } |
381 | } | 381 | } |
382 | } | 382 | } |
383 | 383 | ||
384 | syslog(LOG_INFO, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd ? "true" : "false"); | 384 | write_log(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd ? "true" : "false"); |
385 | 385 | ||
386 | if (*enable_motd) { | 386 | if (*enable_motd) { |
387 | syslog(LOG_INFO, "'%s': %s\n", NAME_MOTD, *motd); | 387 | write_log(LOG_LEVEL_INFO, "'%s': %s\n", NAME_MOTD, *motd); |
388 | } | 388 | } |
389 | 389 | ||
390 | return 1; | 390 | return 1; |
@@ -408,7 +408,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
408 | config_init(&cfg); | 408 | config_init(&cfg); |
409 | 409 | ||
410 | if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) { | 410 | if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) { |
411 | syslog(LOG_ERR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); | 411 | write_log(LOG_LEVEL_ERROR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); |
412 | config_destroy(&cfg); | 412 | config_destroy(&cfg); |
413 | return 0; | 413 | return 0; |
414 | } | 414 | } |
@@ -416,13 +416,13 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
416 | config_setting_t *node_list = config_lookup(&cfg, NAME_BOOTSTRAP_NODES); | 416 | config_setting_t *node_list = config_lookup(&cfg, NAME_BOOTSTRAP_NODES); |
417 | 417 | ||
418 | if (node_list == NULL) { | 418 | if (node_list == NULL) { |
419 | syslog(LOG_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n", NAME_BOOTSTRAP_NODES); | 419 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n", NAME_BOOTSTRAP_NODES); |
420 | config_destroy(&cfg); | 420 | config_destroy(&cfg); |
421 | return 1; | 421 | return 1; |
422 | } | 422 | } |
423 | 423 | ||
424 | if (config_setting_length(node_list) == 0) { | 424 | if (config_setting_length(node_list) == 0) { |
425 | syslog(LOG_WARNING, "No bootstrap nodes found. Skipping bootstrapping.\n"); | 425 | write_log(LOG_LEVEL_WARNING, "No bootstrap nodes found. Skipping bootstrapping.\n"); |
426 | config_destroy(&cfg); | 426 | config_destroy(&cfg); |
427 | return 1; | 427 | return 1; |
428 | } | 428 | } |
@@ -446,29 +446,29 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
446 | 446 | ||
447 | // Check that all settings are present | 447 | // Check that all settings are present |
448 | if (config_setting_lookup_string(node, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) { | 448 | if (config_setting_lookup_string(node, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) { |
449 | syslog(LOG_WARNING, "Bootstrap node #%d: Couldn't find '%s' setting. Skipping the node.\n", i, NAME_PUBLIC_KEY); | 449 | write_log(LOG_LEVEL_WARNING, "Bootstrap node #%d: Couldn't find '%s' setting. Skipping the node.\n", i, NAME_PUBLIC_KEY); |
450 | goto next; | 450 | goto next; |
451 | } | 451 | } |
452 | 452 | ||
453 | if (config_setting_lookup_int(node, NAME_PORT, &bs_port) == CONFIG_FALSE) { | 453 | if (config_setting_lookup_int(node, NAME_PORT, &bs_port) == CONFIG_FALSE) { |
454 | syslog(LOG_WARNING, "Bootstrap node #%d: Couldn't find '%s' setting. Skipping the node.\n", i, NAME_PORT); | 454 | write_log(LOG_LEVEL_WARNING, "Bootstrap node #%d: Couldn't find '%s' setting. Skipping the node.\n", i, NAME_PORT); |
455 | goto next; | 455 | goto next; |
456 | } | 456 | } |
457 | 457 | ||
458 | if (config_setting_lookup_string(node, NAME_ADDRESS, &bs_address) == CONFIG_FALSE) { | 458 | if (config_setting_lookup_string(node, NAME_ADDRESS, &bs_address) == CONFIG_FALSE) { |
459 | syslog(LOG_WARNING, "Bootstrap node #%d: Couldn't find '%s' setting. Skipping the node.\n", i, NAME_ADDRESS); | 459 | write_log(LOG_LEVEL_WARNING, "Bootstrap node #%d: Couldn't find '%s' setting. Skipping the node.\n", i, NAME_ADDRESS); |
460 | goto next; | 460 | goto next; |
461 | } | 461 | } |
462 | 462 | ||
463 | // Process settings | 463 | // Process settings |
464 | if (strlen(bs_public_key) != crypto_box_PUBLICKEYBYTES * 2) { | 464 | if (strlen(bs_public_key) != crypto_box_PUBLICKEYBYTES * 2) { |
465 | syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_PUBLIC_KEY, | 465 | write_log(LOG_LEVEL_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_PUBLIC_KEY, |
466 | bs_public_key); | 466 | bs_public_key); |
467 | goto next; | 467 | goto next; |
468 | } | 468 | } |
469 | 469 | ||
470 | if (bs_port < MIN_ALLOWED_PORT || bs_port > MAX_ALLOWED_PORT) { | 470 | if (bs_port < MIN_ALLOWED_PORT || bs_port > MAX_ALLOWED_PORT) { |
471 | syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %d, should be in [%d, %d]. Skipping the node.\n", i, NAME_PORT, | 471 | write_log(LOG_LEVEL_WARNING, "Bootstrap node #%d: Invalid '%s': %d, should be in [%d, %d]. Skipping the node.\n", i, NAME_PORT, |
472 | bs_port, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); | 472 | bs_port, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); |
473 | goto next; | 473 | goto next; |
474 | } | 474 | } |
@@ -479,11 +479,11 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
479 | free(bs_public_key_bin); | 479 | free(bs_public_key_bin); |
480 | 480 | ||
481 | if (!address_resolved) { | 481 | if (!address_resolved) { |
482 | syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_ADDRESS, bs_address); | 482 | write_log(LOG_LEVEL_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_ADDRESS, bs_address); |
483 | goto next; | 483 | goto next; |
484 | } | 484 | } |
485 | 485 | ||
486 | syslog(LOG_INFO, "Successfully added bootstrap node #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key); | 486 | write_log(LOG_LEVEL_INFO, "Successfully added bootstrap node #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key); |
487 | 487 | ||
488 | next: | 488 | next: |
489 | // config_setting_lookup_string() allocates string inside and doesn't allow us to free it direcly | 489 | // config_setting_lookup_string() allocates string inside and doesn't allow us to free it direcly |
@@ -511,19 +511,19 @@ void print_public_key(const uint8_t *public_key) | |||
511 | index += sprintf(buffer + index, "%02hhX", public_key[i]); | 511 | index += sprintf(buffer + index, "%02hhX", public_key[i]); |
512 | } | 512 | } |
513 | 513 | ||
514 | syslog(LOG_INFO, "Public Key: %s\n", buffer); | 514 | write_log(LOG_LEVEL_INFO, "Public Key: %s\n", buffer); |
515 | 515 | ||
516 | return; | 516 | return; |
517 | } | 517 | } |
518 | 518 | ||
519 | int main(int argc, char *argv[]) | 519 | int main(int argc, char *argv[]) |
520 | { | 520 | { |
521 | openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); | 521 | open_log(LOGGER_BACKEND_SYSLOG); |
522 | 522 | ||
523 | syslog(LOG_INFO, "Running \"%s\" version %lu.\n", DAEMON_NAME, DAEMON_VERSION_NUMBER); | 523 | write_log(LOG_LEVEL_INFO, "Running \"%s\" version %lu.\n", DAEMON_NAME, DAEMON_VERSION_NUMBER); |
524 | 524 | ||
525 | if (argc < 2) { | 525 | if (argc < 2) { |
526 | syslog(LOG_ERR, "Please specify a path to a configuration file as the first argument. Exiting.\n"); | 526 | write_log(LOG_LEVEL_ERROR, "Please specify a path to a configuration file as the first argument. Exiting.\n"); |
527 | return 1; | 527 | return 1; |
528 | } | 528 | } |
529 | 529 | ||
@@ -541,14 +541,14 @@ int main(int argc, char *argv[]) | |||
541 | 541 | ||
542 | if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_ipv4_fallback, | 542 | if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_ipv4_fallback, |
543 | &enable_lan_discovery, &enable_tcp_relay, &tcp_relay_ports, &tcp_relay_port_count, &enable_motd, &motd)) { | 543 | &enable_lan_discovery, &enable_tcp_relay, &tcp_relay_ports, &tcp_relay_port_count, &enable_motd, &motd)) { |
544 | syslog(LOG_INFO, "General config read successfully\n"); | 544 | write_log(LOG_LEVEL_INFO, "General config read successfully\n"); |
545 | } else { | 545 | } else { |
546 | syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path); | 546 | write_log(LOG_LEVEL_ERROR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path); |
547 | return 1; | 547 | return 1; |
548 | } | 548 | } |
549 | 549 | ||
550 | if (port < MIN_ALLOWED_PORT || port > MAX_ALLOWED_PORT) { | 550 | if (port < MIN_ALLOWED_PORT || port > MAX_ALLOWED_PORT) { |
551 | syslog(LOG_ERR, "Invalid port: %d, should be in [%d, %d]. Exiting.\n", port, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); | 551 | write_log(LOG_LEVEL_ERROR, "Invalid port: %d, should be in [%d, %d]. Exiting.\n", port, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); |
552 | return 1; | 552 | return 1; |
553 | } | 553 | } |
554 | 554 | ||
@@ -556,7 +556,7 @@ int main(int argc, char *argv[]) | |||
556 | FILE *pid_file; | 556 | FILE *pid_file; |
557 | 557 | ||
558 | if ((pid_file = fopen(pid_file_path, "r"))) { | 558 | if ((pid_file = fopen(pid_file_path, "r"))) { |
559 | syslog(LOG_WARNING, "Another instance of the daemon is already running, PID file %s exists.\n", pid_file_path); | 559 | write_log(LOG_LEVEL_WARNING, "Another instance of the daemon is already running, PID file %s exists.\n", pid_file_path); |
560 | fclose(pid_file); | 560 | fclose(pid_file); |
561 | } | 561 | } |
562 | 562 | ||
@@ -567,17 +567,17 @@ int main(int argc, char *argv[]) | |||
567 | 567 | ||
568 | if (net == NULL) { | 568 | if (net == NULL) { |
569 | if (enable_ipv6 && enable_ipv4_fallback) { | 569 | if (enable_ipv6 && enable_ipv4_fallback) { |
570 | syslog(LOG_WARNING, "Couldn't initialize IPv6 networking. Falling back to using IPv4.\n"); | 570 | write_log(LOG_LEVEL_WARNING, "Couldn't initialize IPv6 networking. Falling back to using IPv4.\n"); |
571 | enable_ipv6 = 0; | 571 | enable_ipv6 = 0; |
572 | ip_init(&ip, enable_ipv6); | 572 | ip_init(&ip, enable_ipv6); |
573 | net = new_networking(ip, port); | 573 | net = new_networking(ip, port); |
574 | 574 | ||
575 | if (net == NULL) { | 575 | if (net == NULL) { |
576 | syslog(LOG_ERR, "Couldn't fallback to IPv4. Exiting.\n"); | 576 | write_log(LOG_LEVEL_ERROR, "Couldn't fallback to IPv4. Exiting.\n"); |
577 | return 1; | 577 | return 1; |
578 | } | 578 | } |
579 | } else { | 579 | } else { |
580 | syslog(LOG_ERR, "Couldn't initialize networking. Exiting.\n"); | 580 | write_log(LOG_LEVEL_ERROR, "Couldn't initialize networking. Exiting.\n"); |
581 | return 1; | 581 | return 1; |
582 | } | 582 | } |
583 | } | 583 | } |
@@ -586,7 +586,7 @@ int main(int argc, char *argv[]) | |||
586 | DHT *dht = new_DHT(net); | 586 | DHT *dht = new_DHT(net); |
587 | 587 | ||
588 | if (dht == NULL) { | 588 | if (dht == NULL) { |
589 | syslog(LOG_ERR, "Couldn't initialize Tox DHT instance. Exiting.\n"); | 589 | write_log(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n"); |
590 | return 1; | 590 | return 1; |
591 | } | 591 | } |
592 | 592 | ||
@@ -594,15 +594,15 @@ int main(int argc, char *argv[]) | |||
594 | Onion_Announce *onion_a = new_onion_announce(dht); | 594 | Onion_Announce *onion_a = new_onion_announce(dht); |
595 | 595 | ||
596 | if (!(onion && onion_a)) { | 596 | if (!(onion && onion_a)) { |
597 | syslog(LOG_ERR, "Couldn't initialize Tox Onion. Exiting.\n"); | 597 | write_log(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n"); |
598 | return 1; | 598 | return 1; |
599 | } | 599 | } |
600 | 600 | ||
601 | if (enable_motd) { | 601 | if (enable_motd) { |
602 | if (bootstrap_set_callbacks(dht->net, DAEMON_VERSION_NUMBER, (uint8_t *)motd, strlen(motd) + 1) == 0) { | 602 | if (bootstrap_set_callbacks(dht->net, DAEMON_VERSION_NUMBER, (uint8_t *)motd, strlen(motd) + 1) == 0) { |
603 | syslog(LOG_INFO, "Set MOTD successfully.\n"); | 603 | write_log(LOG_LEVEL_INFO, "Set MOTD successfully.\n"); |
604 | } else { | 604 | } else { |
605 | syslog(LOG_ERR, "Couldn't set MOTD: %s. Exiting.\n", motd); | 605 | write_log(LOG_LEVEL_ERROR, "Couldn't set MOTD: %s. Exiting.\n", motd); |
606 | return 1; | 606 | return 1; |
607 | } | 607 | } |
608 | 608 | ||
@@ -610,9 +610,9 @@ int main(int argc, char *argv[]) | |||
610 | } | 610 | } |
611 | 611 | ||
612 | if (manage_keys(dht, keys_file_path)) { | 612 | if (manage_keys(dht, keys_file_path)) { |
613 | syslog(LOG_INFO, "Keys are managed successfully.\n"); | 613 | write_log(LOG_LEVEL_INFO, "Keys are managed successfully.\n"); |
614 | } else { | 614 | } else { |
615 | syslog(LOG_ERR, "Couldn't read/write: %s. Exiting.\n", keys_file_path); | 615 | write_log(LOG_LEVEL_ERROR, "Couldn't read/write: %s. Exiting.\n", keys_file_path); |
616 | return 1; | 616 | return 1; |
617 | } | 617 | } |
618 | 618 | ||
@@ -620,7 +620,7 @@ int main(int argc, char *argv[]) | |||
620 | 620 | ||
621 | if (enable_tcp_relay) { | 621 | if (enable_tcp_relay) { |
622 | if (tcp_relay_port_count == 0) { | 622 | if (tcp_relay_port_count == 0) { |
623 | syslog(LOG_ERR, "No TCP relay ports read. Exiting.\n"); | 623 | write_log(LOG_LEVEL_ERROR, "No TCP relay ports read. Exiting.\n"); |
624 | return 1; | 624 | return 1; |
625 | } | 625 | } |
626 | 626 | ||
@@ -630,17 +630,17 @@ int main(int argc, char *argv[]) | |||
630 | free(tcp_relay_ports); | 630 | free(tcp_relay_ports); |
631 | 631 | ||
632 | if (tcp_server != NULL) { | 632 | if (tcp_server != NULL) { |
633 | syslog(LOG_INFO, "Initialized Tox TCP server successfully.\n"); | 633 | write_log(LOG_LEVEL_INFO, "Initialized Tox TCP server successfully.\n"); |
634 | } else { | 634 | } else { |
635 | syslog(LOG_ERR, "Couldn't initialize Tox TCP server. Exiting.\n"); | 635 | write_log(LOG_LEVEL_ERROR, "Couldn't initialize Tox TCP server. Exiting.\n"); |
636 | return 1; | 636 | return 1; |
637 | } | 637 | } |
638 | } | 638 | } |
639 | 639 | ||
640 | if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) { | 640 | if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) { |
641 | syslog(LOG_INFO, "List of bootstrap nodes read successfully.\n"); | 641 | write_log(LOG_LEVEL_INFO, "List of bootstrap nodes read successfully.\n"); |
642 | } else { | 642 | } else { |
643 | syslog(LOG_ERR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path); | 643 | write_log(LOG_LEVEL_ERROR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path); |
644 | return 1; | 644 | return 1; |
645 | } | 645 | } |
646 | 646 | ||
@@ -650,7 +650,7 @@ int main(int argc, char *argv[]) | |||
650 | FILE *pidf = fopen(pid_file_path, "a+"); | 650 | FILE *pidf = fopen(pid_file_path, "a+"); |
651 | 651 | ||
652 | if (pidf == NULL) { | 652 | if (pidf == NULL) { |
653 | syslog(LOG_ERR, "Couldn't open the PID file for writing: %s. Exiting.\n", pid_file_path); | 653 | write_log(LOG_LEVEL_ERROR, "Couldn't open the PID file for writing: %s. Exiting.\n", pid_file_path); |
654 | return 1; | 654 | return 1; |
655 | } | 655 | } |
656 | 656 | ||
@@ -663,14 +663,14 @@ int main(int argc, char *argv[]) | |||
663 | if (pid > 0) { | 663 | if (pid > 0) { |
664 | fprintf(pidf, "%d", pid); | 664 | fprintf(pidf, "%d", pid); |
665 | fclose(pidf); | 665 | fclose(pidf); |
666 | syslog(LOG_INFO, "Forked successfully: PID: %d.\n", pid); | 666 | write_log(LOG_LEVEL_INFO, "Forked successfully: PID: %d.\n", pid); |
667 | return 0; | 667 | return 0; |
668 | } else { | 668 | } else { |
669 | fclose(pidf); | 669 | fclose(pidf); |
670 | } | 670 | } |
671 | 671 | ||
672 | if (pid < 0) { | 672 | if (pid < 0) { |
673 | syslog(LOG_ERR, "Forking failed. Exiting.\n"); | 673 | write_log(LOG_LEVEL_ERROR, "Forking failed. Exiting.\n"); |
674 | return 1; | 674 | return 1; |
675 | } | 675 | } |
676 | 676 | ||
@@ -679,13 +679,13 @@ int main(int argc, char *argv[]) | |||
679 | 679 | ||
680 | // Create a new SID for the child process | 680 | // Create a new SID for the child process |
681 | if (setsid() < 0) { | 681 | if (setsid() < 0) { |
682 | syslog(LOG_ERR, "SID creation failure. Exiting.\n"); | 682 | write_log(LOG_LEVEL_ERROR, "SID creation failure. Exiting.\n"); |
683 | return 1; | 683 | return 1; |
684 | } | 684 | } |
685 | 685 | ||
686 | // Change the current working directory | 686 | // Change the current working directory |
687 | if ((chdir("/")) < 0) { | 687 | if ((chdir("/")) < 0) { |
688 | syslog(LOG_ERR, "Couldn't change working directory to '/'. Exiting.\n"); | 688 | write_log(LOG_LEVEL_ERROR, "Couldn't change working directory to '/'. Exiting.\n"); |
689 | return 1; | 689 | return 1; |
690 | } | 690 | } |
691 | 691 | ||
@@ -701,7 +701,7 @@ int main(int argc, char *argv[]) | |||
701 | 701 | ||
702 | if (enable_lan_discovery) { | 702 | if (enable_lan_discovery) { |
703 | LANdiscovery_init(dht); | 703 | LANdiscovery_init(dht); |
704 | syslog(LOG_INFO, "Initialized LAN discovery.\n"); | 704 | write_log(LOG_LEVEL_INFO, "Initialized LAN discovery.\n"); |
705 | } | 705 | } |
706 | 706 | ||
707 | while (1) { | 707 | while (1) { |
@@ -719,7 +719,7 @@ int main(int argc, char *argv[]) | |||
719 | networking_poll(dht->net); | 719 | networking_poll(dht->net); |
720 | 720 | ||
721 | if (waiting_for_dht_connection && DHT_isconnected(dht)) { | 721 | if (waiting_for_dht_connection && DHT_isconnected(dht)) { |
722 | syslog(LOG_INFO, "Connected to other bootstrap node successfully.\n"); | 722 | write_log(LOG_LEVEL_INFO, "Connected to other bootstrap node successfully.\n"); |
723 | waiting_for_dht_connection = 0; | 723 | waiting_for_dht_connection = 0; |
724 | } | 724 | } |
725 | 725 | ||