diff options
author | Antonio Caggiano <antonio.caggiano@collabora.com> | 2020-05-28 17:45:57 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-06-01 18:03:33 +0000 |
commit | 2eda978e95aaa18516cfc007aa91c8901fa251c5 (patch) | |
tree | cbebd997d4c2baa34532cfcc983372708e5c4763 /compositor | |
parent | fdc9b4bce5816cdafb9dc08f499ed76778945d36 (diff) |
compositor: Quit when failing to open log file
If users ask explicitly to log to a file, it makes sense to quit
when we fail opening that file. Continuing execution would mean
wasting users' time if they expect to find the log file at the
end of the session.
Signed-off-by: Antonio Caggiano <antonio.caggiano@collabora.com>
Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Diffstat (limited to 'compositor')
-rw-r--r-- | compositor/main.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/compositor/main.c b/compositor/main.c index af31c94e..1a8bf115 100644 --- a/compositor/main.c +++ b/compositor/main.c @@ -171,23 +171,27 @@ custom_handler(const char *fmt, va_list arg) weston_log_scope_vprintf(log_scope, fmt, arg); } -static void +static bool weston_log_file_open(const char *filename) { wl_log_set_handler_server(custom_handler); if (filename != NULL) { weston_logfile = fopen(filename, "a"); - if (weston_logfile) + if (weston_logfile) { os_fd_set_cloexec(fileno(weston_logfile)); - else + } else { fprintf(stderr, "Failed to open %s: %s\n", filename, strerror(errno)); + return false; + } } if (weston_logfile == NULL) weston_logfile = stderr; else setvbuf(weston_logfile, NULL, _IOLBF, 256); + + return true; } static void @@ -3196,7 +3200,9 @@ wet_main(int argc, char *argv[]) log_scope = weston_log_ctx_add_log_scope(log_ctx, "log", "Weston and Wayland log\n", NULL, NULL, NULL); - weston_log_file_open(log); + if (!weston_log_file_open(log)) + return EXIT_FAILURE; + weston_log_set_handler(vlog, vlog_continue); logger = weston_log_subscriber_create_log(weston_logfile); |