|
11 | 11 | #include "generator.h" |
12 | 12 | #include "log.h" |
13 | 13 | #include "mkdir-label.h" |
| 14 | +#include "parse-util.h" |
14 | 15 | #include "path-util.h" |
15 | 16 | #include "process-util.h" |
| 17 | +#include "proc-cmdline.h" |
16 | 18 | #include "strv.h" |
17 | 19 | #include "terminal-util.h" |
18 | 20 | #include "unit-name.h" |
19 | 21 | #include "util.h" |
20 | 22 | #include "virt.h" |
21 | 23 |
|
22 | 24 | static const char *arg_dest = NULL; |
| 25 | +static bool arg_enabled = true; |
23 | 26 |
|
24 | 27 | static int add_symlink(const char *fservice, const char *tservice) { |
25 | 28 | char *from, *to; |
@@ -139,11 +142,48 @@ static int run_container(void) { |
139 | 142 | } |
140 | 143 | } |
141 | 144 |
|
| 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 | + |
142 | 161 | static int run(const char *dest, const char *dest_early, const char *dest_late) { |
| 162 | + _cleanup_free_ char *getty_auto = NULL; |
143 | 163 | int r; |
144 | 164 |
|
145 | 165 | assert_se(arg_dest = dest); |
146 | 166 |
|
| 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 | + |
147 | 187 | if (detect_container() > 0) |
148 | 188 | /* Add console shell and look at $container_ttys, but don't do add any |
149 | 189 | * further magic if we are in a container. */ |
|
0 commit comments