*/
#ifndef lint
-static char rcsid[] = "$Id: main.c,v 1.66 1999/03/24 05:05:24 paulus Exp $";
+static char rcsid[] = "$Id: main.c,v 1.70 1999/03/31 05:39:42 paulus Exp $";
#endif
#include <stdio.h>
u_char inpacket_buf[PPP_MRU+PPP_HDRLEN]; /* buffer for incoming packet */
static int n_children; /* # child processes still running */
+static int got_sigchld; /* set if we have received a SIGCHLD */
static int locked; /* lock() has succeeded */
script_env = NULL;
/* Initialize syslog facilities */
-#ifdef ULTRIX
- openlog("pppd", LOG_PID);
-#else
- openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP);
- setlogmask(LOG_UPTO(LOG_INFO));
-#endif
+ reopen_log();
if (gethostname(hostname, MAXNAMELEN) < 0 ) {
option_error("Couldn't get hostname: %m");
log_to_fd = 1; /* default to stdout */
script_setenv("DEVICE", devnam);
- slprintf(numbuf, sizeof(numbuf), "%d", baud_rate);
- script_setenv("SPEED", numbuf);
/*
* Initialize system-dependent stuff and magic number package.
}
if (get_loop_output())
break;
- reap_kids(0);
+ if (got_sigchld)
+ reap_kids(0);
}
remove_fd(fd_loop);
if (kill_link && !persist)
for (;;) {
/* If the user specified the device name, become the
user before opening it. */
- if (!devnam_info.priv)
+ if (!devnam_info.priv && !default_device)
seteuid(uid);
ttyfd = open(devnam, O_NONBLOCK | O_RDWR, 0);
- if (!devnam_info.priv)
+ if (!devnam_info.priv && !default_device)
seteuid(0);
if (ttyfd >= 0)
break;
close(i);
}
+ slprintf(numbuf, sizeof(numbuf), "%d", baud_rate);
+ script_setenv("SPEED", numbuf);
+
/* run welcome script, if any */
if (welcomer && welcomer[0]) {
if (device_script(welcomer, ttyfd, ttyfd, 0) < 0)
}
open_ccp_flag = 0;
}
- reap_kids(0); /* Don't leave dead kids lying around */
+ if (got_sigchld)
+ reap_kids(0); /* Don't leave dead kids lying around */
}
/*
kill_link = 0;
phase = PHASE_DORMANT; /* allow signal to end holdoff */
}
- reap_kids(0);
+ if (got_sigchld)
+ reap_kids(0);
} while (phase == PHASE_HOLDOFF);
if (!persist)
break;
create_pidfile();
}
+/*
+ * reopen_log - (re)open our connection to syslog.
+ */
+void
+reopen_log()
+{
+#ifdef ULTRIX
+ openlog("pppd", LOG_PID);
+#else
+ openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP);
+ setlogmask(LOG_UPTO(LOG_INFO));
+#endif
+}
+
/*
* Create a file containing our process ID.
*/
/*
* chld - Catch SIGCHLD signal.
- * Calls reap_kids to get status for any dead kids.
+ * Sets a flag so we will call reap_kids in the mainline.
*/
static void
chld(sig)
int sig;
{
+ got_sigchld = 1;
if (waiting)
siglongjmp(sigjmp, 1);
}
if (out == 0)
out = dup(out);
dup2(in, 0);
- if (in != out)
+ if (in > 2)
close(in);
}
if (out != 1) {
dup2(out, 1);
- close(out);
+ if (out > 2)
+ close(out);
}
if (real_ttyfd > 2)
close(real_ttyfd);
if (must_exist || errno != ENOENT) {
/* have to reopen the log, there's nowhere else
for the message to go. */
-#ifdef ULTRIX
- openlog("pppd", LOG_PID);
-#else
- openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP);
- setlogmask(LOG_UPTO(LOG_INFO));
-#endif
+ reopen_log();
syslog(LOG_ERR, "Can't execute %s: %m", prog);
closelog();
}
int pid, status;
struct subprocess *chp, **prevp;
+ got_sigchld = 0;
if (n_children == 0)
return;
while ((pid = waitpid(-1, &status, (waitfor? 0: WNOHANG))) != -1
nibuf = nobuf = 0;
ibufp = obufp = NULL;
pty_readable = stdin_readable = 1;
- gettimeofday(&lasttime, NULL);
nfds = (ofd > pty_master? ofd: pty_master) + 1;
+ if (recordf != NULL) {
+ gettimeofday(&lasttime, NULL);
+ putc(7, recordf); /* put start marker */
+ putc(lasttime.tv_sec >> 24, recordf);
+ putc(lasttime.tv_sec >> 16, recordf);
+ putc(lasttime.tv_sec >> 8, recordf);
+ putc(lasttime.tv_sec, recordf);
+ lasttime.tv_usec = 0;
+ }
while (nibuf != 0 || nobuf != 0 || pty_readable || stdin_readable) {
FD_ZERO(&ready);
int diff;
gettimeofday(&now, NULL);
- diff = (now.tv_sec - tp->tv_sec) * 10
- + (now.tv_usec - tp->tv_usec) / 100000;
+ now.tv_usec /= 100000; /* actually 1/10 s, not usec now */
+ diff = (now.tv_sec - tp->tv_sec) * 10 + (now.tv_usec - tp->tv_usec);
if (diff > 0) {
if (diff > 255) {
putc(5, f);