mirror of
https://github.com/systemd/systemd.git
synced 2025-02-09 13:57:42 +03:00
getty-generator: Use device hotplug to instantiate virtualizer consoles
If getty-generator runs in the initrd, the corresponding tty might not have been instantiated yet in /dev, which means a serial getty is not spawned on it. Instead, let's instantiate the serial-getty when the device appears so that it always gets instantiated.
This commit is contained in:
parent
b3a062cb80
commit
e7e6ce5f8d
@ -23,15 +23,21 @@
|
||||
static const char *arg_dest = NULL;
|
||||
static bool arg_enabled = true;
|
||||
|
||||
static int add_symlink(const char *fservice, const char *tservice) {
|
||||
char *from, *to;
|
||||
static int add_symlink(const char *wants, const char *fservice, const char *tservice) {
|
||||
_cleanup_free_ char *from = NULL, *to = NULL;
|
||||
int r;
|
||||
|
||||
assert(wants);
|
||||
assert(fservice);
|
||||
assert(tservice);
|
||||
|
||||
from = strjoina(SYSTEM_DATA_UNIT_DIR "/", fservice);
|
||||
to = strjoina(arg_dest, "/getty.target.wants/", tservice);
|
||||
from = path_join(SYSTEM_DATA_UNIT_DIR, fservice);
|
||||
if (!from)
|
||||
return -ENOMEM;
|
||||
|
||||
to = path_join(arg_dest, wants, tservice);
|
||||
if (!to)
|
||||
return -ENOMEM;
|
||||
|
||||
(void) mkdir_parents_label(to, 0755);
|
||||
|
||||
@ -47,7 +53,7 @@ static int add_symlink(const char *fservice, const char *tservice) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int add_serial_getty(const char *tty) {
|
||||
static int add_serial_getty(const char *wants ,const char *tty) {
|
||||
_cleanup_free_ char *n = NULL;
|
||||
int r;
|
||||
|
||||
@ -59,7 +65,7 @@ static int add_serial_getty(const char *tty) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to generate service name: %m");
|
||||
|
||||
return add_symlink("serial-getty@.service", n);
|
||||
return add_symlink(wants, "serial-getty@.service", n);
|
||||
}
|
||||
|
||||
static int add_container_getty(const char *tty) {
|
||||
@ -74,7 +80,7 @@ static int add_container_getty(const char *tty) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to generate service name: %m");
|
||||
|
||||
return add_symlink("container-getty@.service", n);
|
||||
return add_symlink("getty.target.wants", "container-getty@.service", n);
|
||||
}
|
||||
|
||||
static int verify_tty(const char *name) {
|
||||
@ -107,7 +113,7 @@ static int run_container(void) {
|
||||
|
||||
log_debug("Automatically adding console shell.");
|
||||
|
||||
r = add_symlink("console-getty.service", "console-getty.service");
|
||||
r = add_symlink("getty.target.wants", "console-getty.service", "console-getty.service");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -209,7 +215,7 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
|
||||
if (verify_tty(tty) < 0)
|
||||
continue;
|
||||
|
||||
r = add_serial_getty(tty);
|
||||
r = add_serial_getty("getty.target.wants", tty);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -224,13 +230,11 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
|
||||
"3270!tty1") {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
|
||||
p = path_join("/sys/class/tty", j);
|
||||
p = strjoin("dev-", j, ".device.wants");
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
if (access(p, F_OK) < 0)
|
||||
continue;
|
||||
|
||||
r = add_serial_getty(j);
|
||||
r = add_serial_getty(p, j);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user