summaryrefslogtreecommitdiffstats
path: root/libexec/getty/chat.c
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/chat.c
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/chat.c')
-rw-r--r--libexec/getty/chat.c67
1 files changed, 28 insertions, 39 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)
OpenPOWER on IntegriCloud