From 645ad38885bb19a33daa7bd2ec69adc1e51963d4 Mon Sep 17 00:00:00 2001 From: Bastien Dejean Date: Mon, 17 Aug 2015 10:14:07 +0200 Subject: [PATCH] Unlink the socket before binding This is a recurring request (the probability of removing an important file is probably low). Also: don't start the X setup unless we have a working socket. --- bspwm.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/bspwm.c b/bspwm.c index e65f16a..d4ee09a 100644 --- a/bspwm.c +++ b/bspwm.c @@ -77,24 +77,6 @@ int main(int argc, char *argv[]) } } - if (config_path[0] == '\0') { - char *config_home = getenv(CONFIG_HOME_ENV); - if (config_home != NULL) - snprintf(config_path, sizeof(config_path), "%s/%s/%s", config_home, WM_NAME, CONFIG_NAME); - else - snprintf(config_path, sizeof(config_path), "%s/%s/%s/%s", getenv("HOME"), ".config", WM_NAME, CONFIG_NAME); - } - - dpy = xcb_connect(NULL, &default_screen); - - if (!check_connection(dpy)) - exit(EXIT_FAILURE); - - load_settings(); - setup(); - - dpy_fd = xcb_get_file_descriptor(dpy); - char *sp = getenv(SOCKET_ENV_VAR); if (sp != NULL) { snprintf(socket_path, sizeof(socket_path), "%s", sp); @@ -114,12 +96,31 @@ int main(int argc, char *argv[]) if (sock_fd == -1) err("Couldn't create the socket.\n"); + unlink(socket_path); if (bind(sock_fd, (struct sockaddr *) &sock_address, sizeof(sock_address)) == -1) err("Couldn't bind a name to the socket.\n"); if (listen(sock_fd, SOMAXCONN) == -1) err("Couldn't listen to the socket.\n"); + if (config_path[0] == '\0') { + char *config_home = getenv(CONFIG_HOME_ENV); + if (config_home != NULL) + snprintf(config_path, sizeof(config_path), "%s/%s/%s", config_home, WM_NAME, CONFIG_NAME); + else + snprintf(config_path, sizeof(config_path), "%s/%s/%s/%s", getenv("HOME"), ".config", WM_NAME, CONFIG_NAME); + } + + dpy = xcb_connect(NULL, &default_screen); + + if (!check_connection(dpy)) + exit(EXIT_FAILURE); + + load_settings(); + setup(); + + dpy_fd = xcb_get_file_descriptor(dpy); + signal(SIGINT, sig_handler); signal(SIGHUP, sig_handler); signal(SIGTERM, sig_handler); -- 2.44.0