summaryrefslogtreecommitdiffstats
path: root/libexec/getty
diff options
context:
space:
mode:
authordavidn <davidn@FreeBSD.org>1997-02-09 16:12:08 +0000
committerdavidn <davidn@FreeBSD.org>1997-02-09 16:12:08 +0000
commitdd9792c5ffdf57acf5385194bafedd6d9dbc0b03 (patch)
treeacd24826a9e8c1392fea1bf626a1a642c870c545 /libexec/getty
parentfe1adf2badb64ea9f4e04e7115c03b676d06b621 (diff)
downloadFreeBSD-src-dd9792c5ffdf57acf5385194bafedd6d9dbc0b03.zip
FreeBSD-src-dd9792c5ffdf57acf5385194bafedd6d9dbc0b03.tar.gz
Tidy-up modem-chat handling: ensure tty modes are restored to
'sane' standard (not raw) settings before abort/exiting; move responsibility of setting raw mode for chat-handling out of chat.c to avoid doing redundant tc{s,g}etattr()s; move DE pause prior setting standard mode before issue/login prompt to avoid echoing modem connect strings. Fixed up comment styles in a couple of places.
Diffstat (limited to 'libexec/getty')
-rw-r--r--libexec/getty/chat.c67
-rw-r--r--libexec/getty/main.c27
2 files changed, 45 insertions, 49 deletions
diff --git a/libexec/getty/chat.c b/libexec/getty/chat.c
index 97148df..21fd69b 100644
--- a/libexec/getty/chat.c
+++ b/libexec/getty/chat.c
@@ -477,45 +477,34 @@ getty_chat(scrstr, timeout, debug)
syslog(LOG_DEBUG, "getty_chat script='%s'", scrstr);
if ((script = read_chat(&scrstr)) != NULL) {
- struct termios tsave_in, tsave_out;
-
- if (tcgetattr(STDIN_FILENO, &tsave_in) == -1 ||
- tcgetattr(STDOUT_FILENO, &tsave_out) == -1) {
- syslog(LOG_ERR, "tcgetattr() failed in chat: %m");
- r = 2;
- } else {
- int i = r = 0;
- int off = 0;
- sig_t old_alarm;
- struct termios tneed;
-
- /* We need to be in raw mode for all this
- */
- tneed = tsave_in;
- cfmakeraw(&tneed);
- tcsetattr(STDIN_FILENO, TCSANOW, &tneed);
- tcsetattr(STDOUT_FILENO, TCSANOW, &tneed);
-
- old_alarm = signal(SIGALRM, chat_alrm);
- chat_unalarm(); /* Force blocking mode at start */
-
- /*
- * This is the send/expect loop
- */
- while (r == 0 && script[i] != NULL)
- if ((r = chat_expect(script[i++])) == 0 && script[i] != NULL)
- r = chat_send(script[i++]);
-
- signal(SIGALRM, old_alarm);
- free(script);
- free(scrstr);
-
- /* Restore flags & previous termios settings
- */
- ioctl(STDIN_FILENO, FIONBIO, &off);
- tcsetattr(STDIN_FILENO, TCSANOW, &tsave_in);
- tcsetattr(STDOUT_FILENO, TCSANOW, &tsave_out);
- }
+ int i = r = 0;
+ int off = 0;
+ sig_t old_alarm;
+ struct termios tneed;
+
+ /*
+ * We need to be in raw mode for all this
+ * Rely on caller...
+ */
+
+ old_alarm = signal(SIGALRM, chat_alrm);
+ chat_unalarm(); /* Force blocking mode at start */
+
+ /*
+ * This is the send/expect loop
+ */
+ while (r == 0 && script[i] != NULL)
+ if ((r = chat_expect(script[i++])) == 0 && script[i] != NULL)
+ r = chat_send(script[i++]);
+
+ signal(SIGALRM, old_alarm);
+ free(script);
+ free(scrstr);
+
+ /*
+ * Ensure stdin is in blocking mode
+ */
+ ioctl(STDIN_FILENO, FIONBIO, &off);
}
if (chat_debug & CHATDEBUG_MISC)
diff --git a/libexec/getty/main.c b/libexec/getty/main.c
index ecd6934..ff895a2 100644
--- a/libexec/getty/main.c
+++ b/libexec/getty/main.c
@@ -183,7 +183,8 @@ main(argc, argv)
{
extern char **environ;
const char *tname;
- int repcnt = 0, failopenlogged = 0, first_time = 1;
+ int repcnt = 0, failopenlogged = 0;
+ int first_sleep = 1, first_time = 1;
struct rlimit limit;
int rval;
@@ -238,6 +239,7 @@ main(argc, argv)
setdefttymode(tname);
if (getty_chat(IC, CT, DC) > 0) {
syslog(LOG_ERR, "modem init problem on %s", ttyn);
+ (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
exit(1);
}
}
@@ -258,11 +260,13 @@ main(argc, argv)
syslog(LOG_ERR, "select %s: %m", ttyn);
} else if (i == 0) {
syslog(LOG_NOTICE, "recycle tty %s", ttyn);
+ (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
exit(0); /* recycle for init */
}
i = getty_chat(AC, CT, DC);
if (i > 0) {
syslog(LOG_ERR, "modem answer problem on %s", ttyn);
+ (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
exit(1);
}
} else { /* blocking open */
@@ -292,6 +296,17 @@ main(argc, argv)
for (;;) {
+ /*
+ * if a delay was specified then sleep for that
+ * number of seconds before writing the initial prompt
+ */
+ if (first_sleep && DE) {
+ sleep(DE);
+ /* remove any noise */
+ (void)tcflush(STDIN_FILENO, TCIOFLUSH);
+ }
+ first_sleep = 0;
+
setttymode(tname, 0);
if (AB) {
tname = autobaud();
@@ -305,14 +320,6 @@ main(argc, argv)
putpad(CL);
edithost(HE);
- /* if a delay was specified then sleep for that
- number of seconds before writing the initial prompt */
- if(DE) {
- sleep(DE);
- /* remove any noise */
- (void)tcflush(STDIN_FILENO, TCIOFLUSH);
- }
-
/* if this is the first time through this, and an
issue file has been given, then send it */
if (first_time && IF) {
@@ -326,8 +333,8 @@ main(argc, argv)
}
close(fd);
}
- first_time = 0;
}
+ first_time = 0;
if (IM && *IM)
putf(IM);
OpenPOWER on IntegriCloud