X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fgetty-generator%2Fgetty-generator.c;h=6c938062def7256c40d40147c7c8d4fbb216c807;hb=8b179a830a789746cce0be6671e2de235e3b0ea9;hp=b2e3eb63932235ce9bd0e4c6ed6ca81b49322e20;hpb=b7def684941808600c344f0be7a2b9fcdda97e0f;p=elogind.git diff --git a/src/getty-generator/getty-generator.c b/src/getty-generator/getty-generator.c index b2e3eb639..6c938062d 100644 --- a/src/getty-generator/getty-generator.c +++ b/src/getty-generator/getty-generator.c @@ -28,6 +28,7 @@ #include "mkdir.h" #include "unit-name.h" #include "virt.h" +#include "fileio.h" static const char *arg_dest = "/tmp"; @@ -42,8 +43,7 @@ static int add_symlink(const char *fservice, const char *tservice) { to = strjoin(arg_dest,"/getty.target.wants/", tservice, NULL); if (!from || !to) { - log_error("Out of memory"); - r = -ENOMEM; + r = log_oom(); goto finish; } @@ -55,7 +55,7 @@ static int add_symlink(const char *fservice, const char *tservice) { /* In case console=hvc0 is passed this will very likely result in EEXIST */ r = 0; else { - log_error("Failed to create symlink from %s to %s: %m", from, to); + log_error("Failed to create symlink %s: %m", to); r = -errno; } } @@ -77,10 +77,8 @@ static int add_serial_getty(const char *tty) { log_debug("Automatically adding serial getty for /dev/%s.", tty); n = unit_name_replace_instance("serial-getty@.service", tty); - if (!n) { - log_error("Out of memory"); - return -ENOMEM; - } + if (!n) + return log_oom(); r = add_symlink("serial-getty@.service", n); free(n); @@ -124,33 +122,42 @@ int main(int argc, char *argv[]) { } if (read_one_line_file("/sys/class/tty/console/active", &active) >= 0) { - const char *tty; - - tty = strrchr(active, ' '); - if (tty) - tty ++; - else - tty = active; - - /* Automatically add in a serial getty on the kernel - * console */ - if (tty_is_vc(tty)) - free(active); - else { + char *w, *state; + size_t l; + + /* Automatically add in a serial getty on all active + * kernel consoles */ + FOREACH_WORD(w, l, active, state) { + char *tty; int k; + tty = strndup(w, l); + if (!tty) { + log_oom(); + free(active); + r = EXIT_FAILURE; + goto finish; + } + + if (isempty(tty) || tty_is_vc(tty)) { + free(tty); + continue; + } + /* We assume that gettys on virtual terminals are * started via manual configuration and do this magic * only for non-VC terminals. */ k = add_serial_getty(tty); - free(active); if (k < 0) { + free(tty); + free(active); r = EXIT_FAILURE; goto finish; } } + free(active); } /* Automatically add in a serial getty on the first @@ -160,7 +167,7 @@ int main(int argc, char *argv[]) { int k; if (asprintf(&p, "/sys/class/tty/%s", j) < 0) { - log_error("Out of memory"); + log_oom(); r = EXIT_FAILURE; goto finish; }