X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fmain.c;h=0be799820739344bd9aa45344b19c26a67d68b03;hp=7b57a2a570e6c771f2909f4c024ec3c5c93e9ba1;hb=66b97cb2741ff687e731834eb6458281df3dd412;hpb=516eb9abe39cf49031bb1192232e6a49e96852fb diff --git a/pppd/main.c b/pppd/main.c index 7b57a2a..0be7998 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -40,7 +40,7 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "$Id: main.c,v 1.124 2003/03/04 05:37:22 fcusack Exp $" +#define RCSID "$Id: main.c,v 1.134 2004/04/12 04:53:00 kad Exp $" #include #include @@ -74,7 +74,7 @@ #include "ipv6cp.h" #endif #include "upap.h" -#include "chap.h" +#include "chap-new.h" #include "eap.h" #include "ccp.h" #include "ecp.h" @@ -175,6 +175,8 @@ struct pppd_stats link_stats; unsigned link_connect_time; int link_stats_valid; +int error_count; + /* * We maintain a list of child process pids and * functions to call when they exit. @@ -436,8 +438,6 @@ main(argc, argv) waiting = 0; - create_linkpidfile(getpid()); - /* * If we're doing dial-on-demand, set up the interface now. */ @@ -457,6 +457,7 @@ main(argc, argv) * Configure the interface and mark it up, etc. */ demand_conf(); + create_linkpidfile(getpid()); } do_callback = 0; @@ -513,6 +514,9 @@ main(argc, argv) status = EXIT_FATAL_ERROR; goto disconnect; } + /* create the pid file, now that we've obtained a ppp interface */ + if (!demand) + create_linkpidfile(getpid()); if (!demand && ifunit >= 0) set_ifunit(1); @@ -585,7 +589,8 @@ main(argc, argv) */ disconnect: new_phase(PHASE_DISCONNECT); - the_channel->disconnect(); + if (the_channel->disconnect) + the_channel->disconnect(); fail: if (the_channel->cleanup) @@ -822,7 +827,7 @@ detach() /* wait for parent to finish updating pid & lock files and die */ close(pipefd[1]); - read(pipefd[0], numbuf, 1); + complete_read(pipefd[0], numbuf, 1); close(pipefd[0]); } @@ -852,7 +857,7 @@ create_pidfile(pid) slprintf(pidfilename, sizeof(pidfilename), "%s%s.pid", _PATH_VARRUN, ifname); if ((pidfile = fopen(pidfilename, "w")) != NULL) { - fprintf(pidfile, "%d\n", getpid()); + fprintf(pidfile, "%d\n", pid); (void) fclose(pidfile); } else { error("Failed to create pid file %s: %m", pidfilename); @@ -872,7 +877,7 @@ create_linkpidfile(pid) slprintf(linkpidfile, sizeof(linkpidfile), "%sppp-%s.pid", _PATH_VARRUN, linkname); if ((pidfile = fopen(linkpidfile, "w")) != NULL) { - fprintf(pidfile, "%d\n", getpid()); + fprintf(pidfile, "%d\n", pid); if (ifname[0]) fprintf(pidfile, "%s\n", ifname); (void) fclose(pidfile); @@ -1060,6 +1065,48 @@ get_input() lcp_sprotrej(0, p - PPP_HDRLEN, len + PPP_HDRLEN); } +/* + * ppp_send_config - configure the transmit-side characteristics of + * the ppp interface. Returns -1, indicating an error, if the channel + * send_config procedure called error() (or incremented error_count + * itself), otherwise 0. + */ +int +ppp_send_config(unit, mtu, accm, pcomp, accomp) + int unit, mtu; + u_int32_t accm; + int pcomp, accomp; +{ + int errs; + + if (the_channel->send_config == NULL) + return 0; + errs = error_count; + (*the_channel->send_config)(mtu, accm, pcomp, accomp); + return (error_count != errs)? -1: 0; +} + +/* + * ppp_recv_config - configure the receive-side characteristics of + * the ppp interface. Returns -1, indicating an error, if the channel + * recv_config procedure called error() (or incremented error_count + * itself), otherwise 0. + */ +int +ppp_recv_config(unit, mru, accm, pcomp, accomp) + int unit, mru; + u_int32_t accm; + int pcomp, accomp; +{ + int errs; + + if (the_channel->recv_config == NULL) + return 0; + errs = error_count; + (*the_channel->recv_config)(mru, accm, pcomp, accomp); + return (error_count != errs)? -1: 0; +} + /* * new_phase - signal the start of a new phase of pppd's operation. */ @@ -1126,6 +1173,7 @@ print_link_stats() info("Connect time %d.%d minutes.", t/10, t%10); info("Sent %u bytes, received %u bytes.", link_stats.bytes_out, link_stats.bytes_in); + link_stats_valid = 0; } } @@ -1282,6 +1330,7 @@ timeleft(tvp) /* * kill_my_pg - send a signal to our process group, and ignore it ourselves. + * We assume that sig is currently blocked. */ static void kill_my_pg(sig) @@ -1289,9 +1338,23 @@ kill_my_pg(sig) { struct sigaction act, oldact; + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask, sig); + act.sa_handler = SIG_IGN; act.sa_flags = 0; kill(0, sig); + /* + * The kill() above made the signal pending for us, as well as + * the rest of our process group, but we don't want it delivered + * to us. It is blocked at the moment. Setting it to be ignored + * will cause the pending signal to be discarded. If we did the + * kill() after setting the signal to be ignored, it is unspecified + * (by POSIX) whether the signal is immediately discarded or left + * pending, and in fact Linux would leave it pending, and so it + * would be delivered after the current signal handler exits, + * leading to an infinite loop. + */ sigaction(sig, &act, &oldact); sigaction(sig, &oldact, NULL); } @@ -1428,9 +1491,7 @@ safe_fork() if (pid > 0) { close(pipefd[1]); /* this read() blocks until the close(pipefd[1]) below */ - while (read(pipefd[0], buf, 1) < 0) - if (errno != EINTR) - break; + complete_read(pipefd[0], buf, 1); close(pipefd[0]); return pid; } @@ -1459,6 +1520,7 @@ device_script(program, in, out, dont_wait) int pid; int status = -1; int errfd; + int fd; ++conn_running; pid = safe_fork(); @@ -1486,6 +1548,14 @@ device_script(program, in, out, dont_wait) /* here we are executing in the child */ + /* make sure fds 0, 1, 2 are occupied */ + while ((fd = dup(in)) >= 0) { + if (fd > 2) { + close(fd); + break; + } + } + /* dup in and out to fds > 2 */ { int fd1 = in, fd2 = out, fd3 = log_to_fd;