aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-11-30 20:23:02 +0100
committerDaniel Eklöf <daniel@ekloef.se>2020-11-30 20:23:02 +0100
commite24f5fbd6047350e7ae3014c1ad5d2eba93d4e8b (patch)
tree3ebdf100e92583b70536a01877f7cd12901b772f /main.c
parent5b934f20ce232923c2066fe06e14e6ce0f29c9e0 (diff)
downloadwbg-e24f5fbd6047350e7ae3014c1ad5d2eba93d4e8b.tar.gz
main: error handling, closes #1
Diffstat (limited to 'main.c')
-rw-r--r--main.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/main.c b/main.c
index 7bdffe6..c149649 100644
--- a/main.c
+++ b/main.c
@@ -71,7 +71,9 @@ render(struct output *output)
struct buffer *buf = shm_get_buffer(
shm, width * scale, height * scale, (uintptr_t)(void *)output);
- assert(buf != NULL);
+
+ if (buf == NULL)
+ return;
uint32_t *data = pixman_image_get_data(image);
int img_width = pixman_image_get_width(image);
@@ -181,9 +183,6 @@ output_done(void *data, struct wl_output *wl_output)
LOG_INFO("output: %s %s (%dx%d, scale=%d)",
output->make, output->model, width, height, scale);
-
- assert(output->surf != NULL);
- assert(output->layer != NULL);
}
static void
@@ -344,18 +343,35 @@ main(int argc, const char *const *argv)
return EXIT_FAILURE;
}
+ int exit_code = EXIT_FAILURE;
+
display = wl_display_connect(NULL);
- assert(display != NULL);
+ if (display == NULL) {
+ LOG_ERR("failed to connect to wayland; no compositor running?");
+ goto out;
+ }
registry = wl_display_get_registry(display);
- assert(registry != NULL);
+ if (registry == NULL) {
+ LOG_ERR("failed to get wayland registry");
+ goto out;
+ }
wl_registry_add_listener(registry, &registry_listener, NULL);
wl_display_roundtrip(display);
- assert(compositor != NULL);
- assert(shm != NULL);
- assert(layer_shell != NULL);
+ if (compositor == NULL) {
+ LOG_ERR("no compositor");
+ goto out;
+ }
+ if (shm == NULL) {
+ LOG_ERR("no shared memory buffers interface");
+ goto out;
+ }
+ if (layer_shell == NULL) {
+ LOG_ERR("no layer shell interface");
+ goto out;
+ }
wl_display_roundtrip(display);
@@ -372,9 +388,10 @@ main(int argc, const char *const *argv)
sigprocmask(SIG_BLOCK, &mask, NULL);
int sig_fd = signalfd(-1, &mask, 0);
- assert(sig_fd >= 0);
-
- int exit_code = EXIT_FAILURE;
+ if (sig_fd < 0) {
+ LOG_ERRNO("failed to create signal FD");
+ goto out;
+ }
while (true) {
wl_display_flush(display);