anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0403-systemctl-pid1-do-not-warn-about-missing-install-inf.patch

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