From: Lennart Poettering Date: Wed, 31 Aug 2011 02:22:41 +0000 (+0200) Subject: getty: simplify things a bit X-Git-Tag: v35~4 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4dc380d16dfbead78de9caaf5104dbc00bac6d75;p=systemd getty: simplify things a bit https://bugs.freedesktop.org/show_bug.cgi?id=39818 --- diff --git a/src/getty-generator.c b/src/getty-generator.c index 4be3ce96..d4beffae 100644 --- a/src/getty-generator.c +++ b/src/getty-generator.c @@ -33,6 +33,9 @@ static int add_symlink(const char *fservice, const char *tservice) { char *from = NULL, *to = NULL; int r; + assert(fservice); + assert(tservice); + asprintf(&from, SYSTEM_DATA_UNIT_PATH "/%s", fservice); asprintf(&to, "%s/getty.target.wants/%s", arg_dest, tservice); @@ -63,6 +66,26 @@ finish: return r; } +static int add_serial_getty(const char *tty) { + char *n; + int r; + + assert(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; + } + + r = add_symlink("serial-getty@.service", n); + free(n); + + return r; +} + int main(int argc, char *argv[]) { static const char virtualization_consoles[] = @@ -112,27 +135,15 @@ int main(int argc, char *argv[]) { if (tty_is_vc(tty)) free(active); else { - char *n; int k; /* We assume that gettys on virtual terminals are * started via manual configuration and do this magic * only for non-VC terminals. */ - log_debug("Automatically adding serial getty for /dev/%s.", tty); - - n = unit_name_replace_instance("serial-getty@.service", tty); + k = add_serial_getty(tty); free(active); - if (!n) { - log_error("Out of memory"); - r = EXIT_FAILURE; - goto finish; - } - - k = add_symlink("serial-getty@.service", n); - free(n); - if (k < 0) { r = EXIT_FAILURE; goto finish; @@ -143,7 +154,7 @@ int main(int argc, char *argv[]) { /* Automatically add in a serial getty on the first * virtualizer console */ NULSTR_FOREACH(j, virtualization_consoles) { - char *n, *p; + char *p; int k; if (asprintf(&p, "/sys/class/tty/%s", j) < 0) { @@ -158,18 +169,7 @@ int main(int argc, char *argv[]) { if (k < 0) continue; - log_debug("Automatically adding serial getty for /dev/%s.", j); - - n = unit_name_replace_instance("serial-getty@.service", j); - if (!n) { - log_error("Out of memory"); - r = EXIT_FAILURE; - goto finish; - } - - k = add_symlink("serial-getty@.service", n); - free(n); - + k = add_serial_getty(j); if (k < 0) { r = EXIT_FAILURE; goto finish;