diff options
Diffstat (limited to 'src/daemon/dlt_daemon_unix_socket.c')
-rw-r--r-- | src/daemon/dlt_daemon_unix_socket.c | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/src/daemon/dlt_daemon_unix_socket.c b/src/daemon/dlt_daemon_unix_socket.c index 05af5cb..0ed92ad 100644 --- a/src/daemon/dlt_daemon_unix_socket.c +++ b/src/daemon/dlt_daemon_unix_socket.c @@ -30,6 +30,8 @@ #include <stdlib.h> #include <sys/un.h> #include <sys/socket.h> +#include <sys/types.h> +#include <sys/stat.h> #include <syslog.h> #include <errno.h> #include "dlt-daemon.h" @@ -40,9 +42,10 @@ char err_string[DLT_DAEMON_TEXTBUFSIZE]; -int dlt_daemon_unix_socket_open(int *sock, char *sock_path) +int dlt_daemon_unix_socket_open(int *sock, char *sock_path, int type, int mask) { struct sockaddr_un addr; + int old_mask; if (sock == NULL || sock_path == NULL) { @@ -50,7 +53,7 @@ int dlt_daemon_unix_socket_open(int *sock, char *sock_path) return -1; } - if ((*sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) + if ((*sock = socket(AF_UNIX, type, 0)) == -1) { dlt_log(LOG_WARNING, "unix socket: socket() error"); return -1; @@ -62,6 +65,9 @@ int dlt_daemon_unix_socket_open(int *sock, char *sock_path) unlink(sock_path); + /* set appropriate access permissions */ + old_mask = umask(mask); + if (bind(*sock, (struct sockaddr *) &addr, sizeof(addr)) == -1) { dlt_log(LOG_WARNING, "unix socket: bind() error"); @@ -74,6 +80,9 @@ int dlt_daemon_unix_socket_open(int *sock, char *sock_path) return -1; } + /* restore permissions */ + umask(old_mask); + return 0; } @@ -89,21 +98,3 @@ int dlt_daemon_unix_socket_close(int sock) return ret; } - -int dlt_daemon_unix_socket_send( - int sock, - void *data1, - int size1, - void *data2, - int size2, - char serialheader) -{ - /* re-use socket send function */ - return dlt_daemon_socket_send( - sock, - data1, - size1, - data2, - size2, - serialheader); -} |