ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
923a60
From 5f273838f41f27e0045395c1677272d9dd12496c Mon Sep 17 00:00:00 2001
923a60
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
923a60
Date: Thu, 21 Apr 2016 20:04:21 -0400
923a60
Subject: [PATCH] systemctl,pid1: do not warn about missing install info with
923a60
 "preset"
923a60
923a60
When "preset" was executed for a unit without install info, we'd warn similarly
923a60
as for "enable" and "disable". But "preset" is usually called for all units,
923a60
because the preset files are provided by the distribution, and the units are under
923a60
control of individual programs, and it's reasonable to call "preset" for all units
923a60
rather then try to do it only for the ones that can be installed.
923a60
We also don't warn about missing info for "preset-all". Thus it seems reasonable
923a60
to silently ignore units w/o install info when presetting.
923a60
923a60
(In addition, when more than one unit was specified, we'd issue the warning
923a60
only if none of them had install info. But this is probably something to fix
923a60
for enable/disable too.)
923a60
923a60
Cherry-picked from: 39207373dd638e548019ddb49929f15795b8b404
923a60
Resolves: #1373950
923a60
---
923a60
 man/systemctl.xml         | 26 +++++++++++++-------------
923a60
 src/systemctl/systemctl.c |  7 ++++---
923a60
 2 files changed, 17 insertions(+), 16 deletions(-)
923a60
923a60
diff --git a/man/systemctl.xml b/man/systemctl.xml
923a60
index 2d0678d18d..bb21f3a887 100644
923a60
--- a/man/systemctl.xml
923a60
+++ b/man/systemctl.xml
923a60
@@ -1012,22 +1012,22 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
923a60
           <term><command>preset <replaceable>NAME</replaceable>...</command></term>
923a60
 
923a60
           <listitem>
923a60
-            <para>Reset one or more unit files, as specified on the
923a60
-            command line, to the defaults configured in the preset
923a60
-            policy files. This has the same effect as
923a60
-            <command>disable</command> or <command>enable</command>,
923a60
-            depending how the unit is listed in the preset files.</para>
923a60
+            <para>Reset the enable/disable status one or more unit files, as specified on
923a60
+            the command line, to the defaults configured in the preset policy files. This
923a60
+            has the same effect as <command>disable</command> or
923a60
+            <command>enable</command>, depending how the unit is listed in the preset
923a60
+            files.</para>
923a60
 
923a60
-            <para>Use <option>--preset-mode=</option> to control
923a60
-            whether units shall be enabled and disabled, or only
923a60
-            enabled, or only disabled.</para>
923a60
+            <para>Use <option>--preset-mode=</option> to control whether units shall be
923a60
+            enabled and disabled, or only enabled, or only disabled.</para>
923a60
+
923a60
+            <para>If the unit carries no install information, it will be silently ignored
923a60
+            by this command.</para>
923a60
 
923a60
-            <para>For more information on the preset policy format,
923a60
-            see
923a60
+            <para>For more information on the preset policy format, see
923a60
             <citerefentry><refentrytitle>systemd.preset</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
923a60
-            For more information on the concept of presets, please
923a60
-            consult the 
923a60
-            url="http://freedesktop.org/wiki/Software/systemd/Preset">Preset</ulink>
923a60
+            For more information on the concept of presets, please consult the
923a60
+            <ulink url="http://freedesktop.org/wiki/Software/systemd/Preset">Preset</ulink>
923a60
             document.</para>
923a60
           </listitem>
923a60
         </varlistentry>
923a60
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
923a60
index e4b404abc2..e854508d9d 100644
923a60
--- a/src/systemctl/systemctl.c
923a60
+++ b/src/systemctl/systemctl.c
923a60
@@ -5367,6 +5367,7 @@ static int enable_unit(sd_bus *bus, char **args) {
923a60
         UnitFileChange *changes = NULL;
923a60
         unsigned n_changes = 0;
923a60
         int carries_install_info = -1;
923a60
+        bool ignore_carries_install_info = false;
923a60
         int r;
923a60
 
923a60
         if (!args[1])
923a60
@@ -5404,7 +5405,6 @@ static int enable_unit(sd_bus *bus, char **args) {
923a60
                         r = unit_file_link(arg_scope, arg_runtime, arg_root, names, arg_force, &changes, &n_changes);
923a60
                 else if (streq(verb, "preset")) {
923a60
                         r = unit_file_preset(arg_scope, arg_runtime, arg_root, names, arg_preset_mode, arg_force, &changes, &n_changes);
923a60
-                        carries_install_info = r;
923a60
                 } else if (streq(verb, "mask"))
923a60
                         r = unit_file_mask(arg_scope, arg_runtime, arg_root, names, arg_force, &changes, &n_changes);
923a60
                 else if (streq(verb, "unmask"))
923a60
@@ -5424,7 +5424,7 @@ static int enable_unit(sd_bus *bus, char **args) {
923a60
         } else {
923a60
                 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL, *m = NULL;
923a60
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
923a60
-                int expect_carries_install_info = false;
923a60
+                bool expect_carries_install_info = false;
923a60
                 bool send_force = true, send_preset_mode = false;
923a60
                 const char *method;
923a60
 
923a60
@@ -5450,6 +5450,7 @@ static int enable_unit(sd_bus *bus, char **args) {
923a60
                                 method = "PresetUnitFiles";
923a60
 
923a60
                         expect_carries_install_info = true;
923a60
+                        ignore_carries_install_info = true;
923a60
                 } else if (streq(verb, "mask"))
923a60
                         method = "MaskUnitFiles";
923a60
                 else if (streq(verb, "unmask")) {
923a60
@@ -5515,7 +5516,7 @@ static int enable_unit(sd_bus *bus, char **args) {
923a60
                         r = 0;
923a60
         }
923a60
 
923a60
-        if (carries_install_info == 0)
923a60
+        if (carries_install_info == 0 && !ignore_carries_install_info)
923a60
                 log_warning("The unit files have no [Install] section. They are not meant to be enabled\n"
923a60
                             "using systemctl.\n"
923a60
                             "Possible reasons for having this kind of units are:\n"