Skip to content

Commit ee3fddc

Browse files
committed
getty-generator: add kernel cmdline and env vars to disable it
systemd.getty_auto/rd.systemd.getty_auto/SYSTEMD_GETTY_AUTO can be used to disable the generator. Enabled by default.
1 parent 3510cef commit ee3fddc

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

man/systemd-getty-generator.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,43 @@
5353
Elsewhere)</ulink>.</para>
5454
</refsect1>
5555

56+
<refsect1>
57+
<title>Kernel Command Line</title>
58+
59+
<para><filename>systemd-getty-generator</filename> understands the following
60+
<citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>
61+
parameters:</para>
62+
63+
<variablelist class='kernel-commandline-options'>
64+
<varlistentry>
65+
<term><varname>systemd.getty_auto=</varname></term>
66+
67+
<listitem><para>this options take an optional boolean argument, and default to yes.
68+
The generator is enabled by default, and a false value may be used to disable it.
69+
</para></listitem>
70+
</varlistentry>
71+
</variablelist>
72+
</refsect1>
73+
74+
<refsect1>
75+
<title>Environment</title>
76+
77+
<variablelist class='environment-variables'>
78+
<varlistentry>
79+
<term><varname>$SYSTEMD_GETTY_AUTO</varname></term>
80+
81+
<listitem><para>This variable takes an optional boolean argument, and default to yes.
82+
The generator is enabled by default, and a false value may be used to disable it.
83+
</para></listitem>
84+
</varlistentry>
85+
</variablelist>
86+
</refsect1>
87+
5688
<refsect1>
5789
<title>See Also</title>
5890
<para>
5991
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
92+
<citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
6093
<citerefentry project='man-pages'><refentrytitle>agetty</refentrytitle><manvolnum>8</manvolnum></citerefentry>
6194
</para>
6295
</refsect1>

src/getty-generator/getty-generator.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111
#include "generator.h"
1212
#include "log.h"
1313
#include "mkdir-label.h"
14+
#include "parse-util.h"
1415
#include "path-util.h"
1516
#include "process-util.h"
17+
#include "proc-cmdline.h"
1618
#include "strv.h"
1719
#include "terminal-util.h"
1820
#include "unit-name.h"
1921
#include "util.h"
2022
#include "virt.h"
2123

2224
static const char *arg_dest = NULL;
25+
static bool arg_enabled = true;
2326

2427
static int add_symlink(const char *fservice, const char *tservice) {
2528
char *from, *to;
@@ -139,11 +142,48 @@ static int run_container(void) {
139142
}
140143
}
141144

145+
static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
146+
int r;
147+
148+
assert(key);
149+
150+
if (proc_cmdline_key_streq(key, "systemd.getty_auto")) {
151+
r = value ? parse_boolean(value) : 1;
152+
if (r < 0)
153+
log_warning_errno(r, "Failed to parse getty_auto switch \"%s\", ignoring: %m", value);
154+
else
155+
arg_enabled = r;
156+
}
157+
158+
return 0;
159+
}
160+
142161
static int run(const char *dest, const char *dest_early, const char *dest_late) {
162+
_cleanup_free_ char *getty_auto = NULL;
143163
int r;
144164

145165
assert_se(arg_dest = dest);
146166

167+
r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
168+
if (r < 0)
169+
log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
170+
171+
r = getenv_for_pid(1, "SYSTEMD_GETTY_AUTO", &getty_auto);
172+
if (r < 0)
173+
log_warning_errno(r, "Failed to parse $SYSTEMD_GETTY_AUTO environment variable, ignoring: %m");
174+
else if (r > 0) {
175+
r = parse_boolean(getty_auto);
176+
if (r < 0)
177+
log_warning_errno(r, "Failed to parse $SYSTEMD_GETTY_AUTO value \"%s\", ignoring: %m", getty_auto);
178+
else
179+
arg_enabled = r;
180+
}
181+
182+
if (!arg_enabled) {
183+
log_debug("Disabled, exiting.");
184+
return 0;
185+
}
186+
147187
if (detect_container() > 0)
148188
/* Add console shell and look at $container_ttys, but don't do add any
149189
* further magic if we are in a container. */

0 commit comments

Comments
 (0)