#include <netdb.h>
#include <utmp.h>
#include <pwd.h>
-#include <setjmp.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "atcp.h"
#endif
-static const char rcsid[] = RCSID;
/* interface vars */
-char ifname[32]; /* Interface name */
+char ifname[MAXIFNAMELEN]; /* Interface name */
int ifunit; /* Interface unit number */
struct channel *the_channel;
static sigset_t signals_handled;
static int waiting;
-static sigjmp_buf sigjmp;
+static int sigpipe[2];
char **script_env; /* Env. variable values for scripts */
int s_env_nalloc; /* # words avail at script_env */
NULL
};
-/*
- * If PPP_DRV_NAME is not defined, use the default "ppp" as the device name.
- */
-#if !defined(PPP_DRV_NAME)
-#define PPP_DRV_NAME "ppp"
-#endif /* !defined(PPP_DRV_NAME) */
-
int
main(argc, argv)
int argc;
info("Starting link");
}
- gettimeofday(&start_time, NULL);
+ get_time(&start_time);
script_unsetenv("CONNECT_TIME");
script_unsetenv("BYTES_SENT");
script_unsetenv("BYTES_RCVD");
handle_events()
{
struct timeval timo;
+ unsigned char buf[16];
kill_link = open_ccp_flag = 0;
- if (sigsetjmp(sigjmp, 1) == 0) {
- sigprocmask(SIG_BLOCK, &signals_handled, NULL);
- if (got_sighup || got_sigterm || got_sigusr2 || got_sigchld) {
- sigprocmask(SIG_UNBLOCK, &signals_handled, NULL);
- } else {
- waiting = 1;
- sigprocmask(SIG_UNBLOCK, &signals_handled, NULL);
- wait_input(timeleft(&timo));
- }
- }
+
+ /* alert via signal pipe */
+ waiting = 1;
+ /* flush signal pipe */
+ for (; read(sigpipe[0], buf, sizeof(buf)) > 0; );
+ add_fd(sigpipe[0]);
+ /* wait if necessary */
+ if (!(got_sighup || got_sigterm || got_sigusr2 || got_sigchld))
+ wait_input(timeleft(&timo));
waiting = 0;
+ remove_fd(sigpipe[0]);
+
calltimeout();
if (got_sighup) {
info("Hangup (SIGHUP)");
{
struct sigaction sa;
+ /* create pipe to wake up event handler from signal handler */
+ if (pipe(sigpipe) < 0)
+ fatal("Couldn't create signal pipe: %m");
+ fcntl(sigpipe[0], F_SETFD, fcntl(sigpipe[0], F_GETFD) | FD_CLOEXEC);
+ fcntl(sigpipe[1], F_SETFD, fcntl(sigpipe[1], F_GETFD) | FD_CLOEXEC);
+ fcntl(sigpipe[0], F_SETFL, fcntl(sigpipe[0], F_GETFL) | O_NONBLOCK);
+ fcntl(sigpipe[1], F_SETFL, fcntl(sigpipe[1], F_GETFL) | O_NONBLOCK);
+
/*
* Compute mask of all interesting signals and install signal handlers
* for each. Only one signal handler may be active at a time. Therefore,
set_ifunit(iskey)
int iskey;
{
- info("Using interface %s%d", PPP_DRV_NAME, ifunit);
- slprintf(ifname, sizeof(ifname), "%s%d", PPP_DRV_NAME, ifunit);
+ char ifkey[32];
+
+ if (req_ifname[0] != '\0')
+ slprintf(ifname, sizeof(ifname), "%s", req_ifname);
+ else
+ slprintf(ifname, sizeof(ifname), "%s%d", PPP_DRV_NAME, ifunit);
+ info("Using interface %s", ifname);
script_setenv("IFNAME", ifname, iskey);
+ slprintf(ifkey, sizeof(ifkey), "%d", ifunit);
+ script_setenv("UNIT", ifkey, iskey);
if (iskey) {
create_pidfile(getpid()); /* write pid to file */
create_linkpidfile(getpid());
{
if (!get_ppp_stats(u, &old_link_stats))
return;
- gettimeofday(&start_time, NULL);
+ get_time(&start_time);
}
/*
char numbuf[32];
if (!get_ppp_stats(u, &link_stats)
- || gettimeofday(&now, NULL) < 0)
+ || get_time(&now) < 0)
return;
link_connect_time = now.tv_sec - start_time.tv_sec;
link_stats_valid = 1;
fatal("Out of memory in timeout()!");
newp->c_arg = arg;
newp->c_func = func;
- gettimeofday(&timenow, NULL);
+ get_time(&timenow);
newp->c_time.tv_sec = timenow.tv_sec + secs;
newp->c_time.tv_usec = timenow.tv_usec + usecs;
if (newp->c_time.tv_usec >= 1000000) {
while (callout != NULL) {
p = callout;
- if (gettimeofday(&timenow, NULL) < 0)
+ if (get_time(&timenow) < 0)
fatal("Failed to get time of day: %m");
if (!(p->c_time.tv_sec < timenow.tv_sec
|| (p->c_time.tv_sec == timenow.tv_sec
if (callout == NULL)
return NULL;
- gettimeofday(&timenow, NULL);
+ get_time(&timenow);
tvp->tv_sec = callout->c_time.tv_sec - timenow.tv_sec;
tvp->tv_usec = callout->c_time.tv_usec - timenow.tv_usec;
if (tvp->tv_usec < 0) {
kill_my_pg(sig);
notify(sigreceived, sig);
if (waiting)
- siglongjmp(sigjmp, 1);
+ write(sigpipe[1], &sig, sizeof(sig));
}
kill_my_pg(sig);
notify(sigreceived, sig);
if (waiting)
- siglongjmp(sigjmp, 1);
+ write(sigpipe[1], &sig, sizeof(sig));
}
{
got_sigchld = 1;
if (waiting)
- siglongjmp(sigjmp, 1);
+ write(sigpipe[1], &sig, sizeof(sig));
}
{
got_sigusr2 = 1;
if (waiting)
- siglongjmp(sigjmp, 1);
+ write(sigpipe[1], &sig, sizeof(sig));
}
/* Executing in the child */
sys_close();
#ifdef USE_TDB
- tdb_close(pppdb);
+ if (pppdb != NULL)
+ tdb_close(pppdb);
#endif
/* make sure infd, outfd and errfd won't get tromped on below */
script_env[i] = newstring;
else
add_script_env(i, newstring);
- } else {
+ } else if (p != NULL) {
remove_script_env(i);
}
}