i3-dump-log -f: switch from pthreads to UNIX sockets

fixes #4117
This commit is contained in:
Michael Stapelberg
2021-01-15 16:12:55 +01:00
committed by Michael Stapelberg
parent 131a6158c8
commit dcd6079c9b
14 changed files with 142 additions and 82 deletions

View File

@ -25,20 +25,20 @@
*
*/
int create_socket(const char *filename, char **out_socketpath) {
int sockfd;
char *resolved = resolve_tilde(filename);
DLOG("Creating UNIX socket at %s\n", resolved);
char *copy = sstrdup(resolved);
const char *dir = dirname(copy);
if (!path_exists(dir))
if (!path_exists(dir)) {
mkdirp(dir, DEFAULT_DIR_MODE);
}
free(copy);
/* Unlink the unix domain socket before */
unlink(resolved);
if ((sockfd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) {
int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (sockfd < 0) {
perror("socket()");
free(resolved);
return -1;

View File

@ -15,6 +15,7 @@ void set_nonblock(int sockfd) {
return;
}
flags |= O_NONBLOCK;
if (fcntl(sockfd, F_SETFL, flags) < 0)
if (fcntl(sockfd, F_SETFL, flags) < 0) {
err(-1, "Could not set O_NONBLOCK");
}
}