weston: arm SEGV handler earlier
authorPekka Paalanen <pekka.paalanen@collabora.co.uk>
Wed, 11 Oct 2017 12:17:47 +0000 (15:17 +0300)
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>
Mon, 27 Nov 2017 13:41:18 +0000 (15:41 +0200)
It is useful to print the backtrace regardless of whether we have a
compositor and a backend initialized yet. Move catch_signals() to the
earliest point in main() and protect the SEGV handler from dereferencing
NULL when we don't yet have a compositor or a backend.

The SEGV handler uses weston_log(), so cannot move catch_signals() any
earlier.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Reviewed-by: Daniel Stone <daniels@collabora.com>
compositor/main.c

index 9e4451e..9f00ee3 100644 (file)
@@ -656,7 +656,8 @@ on_caught_signal(int s, siginfo_t *siginfo, void *context)
 
        print_backtrace();
 
-       segv_compositor->backend->restore(segv_compositor);
+       if (segv_compositor && segv_compositor->backend)
+               segv_compositor->backend->restore(segv_compositor);
 
        raise(SIGTRAP);
 }
@@ -1824,6 +1825,8 @@ int main(int argc, char *argv[])
        weston_log_set_handler(vlog, vlog_continue);
        weston_log_file_open(log);
 
+       catch_signals();
+
        weston_log("%s\n"
                   STAMP_SPACE "%s\n"
                   STAMP_SPACE "Bug reports to: %s\n"
@@ -1872,6 +1875,7 @@ int main(int argc, char *argv[])
                weston_log("fatal: failed to create compositor\n");
                goto out;
        }
+       segv_compositor = ec;
 
        if (weston_compositor_init_config(ec, config) < 0)
                goto out;
@@ -1887,9 +1891,6 @@ int main(int argc, char *argv[])
 
        weston_pending_output_coldplug(ec);
 
-       catch_signals();
-       segv_compositor = ec;
-
        if (idle_time < 0)
                weston_config_section_get_int(section, "idle-time", &idle_time, -1);
        if (idle_time < 0)