Skip to content

Commit e019ea7

Browse files
committed
pid1: order units using TTYVHangup= after vconsole setup
The goal of this change is to delay getty services until after systemd-vconsole-setup has finished. systemd-vconsole-setup starts loadkeys, and it seems that when loadkeys is interrupted by the TTY hangup call we do when starting tty services [1], so that loadkeys starts getting EIO from the ioctl("/dev/tty1", KDSKBENT) syscall it does. Fixes #26908. [1] legionus/kbd#92 (comment) Initially I wanted to add ordering dependencies to individual units, but TTYVHangup= can be added to other various external units too. The solution with an implicit dependency should cover those cases too.
1 parent ce0fe01 commit e019ea7

8 files changed

Lines changed: 35 additions & 6 deletions

File tree

man/systemd.exec.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@
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
74-
<filename>systemd-journald.socket</filename>.</para></listitem>
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>
7579

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

src/basic/special.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#define SPECIAL_QUOTACHECK_SERVICE "systemd-quotacheck.service"
8686
#define SPECIAL_QUOTAON_SERVICE "quotaon.service"
8787
#define SPECIAL_REMOUNT_FS_SERVICE "systemd-remount-fs.service"
88+
#define SPECIAL_VCONSOLE_SETUP_SERVICE "systemd-vconsole-setup.service"
8889
#define SPECIAL_VOLATILE_ROOT_SERVICE "systemd-volatile-root.service"
8990
#define SPECIAL_UDEVD_SERVICE "systemd-udevd.service"
9091
#define SPECIAL_GROWFS_SERVICE "systemd-growfs@.service"

src/core/execute.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6870,6 +6870,16 @@ bool exec_context_has_encrypted_credentials(ExecContext *c) {
68706870
return false;
68716871
}
68726872

6873+
int exec_context_add_default_dependencies(Unit *u, const ExecContext *c) {
6874+
assert(u);
6875+
assert(u->default_dependencies);
6876+
6877+
if (c && exec_context_needs_term(c))
6878+
return unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_VCONSOLE_SETUP_SERVICE,
6879+
/* add_reference= */ true, UNIT_DEPENDENCY_DEFAULT);
6880+
return 0;
6881+
}
6882+
68736883
void exec_status_start(ExecStatus *s, pid_t pid) {
68746884
assert(s);
68756885

src/core/execute.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ void exec_context_revert_tty(ExecContext *c);
486486

487487
int exec_context_get_clean_directories(ExecContext *c, char **prefix, ExecCleanMask mask, char ***ret);
488488
int exec_context_get_clean_mask(ExecContext *c, ExecCleanMask *ret);
489+
int exec_context_add_default_dependencies(Unit *u, const ExecContext *c);
489490

490491
void exec_status_start(ExecStatus *s, pid_t pid);
491492
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
@@ -575,7 +575,7 @@ static int mount_add_default_dependencies(Mount *m) {
575575
return r;
576576
}
577577

578-
return 0;
578+
return exec_context_add_default_dependencies(UNIT(m), &m->exec_context);
579579
}
580580

581581
static int mount_verify(Mount *m) {

src/core/service.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,12 @@ static int service_add_default_dependencies(Service *s) {
740740
return r;
741741

742742
/* Third, add us in for normal shutdown. */
743-
return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
743+
r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
744+
if (r < 0)
745+
return r;
746+
747+
/* Fourth, add generic dependencies */
748+
return exec_context_add_default_dependencies(UNIT(s), &s->exec_context);
744749
}
745750

746751
static void service_fix_stdio(Service *s) {

src/core/socket.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,11 @@ static int socket_add_default_dependencies(Socket *s) {
276276
return r;
277277
}
278278

279-
return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
279+
r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
280+
if (r < 0)
281+
return r;
282+
283+
return exec_context_add_default_dependencies(UNIT(s), &s->exec_context);
280284
}
281285

282286
_pure_ static bool socket_has_exec(Socket *s) {

src/core/swap.c

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

273-
return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
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);
274278
}
275279

276280
static int swap_verify(Swap *s) {

0 commit comments

Comments
 (0)