]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
install: never log from install functions
authorLennart Poettering <lennart@poettering.net>
Thu, 8 Oct 2015 16:33:11 +0000 (18:33 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 12 Nov 2015 16:56:49 +0000 (17:56 +0100)
Instead, let the caller do that. Fix this by moving masked unit messages
into the caller, by returning a clear error code (ESHUTDOWN) by which
this may be detected.

src/core/dbus-manager.c
src/shared/install.c
src/systemctl/systemctl.c

index eaa0fb2b376d2a02b5bab3a4404902511a16e454..efc716913b91605c386adce3b6fd3c71ea39d03d 100644 (file)
@@ -1651,6 +1651,8 @@ static int method_enable_unit_files_generic(
         scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
 
         r = call(scope, runtime, NULL, l, force, &changes, &n_changes);
+        if (r == -ESHUTDOWN)
+                return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit file is masked");
         if (r < 0)
                 return r;
 
@@ -1885,6 +1887,8 @@ static int method_add_dependency_unit_files(sd_bus_message *message, void *userd
         scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
 
         r = unit_file_add_dependency(scope, runtime, NULL, l, target, dep, force, &changes, &n_changes);
+        if (r == -ESHUTDOWN)
+                return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit file is masked");
         if (r < 0)
                 return r;
 
index e1e7c39f6efd84337b842ae6b8fbf8cee4ab1746..427e228c9d8d3db247eb479e3729ad3df62970d0 100644 (file)
@@ -1501,12 +1501,9 @@ int unit_file_add_dependency(
 
                 state = unit_file_get_state(scope, root_dir, *i);
                 if (state < 0)
-                        return log_error_errno(state, "Failed to get unit file state for %s: %m", *i);
-
-                if (state == UNIT_FILE_MASKED || state == UNIT_FILE_MASKED_RUNTIME) {
-                        log_error("Failed to enable unit: Unit %s is masked", *i);
-                        return -EOPNOTSUPP;
-                }
+                        return state;
+                if (IN_SET(state, UNIT_FILE_MASKED, UNIT_FILE_MASKED_RUNTIME))
+                        return -ESHUTDOWN;
 
                 r = install_info_add_auto(&c, *i);
                 if (r < 0)
@@ -1577,14 +1574,11 @@ int unit_file_enable(
         STRV_FOREACH(i, files) {
                 UnitFileState state;
 
-                /* We only want to know if this unit is masked, so we ignore
-                 * errors from unit_file_get_state, deferring other checks.
-                 * This allows templated units to be enabled on the fly. */
                 state = unit_file_get_state(scope, root_dir, *i);
-                if (state == UNIT_FILE_MASKED || state == UNIT_FILE_MASKED_RUNTIME) {
-                        log_error("Failed to enable unit: Unit %s is masked", *i);
-                        return -EOPNOTSUPP;
-                }
+                if (state < 0)
+                        return state;
+                if (IN_SET(state, UNIT_FILE_MASKED, UNIT_FILE_MASKED_RUNTIME))
+                        return -ESHUTDOWN;
 
                 r = install_info_add_auto(&c, *i);
                 if (r < 0)
index e9d73ea9d0d5514c5ebbc8bbe7525ac70bb85321..83ec37d19bcf6e3880d8b225d27c6d7464bdf27b 100644 (file)
@@ -5437,10 +5437,10 @@ static int enable_unit(int argc, char *argv[], void *userdata) {
                 else
                         assert_not_reached("Unknown verb");
 
-                if (r < 0) {
-                        log_error_errno(r, "Operation failed: %m");
-                        goto finish;
-                }
+                if (r == -ESHUTDOWN)
+                        return log_error_errno(r, "Unit file is masked.");
+                if (r < 0)
+                        return log_error_errno(r, "Operation failed: %m");
 
                 if (!arg_quiet)
                         dump_unit_file_changes(changes, n_changes);
@@ -5557,7 +5557,7 @@ static int enable_unit(int argc, char *argv[], void *userdata) {
 
                 r = acquire_bus(BUS_MANAGER, &bus);
                 if (r < 0)
-                        return r;
+                        goto finish;
 
                 new_args[0] = (char*) (streq(argv[0], "enable") ? "start" : "stop");
                 for (i = 0; i < n_changes; i++)
@@ -5603,7 +5603,8 @@ static int add_dependency(int argc, char *argv[], void *userdata) {
                 unsigned n_changes = 0;
 
                 r = unit_file_add_dependency(arg_scope, arg_runtime, arg_root, names, target, dep, arg_force, &changes, &n_changes);
-
+                if (r == -ESHUTDOWN)
+                        return log_error_errno(r, "Unit file is masked.");
                 if (r < 0)
                         return log_error_errno(r, "Can't add dependency: %m");