-/* 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>
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;
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");