forked from external/yambar
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:
parent
406d6b3b83
commit
9d5bbe0566
5 changed files with 29 additions and 11 deletions
9
bar.c
9
bar.c
|
@ -324,8 +324,13 @@ run(struct bar *_bar)
|
|||
/* TODO: a lot of this (up to mapping the window) could be done in bar_new() */
|
||||
xcb_generic_error_t *e;
|
||||
|
||||
bar->conn = xcb_connect(NULL, NULL);
|
||||
assert(bar->conn != NULL);
|
||||
int default_screen;
|
||||
bar->conn = xcb_connect(NULL, &default_screen);
|
||||
if (xcb_connection_has_error(bar->conn) > 0) {
|
||||
LOG_ERR("failed to connect to X");
|
||||
xcb_disconnect(bar->conn);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const xcb_setup_t *setup = xcb_get_setup(bar->conn);
|
||||
|
||||
|
|
14
main.c
14
main.c
|
@ -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[] = {
|
||||
|
|
|
@ -376,7 +376,13 @@ run(struct module *mod)
|
|||
|
||||
struct sockaddr_un addr = {.sun_family = AF_UNIX};
|
||||
{
|
||||
xcb_connection_t *conn = xcb_connect(NULL, NULL);
|
||||
int default_screen;
|
||||
xcb_connection_t *conn = xcb_connect(NULL, &default_screen);
|
||||
if (xcb_connection_has_error(conn) > 0) {
|
||||
LOG_ERR("failed to connect to X");
|
||||
xcb_disconnect(conn);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const xcb_setup_t *setup = xcb_get_setup(conn);
|
||||
xcb_screen_t *screen = xcb_setup_roots_iterator(setup).data;
|
||||
|
|
|
@ -196,9 +196,11 @@ run(struct module *mod)
|
|||
{
|
||||
struct private *m = mod->private;
|
||||
|
||||
m->conn = xcb_connect(NULL, NULL);
|
||||
if (m->conn == NULL) {
|
||||
int default_screen;
|
||||
m->conn = xcb_connect(NULL, &default_screen);
|
||||
if (xcb_connection_has_error(m->conn) > 0) {
|
||||
LOG_ERR("failed to connect to X");
|
||||
xcb_disconnect(m->conn);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
3
xcb.c
3
xcb.c
|
@ -48,8 +48,9 @@ bool
|
|||
xcb_init(void)
|
||||
{
|
||||
xcb_connection_t *conn = xcb_connect(NULL, NULL);
|
||||
if (conn == NULL) {
|
||||
if (xcb_connection_has_error(conn) > 0) {
|
||||
LOG_ERR("failed to connect to X");
|
||||
xcb_disconnect(conn);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue