summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-10-08 17:25:15 +0200
committerLennart Poettering <lennart@poettering.net>2018-10-08 18:49:45 +0200
commit339731dba1f6354898fcffca252f0813bd77a565 (patch)
tree91bf791da678775ed95c2a220456975ddacf8b36
parent40a7b232deb0bf3f8ec2d9ab009714597f84a30b (diff)
downloadsystemd-339731dba1f6354898fcffca252f0813bd77a565.tar.gz
portable: properly handle if the unit file directory for portable service images doesn't exist
if the dir doesn#t exist then let's consider this indication for "this image isn't attached".
-rw-r--r--src/portable/portable.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/portable/portable.c b/src/portable/portable.c
index 03eeb111ce..49eaf84b1a 100644
--- a/src/portable/portable.c
+++ b/src/portable/portable.c
@@ -1150,8 +1150,12 @@ int portable_detach(
where = attached_path(&paths, flags);
d = opendir(where);
- if (!d)
+ if (!d) {
+ if (errno == ENOENT)
+ goto not_found;
+
return log_debug_errno(errno, "Failed to open '%s' directory: %m", where);
+ }
unit_files = set_new(&string_hash_ops);
if (!unit_files)
@@ -1213,10 +1217,8 @@ int portable_detach(
}
}
- if (set_isempty(unit_files)) {
- log_debug("No unit files associated with '%s' found. Image not attached?", name_or_path);
- return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "No unit files associated with '%s' found. Image not attached?", name_or_path);
- }
+ if (set_isempty(unit_files))
+ goto not_found;
SET_FOREACH(item, unit_files, iterator) {
_cleanup_free_ char *md = NULL;
@@ -1290,6 +1292,10 @@ int portable_detach(
}
return ret;
+
+not_found:
+ log_debug("No unit files associated with '%s' found. Image not attached?", name_or_path);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "No unit files associated with '%s' found. Image not attached?", name_or_path);
}
static int portable_get_state_internal(
@@ -1317,8 +1323,15 @@ static int portable_get_state_internal(
where = attached_path(&paths, flags);
d = opendir(where);
- if (!d)
+ if (!d) {
+ if (errno == ENOENT) {
+ /* If the 'attached' directory doesn't exist at all, then we know for sure this image isn't attached. */
+ *ret = PORTABLE_DETACHED;
+ return 0;
+ }
+
return log_debug_errno(errno, "Failed to open '%s' directory: %m", where);
+ }
unit_files = set_new(&string_hash_ops);
if (!unit_files)