tools: make the socket server example take a socket path

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-07-29 14:09:32 +10:00
parent 8078424c14
commit 7e6afe2373

View file

@ -43,21 +43,24 @@ static void sighandler(int signal) {
int main(int argc, char **argv)
{
const char SOCKETNAME[] = "eis.socket";
struct eis *eis = eis_socket_new_context(NULL);
assert(eis);
const char *xdgdir = getenv("XDG_RUNTIME_DIR");
assert(xdgdir != NULL);
_cleanup_free_ char *socketpath = xaprintf("%s/%s", xdgdir, SOCKETNAME);
unlink(socketpath);
_cleanup_free_ char *socketpath = NULL;
if (argc < 2) {
const char SOCKETNAME[] = "eis.socket";
const char *xdgdir = getenv("XDG_RUNTIME_DIR");
assert(xdgdir != NULL);
socketpath = xaprintf("%s/%s", xdgdir, SOCKETNAME);
} else {
socketpath = xstrdup(argv[1]);
}
/* This should be handled by libeis */
signal(SIGPIPE, SIG_IGN);
signal(SIGINT, sighandler);
int rc = eis_socket_init(eis, SOCKETNAME);
int rc = eis_socket_init(eis, socketpath);
if (rc != 0) {
fprintf(stderr, "init failed: %s\n", strerror(errno));
return 1;
@ -129,6 +132,7 @@ int main(int argc, char **argv)
}
eis_unref(eis);
unlink(socketpath);
return 0;
}