diff options
author | vg <vgm+dev@devys.org> | 2024-02-23 15:55:08 +0100 |
---|---|---|
committer | vg <vgm+dev@devys.org> | 2024-02-23 15:55:08 +0100 |
commit | d3a1c560e6a6f58d0159864f70ec75fb07ed1933 (patch) | |
tree | 209b59fe9765c0d8964f9b7bf0fa0371d54d3a99 | |
parent | d7d9e9062e125f725848017b6657b7eff0c266b1 (diff) | |
download | scripts-d3a1c560e6a6f58d0159864f70ec75fb07ed1933.tar.gz scripts-d3a1c560e6a6f58d0159864f70ec75fb07ed1933.tar.bz2 scripts-d3a1c560e6a6f58d0159864f70ec75fb07ed1933.zip |
add umask call to dictate rights for unix socket
-rw-r--r-- | small-codes/syslog-listen.c | 8 |
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"); |