Skip to content

Commit 9027aff

Browse files
authored
Merge pull request #27867 from keszybz/vconsole-reload-again
Restore ordering between vconsole-setup and firstboot services
2 parents 2c941b4 + 8623dab commit 9027aff

File tree

14 files changed

+69
-66
lines changed

14 files changed

+69
-66
lines changed

man/systemd-vconsole-setup.service.xml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@
3232
<refsect1>
3333
<title>Description</title>
3434

35-
<para><filename>systemd-vconsole-setup</filename> sets up and configures either all virtual consoles, or — if the
36-
optional <replaceable>TTY</replaceable> parameter is provided — a specific one. When the system is booting up, it's
37-
called by <citerefentry><refentrytitle>systemd-udevd</refentrytitle><manvolnum>8</manvolnum></citerefentry> during
38-
VT console subsystem initialization. Also,
39-
<citerefentry><refentrytitle>systemd-localed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> invokes
40-
it as needed when language or console changes are made. Internally, this program calls <citerefentry
41-
project='mankier'><refentrytitle>loadkeys</refentrytitle><manvolnum>1</manvolnum></citerefentry> and <citerefentry
42-
project='die-net'><refentrytitle>setfont</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
35+
<para><filename>systemd-vconsole-setup</filename> sets up and configures either all virtual consoles, or
36+
— if the optional <replaceable>TTY</replaceable> parameter is provided — a specific one. When the system
37+
is booting up, <filename>systemd-vconsole-setup.service</filename> is called by
38+
<citerefentry><refentrytitle>systemd-udevd</refentrytitle><manvolnum>8</manvolnum></citerefentry> during
39+
VT console subsystem initialization. Also,
40+
<citerefentry><refentrytitle>systemd-localed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
41+
invokes it as needed when language or console changes are made.
42+
Internally, this program calls
43+
<citerefentry project='mankier'><refentrytitle>loadkeys</refentrytitle><manvolnum>1</manvolnum></citerefentry>
44+
and
45+
<citerefentry project='die-net'><refentrytitle>setfont</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
4346
</para>
4447

4548
<para>Execute <command>systemctl restart systemd-vconsole-setup.service</command> in order to apply any manual

man/systemd.exec.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@
7070

7171
<listitem><para>Units whose standard output or error output is connected to <option>journal</option> or
7272
<option>kmsg</option> (or their combinations with console output, see below) automatically acquire
73-
dependencies of type <varname>After=</varname> on <filename>systemd-journald.socket</filename>.
74-
</para></listitem>
75-
76-
<listitem><para>Units using the terminal (standard input, output, or error are connected to a terminal
77-
or <varname>TTYPath=</varname> is used) automatically acquire an <varname>After=</varname> dependency
78-
on <filename>systemd-vconsole-setup.service</filename>.</para></listitem>
73+
dependencies of type <varname>After=</varname> on
74+
<filename>systemd-journald.socket</filename>.</para></listitem>
7975

8076
<listitem><para>Units using <varname>LogNamespace=</varname> will automatically gain ordering and
8177
requirement dependencies on the two socket units associated with

src/basic/fs-util.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,6 @@ int xopenat_lock(
11721172
int r;
11731173

11741174
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
1175-
assert(path);
11761175
assert(IN_SET(operation & ~LOCK_NB, LOCK_EX, LOCK_SH));
11771176

11781177
/* POSIX/UNPOSIX locks don't work on directories (errno is set to -EBADF so let's return early with

src/basic/special.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
#define SPECIAL_QUOTACHECK_SERVICE "systemd-quotacheck.service"
8787
#define SPECIAL_QUOTAON_SERVICE "quotaon.service"
8888
#define SPECIAL_REMOUNT_FS_SERVICE "systemd-remount-fs.service"
89-
#define SPECIAL_VCONSOLE_SETUP_SERVICE "systemd-vconsole-setup.service"
9089
#define SPECIAL_VOLATILE_ROOT_SERVICE "systemd-volatile-root.service"
9190
#define SPECIAL_UDEVD_SERVICE "systemd-udevd.service"
9291
#define SPECIAL_GROWFS_SERVICE "[email protected]"

src/core/execute.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -229,25 +229,34 @@ static int exec_context_tty_size(const ExecContext *context, unsigned *ret_rows,
229229
}
230230

231231
static void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p) {
232-
const char *path;
232+
_cleanup_close_ int fd = -EBADF;
233+
const char *path = exec_context_tty_path(ASSERT_PTR(context));
233234

234-
assert(context);
235+
/* Take a lock around the device for the duration of the setup that we do here.
236+
* systemd-vconsole-setup.service also takes the lock to avoid being interrupted.
237+
* We open a new fd that will be closed automatically, and operate on it for convenience.
238+
*/
235239

236-
path = exec_context_tty_path(context);
240+
if (p && p->stdin_fd >= 0) {
241+
fd = xopenat_lock(p->stdin_fd, NULL,
242+
O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY, 0, 0, LOCK_BSD, LOCK_EX);
243+
if (fd < 0)
244+
return;
245+
} else if (path) {
246+
fd = open_terminal(path, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
247+
if (fd < 0)
248+
return;
237249

238-
if (context->tty_vhangup) {
239-
if (p && p->stdin_fd >= 0)
240-
(void) terminal_vhangup_fd(p->stdin_fd);
241-
else if (path)
242-
(void) terminal_vhangup(path);
243-
}
250+
if (lock_generic(fd, LOCK_BSD, LOCK_EX) < 0)
251+
return;
252+
} else
253+
return; /* nothing to do */
244254

245-
if (context->tty_reset) {
246-
if (p && p->stdin_fd >= 0)
247-
(void) reset_terminal_fd(p->stdin_fd, true);
248-
else if (path)
249-
(void) reset_terminal(path);
250-
}
255+
if (context->tty_vhangup)
256+
(void) terminal_vhangup_fd(fd);
257+
258+
if (context->tty_reset)
259+
(void) reset_terminal_fd(fd, true);
251260

252261
if (p && p->stdin_fd >= 0) {
253262
unsigned rows = context->tty_rows, cols = context->tty_cols;
@@ -7180,16 +7189,6 @@ bool exec_context_has_encrypted_credentials(ExecContext *c) {
71807189
return false;
71817190
}
71827191

7183-
int exec_context_add_default_dependencies(Unit *u, const ExecContext *c) {
7184-
assert(u);
7185-
assert(u->default_dependencies);
7186-
7187-
if (c && exec_context_needs_term(c))
7188-
return unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_VCONSOLE_SETUP_SERVICE,
7189-
/* add_reference= */ true, UNIT_DEPENDENCY_DEFAULT);
7190-
return 0;
7191-
}
7192-
71937192
void exec_status_start(ExecStatus *s, pid_t pid) {
71947193
assert(s);
71957194

src/core/execute.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,6 @@ void exec_context_revert_tty(ExecContext *c);
501501

502502
int exec_context_get_clean_directories(ExecContext *c, char **prefix, ExecCleanMask mask, char ***ret);
503503
int exec_context_get_clean_mask(ExecContext *c, ExecCleanMask *ret);
504-
int exec_context_add_default_dependencies(Unit *u, const ExecContext *c);
505504

506505
void exec_status_start(ExecStatus *s, pid_t pid);
507506
void exec_status_exit(ExecStatus *s, const ExecContext *context, pid_t pid, int code, int status);

src/core/mount.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ static int mount_add_default_dependencies(Mount *m) {
601601
if (r < 0)
602602
return r;
603603

604-
return exec_context_add_default_dependencies(UNIT(m), &m->exec_context);
604+
return 0;
605605
}
606606

607607
static int mount_verify(Mount *m) {

src/core/service.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -747,12 +747,7 @@ static int service_add_default_dependencies(Service *s) {
747747
return r;
748748

749749
/* Third, add us in for normal shutdown. */
750-
r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
751-
if (r < 0)
752-
return r;
753-
754-
/* Fourth, add generic dependencies */
755-
return exec_context_add_default_dependencies(UNIT(s), &s->exec_context);
750+
return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
756751
}
757752

758753
static void service_fix_stdio(Service *s) {

src/core/socket.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,7 @@ static int socket_add_default_dependencies(Socket *s) {
283283
return r;
284284
}
285285

286-
r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
287-
if (r < 0)
288-
return r;
289-
290-
return exec_context_add_default_dependencies(UNIT(s), &s->exec_context);
286+
return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
291287
}
292288

293289
_pure_ static bool socket_has_exec(Socket *s) {

src/core/swap.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,7 @@ static int swap_add_default_dependencies(Swap *s) {
270270
if (r < 0)
271271
return r;
272272

273-
r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
274-
if (r < 0)
275-
return r;
276-
277-
return exec_context_add_default_dependencies(UNIT(s), &s->exec_context);
273+
return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
278274
}
279275

280276
static int swap_verify(Swap *s) {

0 commit comments

Comments
 (0)