diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml
index c1088a30133..3f3ed77f460 100644
--- a/man/systemd.exec.xml
+++ b/man/systemd.exec.xml
@@ -70,8 +70,12 @@
Units whose standard output or error output is connected to or
(or their combinations with console output, see below) automatically acquire
- dependencies of type After= on
- systemd-journald.socket.
+ dependencies of type After= on systemd-journald.socket.
+
+
+ Units using the terminal (standard input, output, or error are connected to a terminal
+ or TTYPath= is used) automatically acquire an After= dependency
+ on systemd-vconsole-setup.service.
Units using LogNamespace= will automatically gain ordering and
requirement dependencies on the two socket units associated with
diff --git a/src/basic/special.h b/src/basic/special.h
index 0e4342eb40d..ed3852a4504 100644
--- a/src/basic/special.h
+++ b/src/basic/special.h
@@ -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"
diff --git a/src/core/execute.c b/src/core/execute.c
index 8ddd7362a3e..ca89e3b0035 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -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);
diff --git a/src/core/execute.h b/src/core/execute.h
index d2f55074058..c2c983d0c30 100644
--- a/src/core/execute.h
+++ b/src/core/execute.h
@@ -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);
diff --git a/src/core/mount.c b/src/core/mount.c
index 549d7dbf986..f25188681d7 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -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) {
diff --git a/src/core/service.c b/src/core/service.c
index 5c16a39309e..7e3a8ee0820 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -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) {
diff --git a/src/core/socket.c b/src/core/socket.c
index 0fd1ad144b0..a932ddf8214 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -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) {
diff --git a/src/core/swap.c b/src/core/swap.c
index c6e2c8b1bd9..26a950b058d 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -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) {