Allow connections via UNIX sockets.

This is mainly useful for control connections. The client must still present
the control cookie from the PID file.
This commit is contained in:
Guus Sliepen 2013-01-17 18:12:55 +01:00
parent 2c14123062
commit 94587264bd
6 changed files with 108 additions and 0 deletions

View file

@ -666,6 +666,26 @@ static bool connect_tincd(bool verbose) {
}
#endif
#ifndef HAVE_MINGW
struct sockaddr_un sa;
sa.sun_family = AF_UNIX;
strncpy(sa.sun_path, unixsocketname, sizeof sa.sun_path);
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if(fd < 0) {
if(verbose)
fprintf(stderr, "Cannot create UNIX socket: %s\n", sockstrerror(sockerrno));
return false;
}
if(connect(fd, (struct sockaddr *)&sa, sizeof sa) < 0) {
if(verbose)
fprintf(stderr, "Cannot connect to UNIX socket %s: %s\n", unixsocketname, sockstrerror(sockerrno));
close(fd);
fd = -1;
return false;
}
#else
struct addrinfo hints = {
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
@ -706,6 +726,7 @@ static bool connect_tincd(bool verbose) {
}
freeaddrinfo(res);
#endif
char data[4096];
int version;