add awesome-client to communicate via awesome socket

This commit is contained in:
daniel@brinkers.de 2007-10-27 13:22:47 +02:00 committed by Julien Danjou
parent 0bbfff8026
commit 23d2e4dd57
2 changed files with 53 additions and 1 deletions

View File

@ -6,7 +6,10 @@ include config.mk
SRC = client.c draw.c event.c layout.c awesome.c tag.c util.c config.c screen.c statusbar.c uicb.c tab.c window.c SRC = client.c draw.c event.c layout.c awesome.c tag.c util.c config.c screen.c statusbar.c uicb.c tab.c window.c
OBJ = ${SRC:.c=.o} ${LAYOUTS:.c=.o} OBJ = ${SRC:.c=.o} ${LAYOUTS:.c=.o}
all: options awesome SRCCLIENT = awesome-client.c util.c
OBJCLIENT = ${SRCCLIENT:.c=.o}
all: options awesome awesome-client
options: options:
@echo awesome build options: @echo awesome build options:
@ -21,6 +24,12 @@ options:
${OBJ}: awesome.h config.mk ${OBJ}: awesome.h config.mk
${OBJCLIENT}: config.mk
awesome-client: ${OBJCLIENT}
@echo -e \\t\(CC\) ${OBJCLIENT} -o $@
@${CC} -o $@ ${OBJCLIENT} ${LDFLAGS}
awesome: ${OBJ} awesome: ${OBJ}
@echo -e \\t\(CC\) ${OBJ} -o $@ @echo -e \\t\(CC\) ${OBJ} -o $@
@${CC} -o $@ ${OBJ} ${LDFLAGS} @${CC} -o $@ ${OBJ} ${LDFLAGS}

43
awesome-client.c Normal file
View File

@ -0,0 +1,43 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include "util.h"
#define CONTROL_UNIX_SOCKET_PATH ".awesome_so_ctl"
int
main()
{
ssize_t path_len;
struct sockaddr_un addr;
char buf[1024];
const char *homedir;
int csfd;
homedir = getenv("HOME");
path_len = a_strlen(homedir) + a_strlen(CONTROL_UNIX_SOCKET_PATH) + 2;
if(path_len >= (int)sizeof(addr.sun_path))
{
fprintf(stderr, "error: path of control UNIX domain socket is too long");
exit(1);
}
a_strcpy(addr.sun_path, path_len, homedir);
a_strcat(addr.sun_path, path_len, "/");
a_strcat(addr.sun_path, path_len, CONTROL_UNIX_SOCKET_PATH);
csfd = socket(AF_UNIX, SOCK_DGRAM, 0);
if(csfd < 0)
perror("error opening UNIX domain socket");
addr.sun_family = AF_UNIX;
while(fgets(buf, sizeof(buf), stdin))
{
if(sendto(csfd, buf, strlen(buf), MSG_NOSIGNAL, (struct sockaddr*)&addr, sizeof(addr)) == -1)
perror("error sending datagram");
}
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99