From ff57306bc49791ac73ddf514670c77745f04f45a Mon Sep 17 00:00:00 2001 From: ache Date: Wed, 20 Sep 1995 12:56:25 +0000 Subject: From Bruce: slattach always exited early because fd is not open in acquire_line(). Other (trivial) changes that I've been neglecting for some time: - Turn off O_NONBLOCK so that `chat' doesn't need to worry about it (`chat' actually does worry about it). - Really set speeds POSIXly :-). cfsetspeed() isn't POSIX. - Fix spelling error in comment. - Gripe about bad programming of doing everything from signal handlers. slattach should be written to do everything from the sigsuspend() loop, but I don't want to do it :-). From me: Use .PATH to find uucplock.c Submitted by: bde --- sbin/slattach/Makefile | 4 +++- sbin/slattach/slattach.c | 26 +++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'sbin/slattach') diff --git a/sbin/slattach/Makefile b/sbin/slattach/Makefile index e1b2845..4d288ec 100644 --- a/sbin/slattach/Makefile +++ b/sbin/slattach/Makefile @@ -1,6 +1,6 @@ # @(#)Makefile 5.4 (Berkeley) 5/11/90 # -# $Header: /home/ncvs/src/sbin/slattach/Makefile,v 1.4 1994/08/23 08:28:30 rich Exp $ +# $Header: /home/ncvs/src/sbin/slattach/Makefile,v 1.5 1995/09/19 03:27:23 ache Exp $ PROG= slattach SRCS= slattach.c uucplock.c @@ -9,4 +9,6 @@ MLINKS= slattach.8 slip.8 LDADD= -lutil DPADD= ${LIBUTIL} +.PATH: ${.CURDIR}/../startslip + .include diff --git a/sbin/slattach/slattach.c b/sbin/slattach/slattach.c index cfd8275..1fa776e 100644 --- a/sbin/slattach/slattach.c +++ b/sbin/slattach/slattach.c @@ -255,9 +255,11 @@ int main(int argc, char **argv) void acquire_line() { int ttydisc = TTYDISC; + int oflags; FILE *pidfile; - if (ioctl(fd, TIOCSETD, &ttydisc) < 0) { /* reset to tty discipline */ + /* reset to tty discipline */ + if (fd >= 0 && ioctl(fd, TIOCSETD, &ttydisc) < 0) { syslog(LOG_ERR, "ioctl(TIOCSETD): %m"); exit_handler(1); } @@ -299,6 +301,15 @@ void acquire_line() syslog(LOG_ERR, "open(%s) %m", dev); exit_handler(1); } + /* Turn off O_NONBLOCK for dumb redialers, if any. */ + if ((oflags = fcntl(fd, F_GETFL)) == -1) { + syslog(LOG_ERR, "fcntl(F_GETFL) failed: %m"); + exit_handler(1); + } + if (fcntl(fd, F_SETFL, oflags & ~O_NONBLOCK) == -1) { + syslog(LOG_ERR, "fcntl(F_SETFL) failed: %m"); + exit_handler(1); + } (void)dup2(fd, STDIN_FILENO); (void)dup2(fd, STDOUT_FILENO); (void)dup2(fd, STDERR_FILENO); @@ -323,7 +334,8 @@ void setup_line(int cflag) { tty.c_lflag = tty.c_iflag = tty.c_oflag = 0; tty.c_cflag = CREAD | CS8 | flow_control | modem_control | cflag; - cfsetspeed(&tty, speed); + cfsetispeed(&tty, speed); + cfsetospeed(&tty, speed); /* set the line speed and flow control */ if (tcsetattr(fd, TCSAFLUSH, &tty) < 0) { syslog(LOG_ERR, "tcsetattr(TCSAFLUSH): %m"); @@ -434,7 +446,7 @@ void configure_network() } } -/* signup_handler() is invoked when carrier drops, eg. before redial. */ +/* sighup_handler() is invoked when carrier drops, eg. before redial. */ void sighup_handler() { int ttydisc = TTYDISC; @@ -477,6 +489,14 @@ again: } else setup_line(0); } else { +#if 0 + /* + * XXX should do this except we are called from main() via + * kill(getpid(), SIGHUP). Ick. + */ + syslog(LOG_NOTICE, "SIGHUP on %s (sl%d); exiting", dev, unit); + exit_handler(0); +#endif if (ioctl(fd, TIOCSETD, &ttydisc) < 0) { syslog(LOG_ERR, "ioctl(TIOCSETD): %m"); exit_handler(1); -- cgit v1.1