misc: xcb_connect() always returns a non-NULL pointer

Instead, we need to check if xcb_connection_has_error() says something
went wrong. We also need to call xcb_disconnect() on the disfunctional
XCB connection object.
This commit is contained in:
Daniel Eklöf 2019-01-19 18:45:15 +01:00
parent 406d6b3b83
commit 9d5bbe0566
5 changed files with 29 additions and 11 deletions

14
main.c
View file

@ -119,6 +119,15 @@ main(int argc, const char *const *argv)
return 1;
}
/* Connect to XCB, to be able to detect a disconnect (allowing us
* to exit) */
xcb_connection_t *xcb = xcb_connect(NULL, NULL);
if (xcb_connection_has_error(xcb) > 0) {
LOG_ERR("failed to connect to X");
xcb_disconnect(xcb);
return 1;
}
xcb_init();
bar->abort_fd = abort_fd;
@ -129,11 +138,6 @@ main(int argc, const char *const *argv)
/* Now unblock. We should be only thread receiving SIGINT */
pthread_sigmask(SIG_UNBLOCK, &signal_mask, NULL);
/* Connect to XCB, to be able to detect a disconnect (allowing us
* to exit) */
xcb_connection_t *xcb = xcb_connect(NULL, NULL);
assert(xcb != NULL);
/* Wait for SIGINT, or XCB disconnect */
while (!aborted) {
struct pollfd fds[] = {