- int x;
- int fdflags;
- char fname [30];
-/*
- * Take down the existing interface
- */
- sifdown (0);
- (void) ioctl(ppp_fd, TIOCSETD, &tty_disc);
-/*
- * Find the existing flags. This works even if the tty has stolen the
- * line discipline.
- */
- fdflags = fcntl(ppp_fd, F_GETFL);
- if (fdflags < 0)
- {
- syslog (LOG_ERR, "retrieve file flags failed: %m(%d)", errno);
- fdflags = O_NONBLOCK | O_RDWR;
- }
-/*
- * Re-open the file so the we can re-establish the previous discipline
- */
- sprintf (fname, "/proc/self/fd/%d", ppp_fd);
- x = open (fname, O_RDWR | O_NONBLOCK, 0);
- if (x < 0)
- {
- syslog (LOG_ERR, "reopen of tty file failed: %m(%d)", errno);
- }
-/*
- * Transfer the newly opened file (to the same tty) back to the tty
- * file handle.
- */
- else
- {
- dup2 (x, ppp_fd);
- close (x);
- fcntl (ppp_fd, F_SETFL, fdflags);
- set_up_tty(ppp_fd, 0);
- }
-/*
- * Switch to the tty slave and put that into the PPP discipline.
- */
- set_ppp_fd(slave_fd);
-
- if (ioctl(ppp_fd, TIOCSETD, &ppp_disc) < 0)