char *tty = NULL;
struct passwd *pwd;
int c, status = 0;
+ int reconnect = 0;
int opt_e = 0;
struct console *con;
pid_t pid;
}
/*
- * See if we have a timeout flag.
+ * See if we have a timeout flag.
*/
opterr = 0;
while((c = getopt(argc, argv, "ept:")) != EOF) switch(c) {
saved_sighup = signal(SIGHUP, SIG_IGN);
/*
- * See if we need to open an other tty device.
+ * See if we need to open an other tty device.
*/
if (optind < argc)
tty = argv[optind];
tty = getenv("CONSOLE");
/*
- * Detect possible consoles, use stdin as fallback.
+ * Detect possible consoles, use stdin as fallback.
+ * If an optional tty is given, reconnect it to stdin.
*/
- detect_consoles(tty, 0);
+ reconnect = detect_consoles(tty, 0);
/*
* Should not happen
exit(1);
}
+ /*
+ * If previous stdin was not the speified tty and therefore reconnected
+ * to the specified tty also reconnect stdout and stderr.
+ */
+ if (reconnect) {
+ if (isatty(1) == 0)
+ dup2(0, 1);
+ if (isatty(2) == 0)
+ dup2(0, 2);
+ }
+
/*
* Get the root password.
*/
break;
}
fprintf(stderr, "Login incorrect.\n\r");
+ sleep(3);
}
if (alarm_rised) {
tcfinal(con);