From 8ce1c5ddf3e9d59f861b2d2f321c31b142955171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sun, 28 Nov 2021 02:00:46 +0200 Subject: [PATCH] Gracefully handle errors in initialization --- sortix.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/sortix.c b/sortix.c index 0f43c83..fb32f0f 100644 --- a/sortix.c +++ b/sortix.c @@ -10,7 +10,6 @@ #include -#include //debg #include #include @@ -135,10 +134,13 @@ static unsigned char *sortix_init_driver(unsigned char *param, unsigned char *di connection = display_connect_default(); if (!connection && errno == ECONNREFUSED) - return "TODO: display_spawn"; + display_spawn(g_argc, g_argv); - if (!connection) - return "TODO: Proper error reporting"; + if (!connection) { + char err[256]; + snprintf(err, sizeof(err), "Error connecting to display: %s\n", strerror(errno)); + return stracpy(err); + } sortix_driver.get_color = get_color_fn(sortix_driver.depth); @@ -153,9 +155,6 @@ static unsigned char *sortix_init_driver(unsigned char *param, unsigned char *di static struct graphics_device *sortix_init_device(void) { - if (current_dev) - errx(1, "Attempting to create second window"); - struct graphics_device *dev = mem_calloc(sizeof(struct graphics_device)); dev->size.x1 = 0;