getty: code cleanup, part 2

* Clean up whitespace
* Reindent

Sponsored by:	Klara, Inc.
This commit is contained in:
Dag-Erling Smørgrav 2022-11-04 15:21:43 +01:00
parent 8ad7a14ab4
commit f285f41498
4 changed files with 80 additions and 80 deletions

View File

@ -248,7 +248,7 @@ cleanchr(char **buf, unsigned char ch)
l = 2;
ch &= 0x7f;
} else
l = 0;
l = 0;
if (ch < 32) {
tmp[l++] = '^';
@ -344,7 +344,7 @@ chat_expect(const char *str)
if (chat_debug & CHATDEBUG_RECEIVE)
syslog(LOG_DEBUG, "chat_recv '%s' m=%d",
cleanchr(NULL, ch), i);
cleanchr(NULL, ch), i);
if (ch == str[i])
got[i++] = ch;
@ -365,9 +365,9 @@ chat_expect(const char *str)
}
}
alarm(0);
chat_unalarm();
alarmed = 0;
free(got);
chat_unalarm();
alarmed = 0;
free(got);
}
}
@ -399,13 +399,13 @@ chat_send(char const *str)
unsigned char ch = (unsigned char)*str++;
if (alarmed)
r = 3;
r = 3;
else if (ch == PAUSE_CH)
usleep(500000); /* 1/2 second */
else {
usleep(10000); /* be kind to modem */
if (write(STDOUT_FILENO, &ch, 1) != 1)
r = alarmed ? 3 : 2;
r = alarmed ? 3 : 2;
}
}
alarm(0);
@ -414,7 +414,7 @@ chat_send(char const *str)
}
if (chat_debug & CHATDEBUG_SEND)
syslog(LOG_DEBUG, "chat_send %s", result(r));
syslog(LOG_DEBUG, "chat_send %s", result(r));
return r;
}
@ -481,7 +481,7 @@ getty_chat(char *scrstr, int timeout, int debug)
}
if (chat_debug & CHATDEBUG_MISC)
syslog(LOG_DEBUG, "getty_chat %s", result(r));
syslog(LOG_DEBUG, "getty_chat %s", result(r));
}
return r;

View File

@ -34,7 +34,7 @@
static char sccsid[] = "@(#)from: init.c 8.1 (Berkeley) 6/4/93";
#endif
static const char rcsid[] =
"$FreeBSD$";
"$FreeBSD$";
#endif /* not lint */
/*
@ -123,7 +123,7 @@ struct gettynums gettynums[] = {
{ "dc", 0, 0, 0 }, /* debug chat script value */
{ NULL, 0, 0, 0 }
};
struct gettyflags gettyflags[] = {
{ "ht", 0, 0, 0, 0 }, /* has tabs */

View File

@ -213,81 +213,81 @@ main(int argc, char *argv[])
* J. Gettys - MIT Project Athena.
*/
if (argc <= 2 || strcmp(argv[2], "-") == 0)
snprintf(ttyn, sizeof(ttyn), "%s", ttyname(STDIN_FILENO));
snprintf(ttyn, sizeof(ttyn), "%s", ttyname(STDIN_FILENO));
else {
snprintf(ttyn, sizeof(ttyn), "%s%s", _PATH_DEV, argv[2]);
if (strcmp(argv[0], "+") != 0) {
chown(ttyn, 0, 0);
chmod(ttyn, 0600);
revoke(ttyn);
snprintf(ttyn, sizeof(ttyn), "%s%s", _PATH_DEV, argv[2]);
if (strcmp(argv[0], "+") != 0) {
chown(ttyn, 0, 0);
chmod(ttyn, 0600);
revoke(ttyn);
/*
* Do the first scan through gettytab.
* Terminal mode parameters will be wrong until
* defttymode() called, but they're irrelevant for
* the initial setup of the terminal device.
*/
dogettytab();
/*
* Do the first scan through gettytab.
* Terminal mode parameters will be wrong until
* defttymode() called, but they're irrelevant for
* the initial setup of the terminal device.
*/
dogettytab();
/*
* Init or answer modem sequence has been specified.
*/
if (IC || AC) {
if (!opentty(ttyn, O_RDWR|O_NONBLOCK))
exit(1);
defttymode();
setttymode(1);
}
/*
* Init or answer modem sequence has been specified.
*/
if (IC || AC) {
if (!opentty(ttyn, O_RDWR|O_NONBLOCK))
exit(1);
defttymode();
setttymode(1);
}
if (IC) {
if (getty_chat(IC, CT, DC) > 0) {
syslog(LOG_ERR, "modem init problem on %s", ttyn);
(void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
exit(1);
if (IC) {
if (getty_chat(IC, CT, DC) > 0) {
syslog(LOG_ERR, "modem init problem on %s", ttyn);
(void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
exit(1);
}
}
if (AC) {
fd_set rfds;
struct timeval to;
int i;
FD_ZERO(&rfds);
FD_SET(0, &rfds);
to.tv_sec = RT;
to.tv_usec = 0;
i = select(32, &rfds, NULL, NULL, RT ? &to : NULL);
if (i < 0) {
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 { /* maybe blocking open */
if (!opentty(ttyn, O_RDWR | (NC ? O_NONBLOCK : 0 )))
exit(1);
}
}
if (AC) {
fd_set rfds;
struct timeval to;
int i;
FD_ZERO(&rfds);
FD_SET(0, &rfds);
to.tv_sec = RT;
to.tv_usec = 0;
i = select(32, &rfds, NULL, NULL, RT ? &to : NULL);
if (i < 0) {
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 { /* maybe blocking open */
if (!opentty(ttyn, O_RDWR | (NC ? O_NONBLOCK : 0 )))
exit(1);
}
}
}
defttymode();
for (;;) {
/*
* if a delay was specified then sleep for that
* 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);
sleep(DE);
/* remove any noise */
(void)tcflush(STDIN_FILENO, TCIOFLUSH);
}
first_sleep = 0;
@ -315,7 +315,7 @@ main(int argc, char *argv[])
char * cp;
while ((cp = get_line(fd)) != NULL) {
putf(cp);
putf(cp);
}
close(fd);
}
@ -436,7 +436,7 @@ opentty(const char *tty, int flags)
return 0;
sleep(60);
}
if (login_tty(i) < 0) {
if (login_tty(i) < 0) {
if (daemon(0,0) < 0) {
syslog(LOG_ERR,"daemon: %m");
close(i);
@ -552,7 +552,7 @@ getname(void)
See RFC1662.
Derived from code from Michael Hancock, <michaelh@cet.co.jp>
and Erik 'PPP' Olson, <eriko@wrq.com>
*/
*/
if (PP && (cs == PPP_FRAME)) {
ppp_state = 1;
@ -561,7 +561,7 @@ getname(void)
} else if (ppp_state == 2 && cs == PPP_ESCAPE) {
ppp_state = 3;
} else if ((ppp_state == 2 && cs == PPP_CONTROL)
|| (ppp_state == 3 && cs == PPP_CONTROL_ESCAPED)) {
|| (ppp_state == 3 && cs == PPP_CONTROL_ESCAPED)) {
ppp_state = 4;
} else if (ppp_state == 4 && cs == PPP_LCP_HI) {
ppp_state = 5;
@ -798,7 +798,7 @@ putf(const char *cp)
static void
dogettytab(void)
{
/* Read the database entry. */
gettable(tname);

View File

@ -34,7 +34,7 @@
static char sccsid[] = "@(#)from: subr.c 8.1 (Berkeley) 6/4/93";
#endif
static const char rcsid[] =
"$FreeBSD$";
"$FreeBSD$";
#endif /* not lint */
/*
@ -188,8 +188,8 @@ setdefaults(void)
for (sp = gettystrs; sp->field; sp++)
if (!sp->value)
sp->value = !sp->defalt ? sp->defalt
: strdup(sp->defalt);
sp->value = !sp->defalt ?
sp->defalt : strdup(sp->defalt);
for (np = gettynums; np->field; np++)
if (!np->set)
np->value = np->defalt;
@ -509,7 +509,7 @@ edithost(const char *pattern)
* In case of any errors, or if the pattern did not match, pass
* the original hostname as is.
*/
copyasis:
copyasis:
strlcpy(editedhost, HN, sizeof(editedhost));
}