diff options
author | Sebastien RAILLET <sebastien.raillet@marelli.com> | 2021-09-22 16:54:31 +0200 |
---|---|---|
committer | Saya Sugiura <39760799+ssugiura@users.noreply.github.com> | 2021-10-12 14:55:32 +0900 |
commit | 1919000c897ccf0f88a5584faf3a2efc1a7a3c30 (patch) | |
tree | 2e10abe01f75c9ac2a3427b3a3d5ecf893a800e9 /src/daemon/dlt_daemon_unix_socket.c | |
parent | 9214f892302615beed95222b56065655a40ff2a7 (diff) | |
download | DLT-daemon-1919000c897ccf0f88a5584faf3a2efc1a7a3c30.tar.gz |
dlt-daemon: create sockets using "android way"
* Before this commit, dlt-daemon sockets were created inside
/data/local/tmp. This works but have many drawbacks:
- /data/local/tmp isn't always a tmpfs depending of the android
system you have. Means sockets are potentially created on a
filesystem which binds to a real device
- as the sockets are created by the dlt-daemon itself, this
prevent the usage of specific SELinux labels / contexts as
they will inherit the label / context from its parent
location (e.g the ones from /data/local/tmp). This prevent a
fine control of the SELinux label / context that you would like
to apply on them
* This commit adapts the dlt-daemon in such way:
- application and control sockets are now created inside
/dev/socket which is the standard path for sockets on android
- these sockets are now created by init (see dlt-daemon.rc) and
their fds are recovered by dlt-daemon through a specific android
API (dlt_daemon_unix_android_get_socket). If the fds can't be
recovered, we fallback to the previous mechanism by creating
by ourself the sockets (even if this will prevent SELinux
label / context on this socket)
- all these modifications have been put under compilation flag
for android
Signed-off-by: Sebastien RAILLET <sebastien.raillet@marelli.com>
Diffstat (limited to 'src/daemon/dlt_daemon_unix_socket.c')
-rw-r--r-- | src/daemon/dlt_daemon_unix_socket.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/daemon/dlt_daemon_unix_socket.c b/src/daemon/dlt_daemon_unix_socket.c index b58beb1..ea889b0 100644 --- a/src/daemon/dlt_daemon_unix_socket.c +++ b/src/daemon/dlt_daemon_unix_socket.c @@ -28,17 +28,59 @@ #include <stdlib.h> #include <string.h> #include <sys/un.h> -#include <sys/socket.h> +#if defined(ANDROID) +# include <cutils/sockets.h> /* for android_get_control_socket() */ +# include <libgen.h> /* for basename() */ +#else +# include <sys/socket.h> /* for socket(), connect(), (), and recv() */ +#endif #include <sys/types.h> #include <sys/stat.h> #include <syslog.h> #include <errno.h> + #include "dlt-daemon.h" #include "dlt_common.h" #include "dlt-daemon_cfg.h" #include "dlt_daemon_socket.h" #include "dlt_daemon_unix_socket.h" +#ifdef ANDROID +DltReturnValue dlt_daemon_unix_android_get_socket(int *sock, const char *sock_path) +{ + DltReturnValue ret = DLT_RETURN_OK; + + if ((sock == NULL) || (sock_path == NULL)) { + dlt_log(LOG_ERR, "dlt_daemon_unix_android_get_socket: arguments invalid"); + ret = DLT_RETURN_WRONG_PARAMETER; + } + else { + const char* sock_name = basename(sock_path); + if (sock_name == NULL) { + dlt_log(LOG_WARNING, + "dlt_daemon_unix_android_get_socket: can't get socket name from its path"); + ret = DLT_RETURN_ERROR; + } + else { + *sock = android_get_control_socket(sock_name); + if (*sock < 0) { + dlt_log(LOG_WARNING, + "dlt_daemon_unix_android_get_socket: can get socket from init"); + ret = DLT_RETURN_ERROR; + } + else { + if (listen(*sock, 1) == -1) { + dlt_vlog(LOG_WARNING, "unix socket: listen error: %s", strerror(errno)); + ret = DLT_RETURN_ERROR; + } + } + } + } + + return ret; +} +#endif + int dlt_daemon_unix_socket_open(int *sock, char *sock_path, int type, int mask) { struct sockaddr_un addr; |