[systemd-devel] [PATCH 1/1] rfkill: Rework systemd-rfkill

João Paulo Rechi Vita jprvita at gmail.com
Fri Aug 21 08:56:57 PDT 2015


This commit adds a udev rule to save the RFKill state on every change,
so systemd-rfkill always have the most up-to-date state. This also
removes the need for saving the RFKill state on shutdown, so
systemd-rfkill at .service does not have to be active until shutdown, which
in turn removes the need for the RFKill device units.

Without this change systemd-rfkill does not support devices that lose
power over suspend and do a disconnect()/probe() cycle (when the driver
does not implement a reset_resume() callback): systemd-rfkill will
restore the RFKill state that was saved on the last shutdown instead of
the one right before suspending.

This also removes an item from our TODO.
---
 Makefile-man.am                  | 12 ------
 Makefile.am                      |  6 ---
 TODO                             |  2 +-
 man/kernel-command-line.xml      |  7 ++--
 man/systemd-rfkill at .service.xml  | 88 ----------------------------------------
 rules/99-systemd.rules.in        |  5 ++-
 units/.gitignore                 |  1 -
 units/systemd-rfkill at .service.in | 23 -----------
 8 files changed, 7 insertions(+), 137 deletions(-)
 delete mode 100644 man/systemd-rfkill at .service.xml
 delete mode 100644 units/systemd-rfkill at .service.in

diff --git a/Makefile-man.am b/Makefile-man.am
index c0cebaa..0516d24 100644
--- a/Makefile-man.am
+++ b/Makefile-man.am
@@ -1789,17 +1789,6 @@ man/systemd-resolved.html: man/systemd-resolved.service.html
 
 endif
 
-if ENABLE_RFKILL
-MANPAGES += \
-	man/systemd-rfkill at .service.8
-MANPAGES_ALIAS += \
-	man/systemd-rfkill.8
-man/systemd-rfkill.8: man/systemd-rfkill at .service.8
-man/systemd-rfkill.html: man/systemd-rfkill at .service.html
-	$(html-alias)
-
-endif
-
 if ENABLE_SYSUSERS
 MANPAGES += \
 	man/sysusers.d.5
@@ -2336,7 +2325,6 @@ EXTRA_DIST += \
 	man/systemd-random-seed.service.xml \
 	man/systemd-remount-fs.service.xml \
 	man/systemd-resolved.service.xml \
-	man/systemd-rfkill at .service.xml \
 	man/systemd-run.xml \
 	man/systemd-sleep.conf.xml \
 	man/systemd-socket-proxyd.xml \
diff --git a/Makefile.am b/Makefile.am
index 2927757..a5e30ef 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4432,9 +4432,6 @@ if ENABLE_RFKILL
 rootlibexec_PROGRAMS += \
 	systemd-rfkill
 
-nodist_systemunit_DATA += \
-	units/systemd-rfkill at .service
-
 systemd_rfkill_SOURCES = \
 	src/rfkill/rfkill.c
 
@@ -4442,9 +4439,6 @@ systemd_rfkill_LDADD = \
 	libshared.la
 endif
 
-EXTRA_DIST += \
-	units/systemd-rfkill at .service.in
-
 # ------------------------------------------------------------------------------
 if HAVE_LIBCRYPTSETUP
 rootlibexec_PROGRAMS += \
diff --git a/TODO b/TODO
index ce50f16..17ec28c 100644
--- a/TODO
+++ b/TODO
@@ -450,7 +450,7 @@ Features:
 
 * unify dispatch table in systemctl_main() and friends
 
-* rfkill,backlight: we probably should run the load tools inside of the udev rules so that the state is properly initialized by the time other software sees it
+* backlight: we probably should run the load tools inside of the udev rules so that the state is properly initialized by the time other software sees it
 
 * After coming back from hibernation reset hibernation swap partition using the /dev/snapshot ioctl APIs
 
diff --git a/man/kernel-command-line.xml b/man/kernel-command-line.xml
index eb73727..2a37275 100644
--- a/man/kernel-command-line.xml
+++ b/man/kernel-command-line.xml
@@ -114,10 +114,9 @@
         <listitem>
           <para>This parameter is understood by several system tools
           to control whether or not they should restore system state
-          from the previous boot. For details, see
-          <citerefentry><refentrytitle>systemd-backlight at .service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
-          and
-          <citerefentry><refentrytitle>systemd-rfkill at .service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
+          from the previous boot, like systemd-rfkill and
+          systemd-backlight. For more information, see
+          <citerefentry><refentrytitle>systemd-backlight at .service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
           </para>
         </listitem>
       </varlistentry>
diff --git a/man/systemd-rfkill at .service.xml b/man/systemd-rfkill at .service.xml
deleted file mode 100644
index 709b09d..0000000
--- a/man/systemd-rfkill at .service.xml
+++ /dev/null
@@ -1,88 +0,0 @@
-<?xml version="1.0"?>
-<!--*-nxml-*-->
-<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
-<!--
-  This file is part of systemd.
-
-  Copyright 2013 Lennart Poettering
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
--->
-<refentry id="systemd-rfkill at .service" conditional='ENABLE_RFKILL'>
-
-  <refentryinfo>
-    <title>systemd-rfkill at .service</title>
-    <productname>systemd</productname>
-
-    <authorgroup>
-      <author>
-        <contrib>Developer</contrib>
-        <firstname>Lennart</firstname>
-        <surname>Poettering</surname>
-        <email>lennart at poettering.net</email>
-      </author>
-    </authorgroup>
-  </refentryinfo>
-
-  <refmeta>
-    <refentrytitle>systemd-rfkill at .service</refentrytitle>
-    <manvolnum>8</manvolnum>
-  </refmeta>
-
-  <refnamediv>
-    <refname>systemd-rfkill at .service</refname>
-    <refname>systemd-rfkill</refname>
-    <refpurpose>Load and save the RF kill switch state at boot and shutdown</refpurpose>
-  </refnamediv>
-
-  <refsynopsisdiv>
-    <para><filename>systemd-rfkill at .service</filename></para>
-    <para><filename>/usr/lib/systemd/systemd-rfkill</filename></para>
-  </refsynopsisdiv>
-
-  <refsect1>
-    <title>Description</title>
-
-    <para><filename>systemd-rfkill at .service</filename> is a service
-    that restores the RF kill switch state at early boot and saves it
-    at shutdown. On disk, the RF kill switch state is stored in
-    <filename>/var/lib/systemd/rfkill/</filename>.</para>
-  </refsect1>
-
-  <refsect1>
-    <title>Kernel Command Line</title>
-
-    <para><filename>systemd-rfkill</filename> understands the
-    following kernel command line parameter:</para>
-
-    <variablelist class='kernel-commandline-options'>
-      <varlistentry>
-        <term><varname>systemd.restore_state=</varname></term>
-
-        <listitem><para>Takes a boolean argument. Defaults to
-        <literal>1</literal>. If <literal>0</literal>, does not
-        restore the rfkill settings on boot. However, settings will
-        still be stored on shutdown. </para></listitem>
-      </varlistentry>
-    </variablelist>
-  </refsect1>
-
-  <refsect1>
-    <title>See Also</title>
-    <para>
-      <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
-    </para>
-  </refsect1>
-
-</refentry>
diff --git a/rules/99-systemd.rules.in b/rules/99-systemd.rules.in
index 10b90b8..75c7113 100644
--- a/rules/99-systemd.rules.in
+++ b/rules/99-systemd.rules.in
@@ -55,9 +55,10 @@ ACTION=="add", SUBSYSTEM=="net", KERNEL!="lo", RUN+="@rootlibexecdir@/systemd-sy
 SUBSYSTEM=="backlight", TAG+="systemd", IMPORT{builtin}="path_id", ENV{SYSTEMD_WANTS}+="systemd-backlight at backlight:$name.service"
 SUBSYSTEM=="leds", KERNEL=="*kbd_backlight", TAG+="systemd", IMPORT{builtin}="path_id", ENV{SYSTEMD_WANTS}+="systemd-backlight at leds:$name.service"
 
-# Pull in rfkill save/restore for all rfkill devices
+# Save/restore state for all rfkill devices
 
-SUBSYSTEM=="rfkill", TAG+="systemd", IMPORT{builtin}="path_id", ENV{SYSTEMD_ALIAS}+="/sys/subsystem/rfkill/devices/%k", ENV{SYSTEMD_WANTS}+="systemd-rfkill@$name.service"
+SUBSYSTEM=="rfkill", ACTION=="add", IMPORT{builtin}="path_id", RUN+="@rootlibexecdir@/systemd-rfkill restore $name"
+SUBSYSTEM=="rfkill", ACTION=="change", IMPORT{builtin}="path_id", RUN+="@rootlibexecdir@/systemd-rfkill save $name"
 
 # Asynchronously mount file systems implemented by these modules as soon as they are loaded.
 SUBSYSTEM=="module", KERNEL=="fuse", TAG+="systemd", ENV{SYSTEMD_WANTS}+="sys-fs-fuse-connections.mount"
diff --git a/units/.gitignore b/units/.gitignore
index d45492d..561ecfe 100644
--- a/units/.gitignore
+++ b/units/.gitignore
@@ -58,7 +58,6 @@
 /systemd-resolved.service
 /systemd-resolved.service.m4
 /systemd-hibernate-resume at .service
-/systemd-rfkill at .service
 /systemd-suspend.service
 /systemd-sysctl.service
 /systemd-sysusers.service
diff --git a/units/systemd-rfkill at .service.in b/units/systemd-rfkill at .service.in
deleted file mode 100644
index e53bf5f..0000000
--- a/units/systemd-rfkill at .service.in
+++ /dev/null
@@ -1,23 +0,0 @@
-#  This file is part of systemd.
-#
-#  systemd is free software; you can redistribute it and/or modify it
-#  under the terms of the GNU Lesser General Public License as published by
-#  the Free Software Foundation; either version 2.1 of the License, or
-#  (at your option) any later version.
-
-[Unit]
-Description=Load/Save RF Kill Switch Status of %I
-Documentation=man:systemd-rfkill at .service(8)
-DefaultDependencies=no
-BindsTo=sys-subsystem-rfkill-devices-%i.device
-RequiresMountsFor=/var/lib/systemd/rfkill
-Conflicts=shutdown.target
-After=systemd-remount-fs.service
-Before=sysinit.target shutdown.target
-
-[Service]
-Type=oneshot
-RemainAfterExit=yes
-ExecStart=@rootlibexecdir@/systemd-rfkill load %I
-ExecStop=@rootlibexecdir@/systemd-rfkill save %I
-TimeoutSec=30s
-- 
2.1.4



More information about the systemd-devel mailing list