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.
This commit is contained in:
parent
ab25b7d505
commit
26015440b9
@ -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;
|
||||
int i = r = 0;
|
||||
int off = 0;
|
||||
sig_t old_alarm;
|
||||
struct termios tneed;
|
||||
|
||||
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
|
||||
* Rely on caller...
|
||||
*/
|
||||
|
||||
/* 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 */
|
||||
|
||||
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++]);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
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);
|
||||
}
|
||||
/*
|
||||
* Ensure stdin is in blocking mode
|
||||
*/
|
||||
ioctl(STDIN_FILENO, FIONBIO, &off);
|
||||
}
|
||||
|
||||
if (chat_debug & CHATDEBUG_MISC)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user