* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#define RCSID "$Id: main.c,v 1.123 2003/03/03 05:11:46 paulus Exp $"
+#define RCSID "$Id: main.c,v 1.137 2004/10/24 23:13:16 paulus Exp $"
#include <stdio.h>
#include <ctype.h>
#include "ipv6cp.h"
#endif
#include "upap.h"
-#include "chap.h"
+#include "chap-new.h"
#include "eap.h"
#include "ccp.h"
#include "ecp.h"
int got_sigterm;
int got_sighup;
+static sigset_t signals_handled;
static int waiting;
static sigjmp_buf sigjmp;
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.
waiting = 0;
- create_linkpidfile(getpid());
-
/*
* If we're doing dial-on-demand, set up the interface now.
*/
* Configure the interface and mark it up, etc.
*/
demand_conf();
+ create_linkpidfile(getpid());
}
do_callback = 0;
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);
*/
disconnect:
new_phase(PHASE_DISCONNECT);
- the_channel->disconnect();
+ if (the_channel->disconnect)
+ the_channel->disconnect();
fail:
if (the_channel->cleanup)
handle_events()
{
struct timeval timo;
- sigset_t mask;
kill_link = open_ccp_flag = 0;
if (sigsetjmp(sigjmp, 1) == 0) {
- sigprocmask(SIG_BLOCK, &mask, NULL);
+ sigprocmask(SIG_BLOCK, &signals_handled, NULL);
if (got_sighup || got_sigterm || got_sigusr2 || got_sigchld) {
- sigprocmask(SIG_UNBLOCK, &mask, NULL);
+ sigprocmask(SIG_UNBLOCK, &signals_handled, NULL);
} else {
waiting = 1;
- sigprocmask(SIG_UNBLOCK, &mask, NULL);
+ sigprocmask(SIG_UNBLOCK, &signals_handled, NULL);
wait_input(timeleft(&timo));
}
}
setup_signals()
{
struct sigaction sa;
- sigset_t mask;
/*
* Compute mask of all interesting signals and install signal handlers
* for each. Only one signal handler may be active at a time. Therefore,
* all other signals should be masked when any handler is executing.
*/
- sigemptyset(&mask);
- sigaddset(&mask, SIGHUP);
- sigaddset(&mask, SIGINT);
- sigaddset(&mask, SIGTERM);
- sigaddset(&mask, SIGCHLD);
- sigaddset(&mask, SIGUSR2);
+ sigemptyset(&signals_handled);
+ sigaddset(&signals_handled, SIGHUP);
+ sigaddset(&signals_handled, SIGINT);
+ sigaddset(&signals_handled, SIGTERM);
+ sigaddset(&signals_handled, SIGCHLD);
+ sigaddset(&signals_handled, SIGUSR2);
#define SIGNAL(s, handler) do { \
sa.sa_handler = handler; \
fatal("Couldn't establish signal handler (%d): %m", s); \
} while (0)
- sa.sa_mask = mask;
+ sa.sa_mask = signals_handled;
sa.sa_flags = 0;
SIGNAL(SIGHUP, hup); /* Hangup */
SIGNAL(SIGINT, term); /* Interrupt */
/* 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]);
}
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);
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);
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.
*/
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;
}
}
/*
* 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)
{
struct sigaction act, oldact;
+ sigemptyset(&act.sa_mask); /* unnecessary in fact */
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);
}
if (pid > 0) {
close(pipefd[1]);
/* this read() blocks until the close(pipefd[1]) below */
- read(pipefd[0], buf, 1);
+ complete_read(pipefd[0], buf, 1);
close(pipefd[0]);
return pid;
}
int pid;
int status = -1;
int errfd;
+ int fd;
++conn_running;
pid = safe_fork();
/* 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;
close(2);
if (the_channel->close)
(*the_channel->close)();
+ else
+ close(devfd); /* some plugins don't have a close function */
closelog();
close(fd_devnull);