|
|
923a60 |
From 2047b2d0db643a168144b708cf58091ca47acb21 Mon Sep 17 00:00:00 2001
|
|
|
923a60 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
923a60 |
Date: Wed, 4 May 2016 10:10:57 -0400
|
|
|
923a60 |
Subject: [PATCH] shared/install: handle dangling aliases as an explicit case,
|
|
|
923a60 |
report nicely
|
|
|
923a60 |
|
|
|
923a60 |
This fixes 'preset-all' with a unit that is a dangling symlink.
|
|
|
923a60 |
|
|
|
923a60 |
$ systemctl --root=/ preset-all
|
|
|
923a60 |
Unit syslog.service is an alias to a unit that is not present, ignoring.
|
|
|
923a60 |
Unit auditd.service is masked, ignoring.
|
|
|
923a60 |
Unit NetworkManager.service is masked, ignoring.
|
|
|
923a60 |
|
|
|
923a60 |
Cherry-picked from: 893275df36c8c358d3c0b851ca255a6169dac138
|
|
|
923a60 |
Resolves: #1375097
|
|
|
923a60 |
---
|
|
|
923a60 |
src/libsystemd/sd-bus/bus-util.c | 2 ++
|
|
|
923a60 |
src/shared/install.c | 17 +++++++++++++----
|
|
|
923a60 |
src/shared/install.h | 1 +
|
|
|
923a60 |
src/systemctl/systemctl.c | 3 +++
|
|
|
923a60 |
4 files changed, 19 insertions(+), 4 deletions(-)
|
|
|
923a60 |
|
|
|
923a60 |
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
|
|
|
923a60 |
index 75d03708e2..d357760870 100644
|
|
|
923a60 |
--- a/src/libsystemd/sd-bus/bus-util.c
|
|
|
923a60 |
+++ b/src/libsystemd/sd-bus/bus-util.c
|
|
|
923a60 |
@@ -1897,6 +1897,8 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, Un
|
|
|
923a60 |
log_info("Removed symlink %s.", path);
|
|
|
923a60 |
else if (streq(type, "masked"))
|
|
|
923a60 |
log_info("Unit %s is masked, ignoring.", path);
|
|
|
923a60 |
+ else if (streq(type, "dangling"))
|
|
|
923a60 |
+ log_info("Unit %s is an alias to a unit that is not present, ignoring.", path);
|
|
|
923a60 |
else
|
|
|
923a60 |
log_notice("Manager reported unknown change type \"%s\" for %s.", type, path);
|
|
|
923a60 |
}
|
|
|
923a60 |
diff --git a/src/shared/install.c b/src/shared/install.c
|
|
|
923a60 |
index 62da52d3b3..b0a29ddd7e 100644
|
|
|
923a60 |
--- a/src/shared/install.c
|
|
|
923a60 |
+++ b/src/shared/install.c
|
|
|
923a60 |
@@ -1253,12 +1253,15 @@ static int install_info_traverse(
|
|
|
923a60 |
if (r < 0)
|
|
|
923a60 |
return r;
|
|
|
923a60 |
|
|
|
923a60 |
+ /* Try again, with the new target we found. */
|
|
|
923a60 |
r = unit_file_search(c, i, paths, root_dir, flags);
|
|
|
923a60 |
- if (r < 0)
|
|
|
923a60 |
- return r;
|
|
|
923a60 |
+ if (r == -ENOENT)
|
|
|
923a60 |
+ /* Translate error code to highlight this specific case */
|
|
|
923a60 |
+ return -ENOLINK;
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
- /* Try again, with the new target we found. */
|
|
|
923a60 |
+ if (r < 0)
|
|
|
923a60 |
+ return r;
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
if (ret)
|
|
|
923a60 |
@@ -1528,7 +1531,9 @@ static int install_context_mark_for_removal(
|
|
|
923a60 |
return r;
|
|
|
923a60 |
|
|
|
923a60 |
r = install_info_traverse(scope, c, root_dir, paths, i, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS, NULL);
|
|
|
923a60 |
- if (r < 0)
|
|
|
923a60 |
+ if (r == -ENOLINK)
|
|
|
923a60 |
+ return 0;
|
|
|
923a60 |
+ else if (r < 0)
|
|
|
923a60 |
return r;
|
|
|
923a60 |
|
|
|
923a60 |
if (i->type != UNIT_FILE_TYPE_REGULAR)
|
|
|
923a60 |
@@ -2405,6 +2410,9 @@ int unit_file_preset_all(
|
|
|
923a60 |
if (r == -ESHUTDOWN)
|
|
|
923a60 |
r = unit_file_changes_add(changes, n_changes,
|
|
|
923a60 |
UNIT_FILE_IS_MASKED, de->d_name, NULL);
|
|
|
923a60 |
+ else if (r == -ENOLINK)
|
|
|
923a60 |
+ r = unit_file_changes_add(changes, n_changes,
|
|
|
923a60 |
+ UNIT_FILE_IS_DANGLING, de->d_name, NULL);
|
|
|
923a60 |
if (r < 0)
|
|
|
923a60 |
return r;
|
|
|
923a60 |
}
|
|
|
923a60 |
@@ -2539,6 +2547,7 @@ static const char* const unit_file_change_type_table[_UNIT_FILE_CHANGE_TYPE_MAX]
|
|
|
923a60 |
[UNIT_FILE_SYMLINK] = "symlink",
|
|
|
923a60 |
[UNIT_FILE_UNLINK] = "unlink",
|
|
|
923a60 |
[UNIT_FILE_IS_MASKED] = "masked",
|
|
|
923a60 |
+ [UNIT_FILE_IS_DANGLING] = "dangling",
|
|
|
923a60 |
};
|
|
|
923a60 |
|
|
|
923a60 |
DEFINE_STRING_TABLE_LOOKUP(unit_file_change_type, UnitFileChangeType);
|
|
|
923a60 |
diff --git a/src/shared/install.h b/src/shared/install.h
|
|
|
923a60 |
index f0e36661b5..7e40445d36 100644
|
|
|
923a60 |
--- a/src/shared/install.h
|
|
|
923a60 |
+++ b/src/shared/install.h
|
|
|
923a60 |
@@ -61,6 +61,7 @@ typedef enum UnitFileChangeType {
|
|
|
923a60 |
UNIT_FILE_SYMLINK,
|
|
|
923a60 |
UNIT_FILE_UNLINK,
|
|
|
923a60 |
UNIT_FILE_IS_MASKED,
|
|
|
923a60 |
+ UNIT_FILE_IS_DANGLING,
|
|
|
923a60 |
_UNIT_FILE_CHANGE_TYPE_MAX,
|
|
|
923a60 |
_UNIT_FILE_CHANGE_TYPE_INVALID = -1
|
|
|
923a60 |
} UnitFileChangeType;
|
|
|
923a60 |
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
|
|
|
923a60 |
index a688d69052..39f0150e52 100644
|
|
|
923a60 |
--- a/src/systemctl/systemctl.c
|
|
|
923a60 |
+++ b/src/systemctl/systemctl.c
|
|
|
923a60 |
@@ -1955,6 +1955,9 @@ static void dump_unit_file_changes(const UnitFileChange *changes, unsigned n_cha
|
|
|
923a60 |
case UNIT_FILE_IS_MASKED:
|
|
|
923a60 |
log_info("Unit %s is masked, ignoring.", changes[i].path);
|
|
|
923a60 |
break;
|
|
|
923a60 |
+ case UNIT_FILE_IS_DANGLING:
|
|
|
923a60 |
+ log_info("Unit %s is an alias to a unit that is not present, ignoring.", changes[i].path);
|
|
|
923a60 |
+ break;
|
|
|
923a60 |
default:
|
|
|
923a60 |
assert_not_reached("bad change type");
|
|
|
923a60 |
}
|