Skip to content

Commit 2606bca

Browse files
authored
sources/instance.c: Move logger changes from config (#794)
* sources/instance.c: Move logger changes from config There is a bug: when odyssey starts with invalid path to log file, it crashes without message. This commit fix this problem and adds test to check it works correctly. Signed-off-by: Vikmalakhov <[email protected]> * docker/invalid_log_file: log_path -> invalid_log_file Signed-off-by: Vikmalakhov <[email protected]> --------- Signed-off-by: Vikmalakhov <[email protected]>
1 parent ac95c5f commit 2606bca

File tree

5 files changed

+76
-5
lines changed

5 files changed

+76
-5
lines changed

docker/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ COPY ./docker/copy /copy
116116
COPY ./docker/gorm /gorm
117117
COPY ./docker/reload /reload
118118
COPY ./docker/tls-compat /tls-compat
119+
COPY ./docker/invalid_log_file /invalid_log_file
119120

120121
COPY ./third_party/machinarium/gdb/machinarium-gdb.py /gdb.py
121122

docker/entrypoint.sh

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ ody-stop
1010

1111
setup
1212

13+
# path to log file
14+
/invalid_log_file/test_log_file.sh
15+
if [ $? -eq 1 ]
16+
then
17+
exit 1
18+
fi
19+
1320
/tls-compat/test-tls-compat.sh
1421
if [ $? -eq 1 ]
1522
then

docker/invalid_log_file/config.conf

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
storage "postgres_server" {
3+
type "remote"
4+
5+
host "localhost"
6+
port 5432
7+
}
8+
9+
database default {
10+
user default {
11+
authentication "none"
12+
storage "postgres_server"
13+
pool "session"
14+
client_fwd_error yes
15+
}
16+
}
17+
18+
unix_socket_dir "/tmp"
19+
unix_socket_mode "0644"
20+
21+
22+
log_format "%p %t %l [%i %s] (%c) %m\n"
23+
log_file "/hgdfgf/juyhgfd/invalid.log"
24+
log_to_stdout no
25+
26+
daemonize no
27+
28+
locks_dir "/tmp/odyssey"
29+
graceful_die_on_errors yes
30+
enable_online_restart yes
31+
bindwith_reuseport yes
32+
33+
stats_interval 60
34+
35+
pid_file "/var/run/odyssey.pid"
36+
37+
listen {
38+
host "*"
39+
port 6432
40+
}
41+
42+
43+
storage "local" {
44+
type "local"
45+
}
46+
47+
database "console" {
48+
user default {
49+
authentication "none"
50+
role "admin"
51+
pool "session"
52+
storage "local"
53+
}
54+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash -x
2+
3+
set -ex
4+
if ! /usr/bin/odyssey /invalid_log_file/config.conf | grep -q "failed to open log file "; then
5+
echo "ERROR: can't find log open error in stdout"
6+
exit 1
7+
fi
8+
9+
ody-stop

sources/instance.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,6 @@ int od_instance_main(od_instance_t *instance, int argc, char **argv)
227227
goto error;
228228
}
229229

230-
/* configure logger */
231-
od_logger_set_format(&instance->logger, instance->config.log_format);
232-
od_logger_set_debug(&instance->logger, instance->config.log_debug);
233-
od_logger_set_stdout(&instance->logger, instance->config.log_to_stdout);
234-
235230
/* run as daemon */
236231
if (instance->config.daemonize) {
237232
rc = od_daemonize();
@@ -254,6 +249,11 @@ int od_instance_main(od_instance_t *instance, int argc, char **argv)
254249
}
255250
}
256251

252+
/* configure logger */
253+
od_logger_set_format(&instance->logger, instance->config.log_format);
254+
od_logger_set_debug(&instance->logger, instance->config.log_debug);
255+
od_logger_set_stdout(&instance->logger, instance->config.log_to_stdout);
256+
257257
/* syslog */
258258
if (instance->config.log_syslog) {
259259
od_logger_open_syslog(&instance->logger,

0 commit comments

Comments
 (0)