diff options
author | Alexander Mohr <alexander.m.mohr@daimler.com> | 2021-10-20 12:32:42 +0200 |
---|---|---|
committer | Saya Sugiura <39760799+ssugiura@users.noreply.github.com> | 2021-10-21 08:40:31 +0900 |
commit | d2214ac5075c56ba2bbd7f33f16171e1bad6fa48 (patch) | |
tree | 573f05039c4d76ec332cb5e5890b55e18387233c /src/daemon | |
parent | cc7ed02b543f384f37c8fb28b33ed48c038ac648 (diff) | |
download | DLT-daemon-d2214ac5075c56ba2bbd7f33f16171e1bad6fa48.tar.gz |
dlt-daemon: Only create directories if they do not exist yet
dlt_mkdir_recursive runs mkdir for directories which already exist.
This fails if the directory already exists and the dlt-daemon
does not have the permissions to change the mode on the directory.
On many systems the directories are not created by dlt-daemon
itself but rather through the build system or while the
root filesystem is created.
At this stage the permissions are already set properly
and they might be less permissive than what dlt-daemon expects
but still sufficient.
For example is rwx not necessary for each directory in the tree.
Before this commit the following scenario would fail:
* Path is set to /mnt/dlt/
* mnt has 755 permissions for root
* dlt has 755 for dlt user
As dlt daemon would try to run mkdir on /mnt
dlt_mkdir_recursive would fail due to lack of permissions
although the permissions are sufficient for dlt-daemon to
work and write its files into /mnt/dlt/
With this commit /mnt would not be created anymore because it
already exists.
If the permissions are not sufficient for dlt-daemon to write in
it will fail when trying to create files and exit at this point
Signed-off-by: Alexander Mohr <alexander.m.mohr@daimler.com>
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/dlt-daemon.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 955c231..55d5954 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -33,7 +33,7 @@ #include <arpa/inet.h> /* for sockaddr_in and inet_addr() */ #include <stdlib.h> /* for atoi() and exit() */ #include <string.h> /* for memset() */ -#include <unistd.h> /* for close() */ +#include <unistd.h> /* for close() and access */ #include <fcntl.h> #include <signal.h> #include <syslog.h> @@ -837,12 +837,16 @@ static int dlt_mkdir_recursive(const char *dir) for (p = tmp + 1; ((*p) && (ret == 0)) || ((ret == -1 && errno == EEXIST) && (p != end)); p++) if (*p == '/') { *p = 0; - ret = mkdir(tmp, - #ifdef DLT_DAEMON_USE_FIFO_IPC - S_IRWXU); - #else - S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH /*S_IRWXU*/); - #endif + + if (access(tmp, F_OK) != 0 && errno == ENOENT) { + ret = mkdir(tmp, + #ifdef DLT_DAEMON_USE_FIFO_IPC + S_IRWXU); + #else + S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH /*S_IRWXU*/); + #endif + } + *p = '/'; } |