diff options
author | Omar Polo <op@omarpolo.com> | 2021-07-07 09:18:24 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2021-07-07 09:18:24 +0000 |
commit | 8a50fc0330f50c1c0c5fc0b541e0b8a19f900ea5 (patch) | |
tree | 5387297c5de6552741788a6f1f1301ba272f1001 /log.c | |
parent | d336aeafd4b848f3d6f3711e8d233d8b75ce297b (diff) |
initialize the logger early
Initialize the logger as soon as possible and log by default to
stderr. With this, some (common?) errors are printed early instead of
ending up in syslog.
# NB: this is in configless mode
% ./gmid -p 80
[2021-07-07 11:05:57] bind: Address already in use
% ./gmid -p 81
[2021-07-07 11:13:53] bind: Permission denied
%
Diffstat (limited to 'log.c')
-rw-r--r-- | log.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -299,11 +299,11 @@ handle_imsg_log(struct imsgbuf *ibuf, struct imsg *imsg, size_t datalen) static void handle_imsg_log_type(struct imsgbuf *ibuf, struct imsg *imsg, size_t datalen) { - if (log != NULL) { + if (log != NULL && log != stderr) { fflush(log); fclose(log); - log = NULL; } + log = NULL; if (imsg->fd != -1) { if ((log = fdopen(imsg->fd, "a")) == NULL) { @@ -324,6 +324,8 @@ handle_dispatch_imsg(int fd, short ev, void *d) int logger_main(int fd, struct imsgbuf *ibuf) { + log = stderr; + event_init(); event_set(&imsgev, fd, EV_READ | EV_PERSIST, &handle_dispatch_imsg, ibuf); |