]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pid1: order units using TTYVHangup= after vconsole setup
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 19 May 2023 13:50:04 +0000 (15:50 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 19 May 2023 15:46:30 +0000 (17:46 +0200)
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] https://github.com/legionus/kbd/issues/92#issuecomment-1554451788

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.

man/systemd.exec.xml
src/basic/special.h
src/core/execute.c
src/core/execute.h
src/core/mount.c
src/core/service.c
src/core/socket.c
src/core/swap.c

index c1088a301335229ac931b830194f97be0f865cf7..3f3ed77f4602b231d71095ebb416f50e09e36a84 100644 (file)
 
       <listitem><para>Units whose standard output or error output is connected to <option>journal</option> or
       <option>kmsg</option> (or their combinations with console output, see below) automatically acquire
-      dependencies of type <varname>After=</varname> on
-      <filename>systemd-journald.socket</filename>.</para></listitem>
+      dependencies of type <varname>After=</varname> on <filename>systemd-journald.socket</filename>.
+      </para></listitem>
+
+      <listitem><para>Units using the terminal (standard input, output, or error are connected to a terminal
+      or <varname>TTYPath=</varname> is used) automatically acquire an <varname>After=</varname> dependency
+      on <filename>systemd-vconsole-setup.service</filename>.</para></listitem>
 
       <listitem><para>Units using <varname>LogNamespace=</varname> will automatically gain ordering and
       requirement dependencies on the two socket units associated with
index 0e4342eb40daa55074041b921cff564379a24e52..ed3852a4504fd23c5e80212222ca093baa427a34 100644 (file)
@@ -85,6 +85,7 @@
 #define SPECIAL_QUOTACHECK_SERVICE "systemd-quotacheck.service"
 #define SPECIAL_QUOTAON_SERVICE "quotaon.service"
 #define SPECIAL_REMOUNT_FS_SERVICE "systemd-remount-fs.service"
+#define SPECIAL_VCONSOLE_SETUP_SERVICE "systemd-vconsole-setup.service"
 #define SPECIAL_VOLATILE_ROOT_SERVICE "systemd-volatile-root.service"
 #define SPECIAL_UDEVD_SERVICE "systemd-udevd.service"
 #define SPECIAL_GROWFS_SERVICE "systemd-growfs@.service"
index 8ddd7362a3eef06abde0e2e4c42cd596918425a5..ca89e3b003504087a3fa88842f58f898211a371a 100644 (file)
@@ -6870,6 +6870,16 @@ bool exec_context_has_encrypted_credentials(ExecContext *c) {
         return false;
 }
 
+int exec_context_add_default_dependencies(Unit *u, const ExecContext *c) {
+        assert(u);
+        assert(u->default_dependencies);
+
+        if (c && exec_context_needs_term(c))
+                return unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_VCONSOLE_SETUP_SERVICE,
+                                                   /* add_reference= */ true, UNIT_DEPENDENCY_DEFAULT);
+        return 0;
+}
+
 void exec_status_start(ExecStatus *s, pid_t pid) {
         assert(s);
 
index d2f5507405818fcb430285a8adf29c45163ac6b3..c2c983d0c30396486061811d48af9d692257f9cf 100644 (file)
@@ -486,6 +486,7 @@ void exec_context_revert_tty(ExecContext *c);
 
 int exec_context_get_clean_directories(ExecContext *c, char **prefix, ExecCleanMask mask, char ***ret);
 int exec_context_get_clean_mask(ExecContext *c, ExecCleanMask *ret);
+int exec_context_add_default_dependencies(Unit *u, const ExecContext *c);
 
 void exec_status_start(ExecStatus *s, pid_t pid);
 void exec_status_exit(ExecStatus *s, const ExecContext *context, pid_t pid, int code, int status);
index 549d7dbf986f76ec3c2febbea2ca8b9aa71cffda..f25188681d78773eb3c969cdd29e2449b63394f9 100644 (file)
@@ -575,7 +575,7 @@ static int mount_add_default_dependencies(Mount *m) {
                         return r;
         }
 
-        return 0;
+        return exec_context_add_default_dependencies(UNIT(m), &m->exec_context);
 }
 
 static int mount_verify(Mount *m) {
index 5c16a39309e941009aaedd541367e7355fd0de89..7e3a8ee082019de8bdb8848cb9d32bdd78965c34 100644 (file)
@@ -740,7 +740,12 @@ static int service_add_default_dependencies(Service *s) {
                 return r;
 
         /* Third, add us in for normal shutdown. */
-        return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
+        r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
+        if (r < 0)
+                return r;
+
+        /* Fourth, add generic dependencies */
+        return exec_context_add_default_dependencies(UNIT(s), &s->exec_context);
 }
 
 static void service_fix_stdio(Service *s) {
index 0fd1ad144b086e6928b80a2473f98dce6d665b0a..a932ddf8214d0f89d962ee727fd642602bf5acaf 100644 (file)
@@ -276,7 +276,11 @@ static int socket_add_default_dependencies(Socket *s) {
                         return r;
         }
 
-        return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
+        r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
+        if (r < 0)
+                return r;
+
+        return exec_context_add_default_dependencies(UNIT(s), &s->exec_context);
 }
 
 _pure_ static bool socket_has_exec(Socket *s) {
index c6e2c8b1bd94536cd2d557bd78607acc491abf7b..26a950b058d6fc56357b459bf4fbbbd90a67da8a 100644 (file)
@@ -270,7 +270,11 @@ static int swap_add_default_dependencies(Swap *s) {
         if (r < 0)
                 return r;
 
-        return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
+        r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
+        if (r < 0)
+                return r;
+
+        return exec_context_add_default_dependencies(UNIT(s), &s->exec_context);
 }
 
 static int swap_verify(Swap *s) {