]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl-enable: warn if disabled/masked units has active triggering units 29333/head
authorMike Yuan <me@yhndnzj.com>
Tue, 26 Sep 2023 15:21:23 +0000 (23:21 +0800)
committerMike Yuan <me@yhndnzj.com>
Wed, 27 Sep 2023 21:24:51 +0000 (05:24 +0800)
Closes #311

man/systemctl.xml
src/systemctl/systemctl-enable.c

index 1b7179e10acbe79361ba470ab9d5289736f0ad20..d07c8eae28b929d8eda21522e0153e9c39227ef6 100644 (file)
@@ -896,6 +896,10 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
             executed. This output may be suppressed by passing <option>--quiet</option>.
             </para>
 
+            <para>If a unit gets disabled but its triggering units are still active, a warning containing
+            the names of the triggering units is shown. <option>--no-warn</option> can be used to suppress
+            the warning.</para>
+
             <para>When this command is used with <option>--user</option>, the units being operated on might
             still be enabled in global scope, and thus get started automatically even after a successful
             disablement in user scope. In this case, a warning about it is shown, which can be suppressed
@@ -1083,6 +1087,10 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
             <option>--user</option> mode, in which case the directories are below the user's home directory
             however.</para>
 
+            <para>If a unit gets masked but its triggering units are still active, a warning containing
+            the names of the triggering units is shown. <option>--no-warn</option> can be used to suppress
+            the warning.</para>
+
             <xi:include href="version-info.xml" xpointer="v238"/>
           </listitem>
         </varlistentry>
@@ -2240,7 +2248,8 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
               that are enabled in global scope,</para>
             </listitem>
             <listitem>
-              <para>when a <command>stop</command>-ped unit still has active triggering units.</para>
+              <para>when a <command>stop</command>-ped, <command>disable</command>-d, or <command>mask</command>-ed
+              unit still has active triggering units.</para>
             </listitem>
           </itemizedlist>
           </para>
index c2d9336d90478807eaf247fa4e874404732f50fa..4d554444d398ef06390b46af8ed8d61e85979c99 100644 (file)
@@ -138,7 +138,8 @@ int verb_enable(int argc, char *argv[], void *userdata) {
                 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
                 bool expect_carries_install_info = false;
                 bool send_runtime = true, send_force = true, send_preset_mode = false;
-                const char *method;
+                const char *method, *warn_trigger_operation = NULL;
+                bool warn_trigger_ignore_masked = true; /* suppress "used uninitialized" warning */
                 sd_bus *bus;
 
                 if (STR_IN_SET(verb, "mask", "unmask")) {
@@ -170,6 +171,9 @@ int verb_enable(int argc, char *argv[], void *userdata) {
                         method = "DisableUnitFilesWithFlagsAndInstallInfo";
                         expect_carries_install_info = true;
                         send_force = false;
+
+                        warn_trigger_operation = "Disabling";
+                        warn_trigger_ignore_masked = true;
                 } else if (streq(verb, "reenable")) {
                         method = "ReenableUnitFiles";
                         expect_carries_install_info = true;
@@ -185,9 +189,12 @@ int verb_enable(int argc, char *argv[], void *userdata) {
 
                         expect_carries_install_info = true;
                         ignore_carries_install_info = true;
-                } else if (streq(verb, "mask"))
+                } else if (streq(verb, "mask")) {
                         method = "MaskUnitFiles";
-                else if (streq(verb, "unmask")) {
+
+                        warn_trigger_operation = "Masking";
+                        warn_trigger_ignore_masked = false;
+                } else if (streq(verb, "unmask")) {
                         method = "UnmaskUnitFiles";
                         send_force = false;
                 } else if (streq(verb, "revert")) {
@@ -245,6 +252,10 @@ int verb_enable(int argc, char *argv[], void *userdata) {
                         if (r < 0)
                                 return r;
                 }
+
+                if (warn_trigger_operation && !arg_quiet && !arg_no_warn)
+                        STRV_FOREACH(unit, names)
+                                warn_triggering_units(bus, *unit, warn_trigger_operation, warn_trigger_ignore_masked);
         }
 
         if (carries_install_info == 0 && !ignore_carries_install_info)