bspwm/bspc.c

50 lines
1 KiB
C
Raw Normal View History

2012-08-02 20:41:25 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
2012-08-02 22:37:20 +02:00
#include "common.h"
2012-08-02 20:41:25 +02:00
int main(int argc, char *argv[])
{
2012-08-29 12:45:44 +02:00
int sock_fd, nbr, i;
2012-08-02 20:41:25 +02:00
struct sockaddr_un sock_address;
char *sock_path;
2012-08-29 12:45:44 +02:00
char msg[BUFSIZ];
2012-08-02 22:37:20 +02:00
char rsp[BUFSIZ];
2012-08-02 20:41:25 +02:00
2012-08-02 22:37:20 +02:00
if (argc < 2)
2012-08-07 12:17:47 +02:00
return -1;
2012-08-02 20:41:25 +02:00
sock_path = getenv(SOCK_PATH);
if (sock_path == NULL)
2012-08-07 12:17:47 +02:00
return -1;
2012-08-02 20:41:25 +02:00
2012-08-29 12:45:44 +02:00
msg[0] = '\0';
for (i = 1; i < argc; i++) {
strcat(msg, argv[i]);
if (i < (argc - 1))
strcat(msg, TOKEN_SEP);
}
2012-08-02 20:41:25 +02:00
sock_address.sun_family = AF_UNIX;
strcpy(sock_address.sun_path, sock_path);
sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
connect(sock_fd, (struct sockaddr *) &sock_address, sizeof(sock_address));
2012-08-02 22:37:20 +02:00
send(sock_fd, msg, strlen(msg), 0);
2012-08-28 21:15:29 +02:00
2012-08-02 22:37:20 +02:00
if ((nbr = recv(sock_fd, rsp, sizeof(rsp), 0)) > 0) {
rsp[nbr] = '\0';
if (strcmp(rsp, EMPTY_RESPONSE) != 0)
printf("%s", rsp);
2012-08-02 20:41:25 +02:00
}
2012-08-07 12:17:47 +02:00
2012-08-28 21:15:29 +02:00
close(sock_fd);
2012-08-07 12:17:47 +02:00
return 0;
2012-08-02 20:41:25 +02:00
}