Skip to content
Snippets Groups Projects
Commit 5fe5bbb4 authored by Petr Baudis's avatar Petr Baudis
Browse files

compctld: Fix few issues with the creation of socket file

parent c9a27c95
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include <syslog.h> #include <syslog.h>
...@@ -101,12 +102,14 @@ main(int argc, char *argv[]) ...@@ -101,12 +102,14 @@ main(int argc, char *argv[])
int s = socket(AF_UNIX, SOCK_STREAM, 0); int s = socket(AF_UNIX, SOCK_STREAM, 0);
int on = 1; setsockopt(s, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)); int on = 1; setsockopt(s, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
/* TODO: Protect against double execution? */
unlink(SOCKFILE);
struct sockaddr_un sun = { .sun_family = AF_UNIX, .sun_path = SOCKFILE }; struct sockaddr_un sun = { .sun_family = AF_UNIX, .sun_path = SOCKFILE };
if (bind(s, (struct sockaddr *) &sun, sizeof(sun.sun_family) + strlen(sun.sun_path) + 1) < 0) { if (bind(s, (struct sockaddr *) &sun, sizeof(sun.sun_family) + strlen(sun.sun_path) + 1) < 0) {
logperror(SOCKFILE); logperror(SOCKFILE);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
chmod(SOCKFILE, 0777);
listen(s, 10); listen(s, 10);
int fd; int fd;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment