systemctl: kill SysV compat 'runlevel' command

This commit is contained in:
Yu Watanabe
2025-04-21 05:48:53 +09:00
parent 5572fb18c0
commit af925f7eb3
10 changed files with 1 additions and 271 deletions

View File

@@ -47,8 +47,6 @@ A: Note that there might be more than one target active at the same time. So the
$ systemctl list-units --type=target
```
If you are just interested in a single number, you can use the venerable _runlevel_ command, but again, its output might be misleading.
**Q: I want to change a service file, but rpm keeps overwriting it in /usr/lib/systemd/system all the time, how should I handle this?**
A: The recommended way is to copy the service file from /usr/lib/systemd/system to /etc/systemd/system and edit it there. The latter directory takes precedence over the former, and rpm will never overwrite it. If you want to use the distributed service file again you can simply delete (or rename) the service file in /etc/systemd/system again.

View File

@@ -79,7 +79,6 @@ manpages = [
['resolvectl', '1', ['resolvconf'], 'ENABLE_RESOLVE'],
['resolved.conf', '5', ['resolved.conf.d'], 'ENABLE_RESOLVE'],
['run0', '1', [], ''],
['runlevel', '8', [], 'HAVE_SYSV_COMPAT'],
['sd-bus-errors',
'3',
['SD_BUS_ERROR_ACCESS_DENIED',

View File

@@ -1,164 +0,0 @@
<?xml version='1.0'?> <!--*-nxml-*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
<refentry id="runlevel" conditional='HAVE_SYSV_COMPAT'
xmlns:xi="http://www.w3.org/2001/XInclude">
<refentryinfo>
<title>runlevel</title>
<productname>systemd</productname>
</refentryinfo>
<refmeta>
<refentrytitle>runlevel</refentrytitle>
<manvolnum>8</manvolnum>
</refmeta>
<refnamediv>
<refname>runlevel</refname>
<refpurpose>Print previous and current SysV runlevel</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>runlevel</command>
<arg choice="opt" rep="repeat">options</arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Overview</title>
<para>"Runlevels" are an obsolete way to start and stop groups of
services used in SysV init. systemd provides a compatibility layer
that maps runlevels to targets, and associated binaries like
<command>runlevel</command>. Nevertheless, only one runlevel can
be "active" at a given time, while systemd can activate multiple
targets concurrently, so the mapping to runlevels is confusing
and only approximate. Runlevels should not be used in new code,
and are mostly useful as a shorthand way to refer the matching
systemd targets in kernel boot parameters.</para>
<table>
<title>Mapping between runlevels and systemd targets</title>
<tgroup cols='2' align='left' colsep='1' rowsep='1'>
<colspec colname="runlevel" />
<colspec colname="target" />
<thead>
<row>
<entry>Runlevel</entry>
<entry>Target</entry>
</row>
</thead>
<tbody>
<row>
<entry>0</entry>
<entry><filename>poweroff.target</filename></entry>
</row>
<row>
<entry>1</entry>
<entry><filename>rescue.target</filename></entry>
</row>
<row>
<entry>2, 3, 4</entry>
<entry><filename>multi-user.target</filename></entry>
</row>
<row>
<entry>5</entry>
<entry><filename>graphical.target</filename></entry>
</row>
<row>
<entry>6</entry>
<entry><filename>reboot.target</filename></entry>
</row>
</tbody>
</tgroup>
</table>
</refsect1>
<refsect1>
<title>Description</title>
<para><command>runlevel</command> prints the previous and current
SysV runlevel if they are known.</para>
<para>The two runlevel characters are separated by a single space
character. If a runlevel cannot be determined, N is printed
instead. If neither can be determined, the word "unknown" is
printed.</para>
<para>Unless overridden in the environment, this will check the
utmp database for recent runlevel changes.</para>
</refsect1>
<refsect1>
<title>Options</title>
<para>The following option is understood:</para>
<variablelist>
<varlistentry>
<term><option>--help</option></term>
<xi:include href="standard-options.xml" xpointer="help-text" />
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Exit status</title>
<para>If one or both runlevels could be determined, 0 is returned,
a non-zero failure code otherwise.</para>
</refsect1>
<refsect1>
<title>Environment</title>
<variablelist class='environment-variables'>
<varlistentry>
<term><varname>$RUNLEVEL</varname></term>
<listitem><para>If <varname>$RUNLEVEL</varname> is set,
<command>runlevel</command> will print this value as current
runlevel and ignore utmp.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>$PREVLEVEL</varname></term>
<listitem><para>If <varname>$PREVLEVEL</varname> is set,
<command>runlevel</command> will print this value as previous
runlevel and ignore utmp.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Files</title>
<variablelist>
<varlistentry>
<term><filename>/run/utmp</filename></term>
<listitem><para>The utmp database <command>runlevel</command> reads the previous and current runlevel
from.</para>
<xi:include href="version-info.xml" xpointer="v237"/></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>See Also</title>
<para><simplelist type="inline">
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
<member><citerefentry><refentrytitle>systemd.target</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
<member><citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
</simplelist></para>
</refsect1>
</refentry>

View File

@@ -32,7 +32,6 @@ systemctl_sources = files(
)
systemctl_extract_sources = files(
'systemctl-compat-halt.c',
'systemctl-compat-runlevel.c',
'systemctl-compat-shutdown.c',
'systemctl-compat-telinit.c',
'systemctl-daemon-reload.c',
@@ -75,7 +74,7 @@ executables += [
]
foreach alias : (['halt', 'poweroff', 'reboot', 'shutdown'] +
(conf.get('HAVE_SYSV_COMPAT') == 1 ? ['runlevel', 'telinit'] : []))
(conf.get('HAVE_SYSV_COMPAT') == 1 ? ['telinit'] : []))
install_symlink(alias,
pointing_to : sbin_to_bin + 'systemctl',
install_dir : sbindir)

View File

@@ -1,81 +0,0 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <getopt.h>
#include "alloc-util.h"
#include "log.h"
#include "pretty-print.h"
#include "systemctl-compat-runlevel.h"
#include "utmp-wtmp.h"
static int runlevel_help(void) {
_cleanup_free_ char *link = NULL;
int r;
r = terminal_urlify_man("runlevel", "8", &link);
if (r < 0)
return log_oom();
printf("%s [OPTIONS...]\n"
"\n%sPrints the previous and current runlevel of the init system.%s\n"
"\nOptions:\n"
" --help Show this help\n"
"\nSee the %s for details.\n",
program_invocation_short_name,
ansi_highlight(),
ansi_normal(),
link);
return 0;
}
int runlevel_parse_argv(int argc, char *argv[]) {
enum {
ARG_HELP = 0x100,
};
static const struct option options[] = {
{ "help", no_argument, NULL, ARG_HELP },
{}
};
int c;
assert(argc >= 0);
assert(argv);
while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
return runlevel_help();
case '?':
return -EINVAL;
default:
assert_not_reached();
}
if (optind < argc)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Too many arguments.");
return 1;
}
int runlevel_main(void) {
int r, runlevel, previous;
r = utmp_get_runlevel(&runlevel, &previous);
if (r < 0) {
puts("unknown");
return r;
}
printf("%c %c\n",
previous <= 0 ? 'N' : previous,
runlevel <= 0 ? 'N' : runlevel);
return 0;
}

View File

@@ -1,6 +0,0 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
int runlevel_parse_argv(int argc, char *argv[]);
int runlevel_main(void);

View File

@@ -16,7 +16,6 @@
#include "systemctl-cancel-job.h"
#include "systemctl-clean-or-freeze.h"
#include "systemctl-compat-halt.h"
#include "systemctl-compat-runlevel.h"
#include "systemctl-compat-telinit.h"
#include "systemctl-daemon-reload.h"
#include "systemctl-edit.h"
@@ -236,10 +235,6 @@ static int run(int argc, char *argv[]) {
r = logind_show_shutdown();
break;
case ACTION_RUNLEVEL:
r = runlevel_main();
break;
case ACTION_EXIT:
case ACTION_SLEEP:
case ACTION_SUSPEND:

View File

@@ -24,7 +24,6 @@
#include "strv.h"
#include "systemctl.h"
#include "systemctl-compat-halt.h"
#include "systemctl-compat-runlevel.h"
#include "systemctl-compat-shutdown.h"
#include "systemctl-compat-telinit.h"
#include "systemctl-logind.h"
@@ -1142,10 +1141,6 @@ int systemctl_dispatch_parse_argv(int argc, char *argv[]) {
arg_action = _ACTION_INVALID; /* telinit_parse_argv() will figure out the actual action we'll execute */
return telinit_parse_argv(argc, argv);
} else if (invoked_as(argv, "runlevel")) {
arg_action = ACTION_RUNLEVEL;
return runlevel_parse_argv(argc, argv);
}
arg_action = ACTION_SYSTEMCTL;

View File

@@ -25,7 +25,6 @@ enum action {
ACTION_DEFAULT,
ACTION_RELOAD,
ACTION_REEXEC,
ACTION_RUNLEVEL,
ACTION_CANCEL_SHUTDOWN,
ACTION_SHOW_SHUTDOWN,
ACTION_SYSTEMCTL_SHOW_SHUTDOWN,

View File

@@ -63,10 +63,6 @@ os-release.xml ./refsect1[title="Options"]/refsect2[title="Presentation informat
pam_systemd.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="debug="]
pam_systemd.xml ./refsect1[title="Environment"]/variablelist[1]/varlistentry[term="$XDG_SESSION_ID"]
pam_systemd.xml ./refsect1[title="Environment"]/variablelist[1]/varlistentry[term="$XDG_RUNTIME_DIR"]
runlevel.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="--help"]
runlevel.xml ./refsect1[title="Environment"]/variablelist/varlistentry[term="$RUNLEVEL"]
runlevel.xml ./refsect1[title="Environment"]/variablelist/varlistentry[term="$PREVLEVEL"]
runlevel.xml ./refsect1[title="Files"]/variablelist/varlistentry[term="/run/utmp"]
shutdown.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="--help"]
shutdown.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="-H"]
shutdown.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="-P"]