From f42d5e38859c65a186acd0da94bbeeca12faf7a2 Mon Sep 17 00:00:00 2001 From: David Rheinsberg Date: Thu, 2 May 2019 17:33:34 +0200 Subject: [PATCH] launch: improve error handling for opendir() This improves the error-handling of opendir() by always printing diagnostics. Furthermore, it aligns the behavior with dbus-deamon and ignores EACCES. Signed-off-by: David Rheinsberg Upstream-Status: dbus-broker@f42d5e38859c65a186acd0da94bbeeca12faf7a2 --- src/launch/launcher.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/launch/launcher.c b/src/launch/launcher.c index 31a5364..2ec4bda 100644 --- a/src/launch/launcher.c +++ b/src/launch/launcher.c @@ -749,10 +749,23 @@ static int launcher_load_service_dir(Launcher *launcher, const char *dirpath, NS dir = opendir(dirpath); if (!dir) { - if (errno == ENOENT || errno == ENOTDIR) + if (errno == ENOENT || errno == ENOTDIR) { return 0; - else + } else if (errno == EACCES) { + log_append_here(&launcher->log, LOG_ERR, 0, NULL); + r = log_commitf(&launcher->log, "Access denied to service directory '%s'\n", dirpath); + if (r) + return error_fold(r); + + return 0; + } else { + log_append_here(&launcher->log, LOG_ERR, errno, NULL); + r = log_commitf(&launcher->log, "Unable to open service directory '%s': %m\n", dirpath); + if (r) + return error_fold(r); + return error_origin(-errno); + } } r = dirwatch_add(launcher->dirwatch, dirpath); -- 2.20.1