]> git.lizzy.rs Git - bspwm.git/blobdiff - bspc.c
Be verbose regarding broken connections
[bspwm.git] / bspc.c
diff --git a/bspc.c b/bspc.c
index 3903eaf4dda13cfc53e78a8f6499afac4e153285..b50a8fcee57a20a290a82eb887f5aae1b38a08c9 100644 (file)
--- a/bspc.c
+++ b/bspc.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2014, Bastien Dejean
+/* Copyright (c) 2012, Bastien Dejean
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those
- * of the authors and should not be interpreted as representing official policies,
- * either expressed or implied, of the FreeBSD Project.
  */
 
 #include <stdlib.h>
@@ -47,11 +43,24 @@ int main(int argc, char *argv[])
                err("No arguments given.\n");
 
        sock_address.sun_family = AF_UNIX;
-       char *sp = getenv(SOCKET_ENV_VAR);
-       if (sp != NULL)
+       char *sp;
+
+       if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+               err("Failed to create the socket.\n");
+
+       sp = getenv(SOCKET_ENV_VAR);
+       if (sp != NULL) {
                snprintf(sock_address.sun_path, sizeof(sock_address.sun_path), "%s", sp);
-       else
-               snprintf(sock_address.sun_path, sizeof(sock_address.sun_path), SOCKET_PATH_TPL, getenv("DISPLAY"));
+       } else {
+               char *host = NULL;
+               int dn = 0, sn = 0;
+               if (xcb_parse_display(NULL, &host, &dn, &sn) != 0)
+                       snprintf(sock_address.sun_path, sizeof(sock_address.sun_path), SOCKET_PATH_TPL, host, dn, sn);
+               free(host);
+       }
+
+       if (connect(fd, (struct sockaddr *) &sock_address, sizeof(sock_address)) == -1)
+               err("Failed to connect to the socket.\n");
 
        argc--, argv++;
        int msg_len = 0;
@@ -61,12 +70,6 @@ int main(int argc, char *argv[])
                msg_len += n;
        }
 
-       if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
-               err("Failed to create the socket.\n");
-
-       if (connect(fd, (struct sockaddr *) &sock_address, sizeof(sock_address)) == -1)
-               err("Failed to connect to the socket.\n");
-
        if (send(fd, msg, msg_len, 0) == -1)
                err("Failed to send the data.\n");