[PATCH] Some more error handling

Darxus at chaosreigns.com Darxus at chaosreigns.com
Thu Nov 18 22:45:33 PST 2010


Some additional error handling, a couple more \n's in prints, a slightly
clearer error message, and one very minor white space reformat for
consistency.

---
 clients/dnd.c               |    2 ++
 clients/flower.c            |    2 ++
 clients/gears.c             |    3 +++
 clients/image.c             |    2 ++
 clients/smoke.c             |    2 ++
 clients/terminal.c          |    2 ++
 clients/view.c              |    2 ++
 clients/window.c            |    5 ++++-
 compositor/compositor-drm.c |    6 +++++-
 compositor/compositor-x11.c |   32 +++++++++++++++++++++-----------
 10 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/clients/dnd.c b/clients/dnd.c
index 766fc5c..f1009c5 100644
--- a/clients/dnd.c
+++ b/clients/dnd.c
@@ -581,6 +581,8 @@ main(int argc, char *argv[])
 	srandom(tv.tv_usec);
 
 	d = display_create(&argc, &argv, option_entries);
+	if (d == NULL) 
+		exit(EXIT_FAILURE);
 
 	display_set_drag_offer_handler(d, drag_offer_handler);
 
diff --git a/clients/flower.c b/clients/flower.c
index 9054c0f..ff06f27 100644
--- a/clients/flower.c
+++ b/clients/flower.c
@@ -124,6 +124,8 @@ int main(int argc, char *argv[])
 	struct display *d;
 
 	d = display_create(&argc, &argv, NULL);
+	if (d == NULL)
+		exit(EXIT_FAILURE);
 
 	flower.x = 512;
 	flower.y = 384;
diff --git a/clients/gears.c b/clients/gears.c
index 8669683..a8309c3 100644
--- a/clients/gears.c
+++ b/clients/gears.c
@@ -414,6 +414,9 @@ int main(int argc, char *argv[])
 	struct gears *gears;
 
 	d = display_create(&argc, &argv, NULL);
+	if (d == NULL)
+		exit(EXIT_FAILURE);
+
 	gears = gears_create(d);
 	display_run(d);
 
diff --git a/clients/image.c b/clients/image.c
index cf98266..a371c00 100644
--- a/clients/image.c
+++ b/clients/image.c
@@ -244,6 +244,8 @@ main(int argc, char *argv[])
 	int i;
 
 	d = display_create(&argc, &argv, option_entries);
+	if (d == NULL)
+		exit(EXIT_FAILURE);
 
 	for (i = 1; i < argc; i++) {
 		struct image *image;
diff --git a/clients/smoke.c b/clients/smoke.c
index edd036c..c61088e 100644
--- a/clients/smoke.c
+++ b/clients/smoke.c
@@ -273,6 +273,8 @@ int main(int argc, char *argv[])
 	int size, x, y;
 
 	d = display_create(&argc, &argv, NULL);
+	if (d == NULL)
+		exit(EXIT_FAILURE);
 
 	smoke.x = 200;
 	smoke.y = 200;
diff --git a/clients/terminal.c b/clients/terminal.c
index c841ef2..3e1eac8 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -548,6 +548,8 @@ int main(int argc, char *argv[])
 	struct terminal *terminal;
 
 	d = display_create(&argc, &argv, option_entries);
+	if (d == NULL)
+		exit(EXIT_FAILURE);
 
 	terminal = terminal_create(d, option_fullscreen);
 	if (terminal_run(terminal, "/bin/bash"))
diff --git a/clients/view.c b/clients/view.c
index ace838d..f551a42 100644
--- a/clients/view.c
+++ b/clients/view.c
@@ -207,6 +207,8 @@ main(int argc, char *argv[])
 	int i;
 
 	d = display_create(&argc, &argv, option_entries);
+	if (d == NULL)
+		exit(EXIT_FAILURE);
 
 	for (i = 1; i < argc; i++) {
 		struct view *view;
diff --git a/clients/window.c b/clients/window.c
index 9dfd355..2827dc1 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -1459,7 +1459,10 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
 		return NULL;
 	}
 
-	eglBindAPI(EGL_OPENGL_API);
+	if (EGL_FALSE == eglBindAPI(EGL_OPENGL_API)) {
+		fprintf(stderr, "failed to bind api EGL_OPENGL_API\n");
+		return NULL;
+	}
 
 	d->ctx = eglCreateContext(d->dpy, NULL, EGL_NO_CONTEXT, NULL);
 	if (d->ctx == NULL) {
diff --git a/compositor/compositor-drm.c b/compositor/compositor-drm.c
index e843e14..d06f769 100644
--- a/compositor/compositor-drm.c
+++ b/compositor/compositor-drm.c
@@ -339,7 +339,11 @@ init_egl(struct drm_compositor *ec, struct udev_device *device)
 		return -1;
 	}
 
-	eglBindAPI(EGL_OPENGL_ES_API);
+	if (EGL_FALSE == eglBindAPI(EGL_OPENGL_ES_API)) {
+		fprintf(stderr, "failed to bind api EGL_OPENGL_ES_API\n");
+		return -1;
+	}
+
 	ec->base.context = eglCreateContext(ec->base.display, NULL,
 					    EGL_NO_CONTEXT, context_attribs);
 	if (ec->base.context == NULL) {
diff --git a/compositor/compositor-x11.c b/compositor/compositor-x11.c
index 5178873..a3b1f3b 100644
--- a/compositor/compositor-x11.c
+++ b/compositor/compositor-x11.c
@@ -80,19 +80,21 @@ struct x11_input {
 };
 
 
-static void
+static int
 x11_input_create(struct x11_compositor *c)
 {
 	struct x11_input *input;
 
 	input = malloc(sizeof *input);
 	if (input == NULL)
-		return;
+		return -1;
 
 	memset(input, 0, sizeof *input);
 	wlsc_input_device_init(&input->base, &c->base);
 
 	c->base.input_device = &input->base;
+
+	return 0;
 }
 
 
@@ -140,7 +142,7 @@ dri2_connect(struct x11_compositor *c)
 		xcb_dri2_query_version_reply (c->conn,
 					      dri2_query_cookie, &error);
 	if (dri2_query == NULL || error != NULL) {
-		fprintf(stderr, "DRI2: failed to query version");
+		fprintf(stderr, "DRI2: failed to query version\n");
 		free(error);
 		return EGL_FALSE;
 	}
@@ -152,7 +154,7 @@ dri2_connect(struct x11_compositor *c)
 					  connect_cookie, NULL);
 	if (connect == NULL ||
 	    connect->driver_name_length + connect->device_name_length == 0) {
-		fprintf(stderr, "DRI2: failed to authenticate");
+		fprintf(stderr, "DRI2: driver name and device name are empty\n");
 		return -1;
 	}
 
@@ -177,7 +179,7 @@ dri2_connect(struct x11_compositor *c)
 	fd = open(path, O_RDWR);
 	if (fd < 0) {
 		fprintf(stderr,
-			"DRI2: could not open %s (%s)", path, strerror(errno));
+			"DRI2: could not open %s (%s)\n", path, strerror(errno));
 		return -1;
 	}
 
@@ -197,7 +199,7 @@ dri2_authenticate(struct x11_compositor *c, uint32_t magic)
 		xcb_dri2_authenticate_reply(c->conn,
 					    authenticate_cookie, NULL);
 	if (authenticate == NULL || !authenticate->authenticated) {
-		fprintf(stderr, "DRI2: failed to authenticate");
+		fprintf(stderr, "DRI2: failed to authenticate\n");
 		free(authenticate);
 		return -1;
 	}
@@ -222,7 +224,7 @@ x11_compositor_init_egl(struct x11_compositor *c)
 		return -1;
 
 	if (drmGetMagic(c->base.drm.fd, &magic)) {
-		fprintf(stderr, "DRI2: failed to get drm magic");
+		fprintf(stderr, "DRI2: failed to get drm magic\n");
 		return -1;
 	}
 
@@ -246,7 +248,11 @@ x11_compositor_init_egl(struct x11_compositor *c)
 		return -1;
 	}
 
-	eglBindAPI(EGL_OPENGL_ES_API);
+	if (EGL_FALSE == eglBindAPI(EGL_OPENGL_ES_API)) {
+		fprintf(stderr, "failed to bind EGL_OPENGL_ES_API\n");
+		return -1;
+	}
+
 	c->base.context = eglCreateContext(c->base.display, NULL,
 					   EGL_NO_CONTEXT, context_attribs);
 	if (c->base.context == NULL) {
@@ -660,15 +666,17 @@ x11_compositor_create(struct wl_display *display, int width, int height)
 
 	c->base.wl_display = display;
 	if (x11_compositor_init_egl(c) < 0)
-        return NULL;
+		return NULL;
 
 	/* Can't init base class until we have a current egl context */
 	if (wlsc_compositor_init(&c->base, display) < 0)
 		return NULL;
 
-	x11_compositor_create_output(c, width, height);
+	if (x11_compositor_create_output(c, width, height) < 0)
+		return NULL;
 
-	x11_input_create(c);
+	if (x11_input_create(c) < 0)
+		return NULL;
 
 	loop = wl_display_get_event_loop(c->base.wl_display);
 
@@ -678,6 +686,8 @@ x11_compositor_create(struct wl_display *display, int width, int height)
 				     x11_compositor_handle_event, c);
 
 	c->base.authenticate = x11_authenticate;
+	if (c->base.authenticate < 0)
+		return NULL;
 	c->base.present = x11_compositor_present;
 
 	return &c->base;

-- 
"Of course there's strength in numbers. But there's strength in sharp
weaponry too. Ironically, this lead to what we call 'civilization'."
- spore
http://www.ChaosReigns.com


More information about the wayland-devel mailing list