summaryrefslogtreecommitdiff
path: root/src/daemon/dlt_daemon_unix_socket.c
diff options
context:
space:
mode:
authorManikandanChockalingam <manikandan.chockalingam@in.bosch.com>2018-05-18 11:17:31 +0530
committerChristoph Lipka <clipka@users.noreply.github.com>2018-05-18 07:47:31 +0200
commitda6eefe5cac244421c5af413c54e420717e11c9e (patch)
treee7eb7745fbc5e0edd3e2bede4d008a05250f1a18 /src/daemon/dlt_daemon_unix_socket.c
parentf549f5527148b32a15489aae75c9e4557e19cbd4 (diff)
downloadDLT-daemon-da6eefe5cac244421c5af413c54e420717e11c9e.tar.gz
IPC: Unix socket added (#43)
* IPC: Unix socket added The user can select either FIFO or UNIX socket as IPC between user library and daemon through CMakelist option. Socket path configurable for both FIFO and Unix Socket now configurable in CMake Signed-off-by: Christoph Lipka <clipka@de.adit-jv.com> Signed-off-by: ManikandanC <Manikandan.Chockalingam@in.bosch.com>
Diffstat (limited to 'src/daemon/dlt_daemon_unix_socket.c')
-rw-r--r--src/daemon/dlt_daemon_unix_socket.c31
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);
-}