- 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 {
- int k;
+ char *w, *state;
+ size_t l;
+
+ /* Automatically add in a serial getty on all active
+ * kernel consoles */
+ FOREACH_WORD(w, l, active, state) {
+ _cleanup_free_ char *tty = NULL;
+
+ tty = strndup(w, l);
+ if (!tty) {
+ log_oom();
+ return EXIT_FAILURE;
+ }
+
+ if (isempty(tty) || tty_is_vc(tty))
+ continue;