summaryrefslogtreecommitdiff
path: root/libexec/getty
diff options
context:
space:
mode:
authorDavid Nugent <davidn@FreeBSD.org>1997-02-09 16:12:08 +0000
committerDavid Nugent <davidn@FreeBSD.org>1997-02-09 16:12:08 +0000
commit26015440b9d9b76090465d9fc7d5fc728295745a (patch)
treeacd24826a9e8c1392fea1bf626a1a642c870c545 /libexec/getty
parentab25b7d5051b5f667af17335eeb535f2821d02ac (diff)
Notes
Diffstat (limited to 'libexec/getty')
-rw-r--r--libexec/getty/chat.c57
-rw-r--r--libexec/getty/main.c27
2 files changed, 40 insertions, 44 deletions
diff --git a/libexec/getty/chat.c b/libexec/getty/chat.c
index 97148dfb95ce..21fd69bd87fb 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;
+ 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)
diff --git a/libexec/getty/main.c b/libexec/getty/main.c
index ecd693444541..ff895a2b4e92 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);