aboutsummaryrefslogtreecommitdiffstats
path: root/small-codes
diff options
context:
space:
mode:
Diffstat (limited to 'small-codes')
-rw-r--r--small-codes/syslog-listen.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/small-codes/syslog-listen.c b/small-codes/syslog-listen.c
index e248608..4b58271 100644
--- a/small-codes/syslog-listen.c
+++ b/small-codes/syslog-listen.c
@@ -6,13 +6,14 @@
// compile with gcc/clang -o syslog-listen syslog-listen.c
-#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdio.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/un.h>
-#include <errno.h>
+#include <unistd.h>
#define PERROR(code, msg) { if ((code) == -1) { perror((msg)); exit(1); } }
@@ -31,6 +32,7 @@ int main(int argc, const char** argv)
int sock = socket(AF_UNIX, SOCK_DGRAM, 0);
PERROR(sock, "socket");
unlink(argv[1]); // no need to test ret as bind will crash if needed
+ umask(0007); // by default allow user/group calling the program
int ret = bind(sock, (struct sockaddr*)&sock_file, sizeof(sock_file));
PERROR(ret, "bind");