Module Name: src
Committed By: christos
Date: Sun May 24 20:31:25 UTC 2009
Modified Files:
src/usr.sbin/pppd/pppd: sys-bsd.c
Log Message:
- prevent recursive error calls fatal -> die -> cleanup -> sys_cleanup -> cf* ->
fatal/error etc.
- prefix all the errors with __func__.
This allows me to unplug my 3G modem and have pppd exit correctly.
To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/usr.sbin/pppd/pppd/sys-bsd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/pppd/pppd/sys-bsd.c
diff -u src/usr.sbin/pppd/pppd/sys-bsd.c:1.59 src/usr.sbin/pppd/pppd/sys-bsd.c:1.60
--- src/usr.sbin/pppd/pppd/sys-bsd.c:1.59 Thu Apr 2 17:02:06 2009
+++ src/usr.sbin/pppd/pppd/sys-bsd.c Sun May 24 16:31:25 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sys-bsd.c,v 1.59 2009/04/02 21:02:06 christos Exp $ */
+/* $NetBSD: sys-bsd.c,v 1.60 2009/05/24 20:31:25 christos Exp $ */
/*
* sys-bsd.c - System-dependent procedures for setting up
@@ -79,7 +79,7 @@
#if 0
#define RCSID "Id: sys-bsd.c,v 1.47 2000/04/13 12:04:23 paulus Exp "
#else
-__RCSID("$NetBSD: sys-bsd.c,v 1.59 2009/04/02 21:02:06 christos Exp $");
+__RCSID("$NetBSD: sys-bsd.c,v 1.60 2009/05/24 20:31:25 christos Exp $");
#endif
#endif
@@ -153,6 +153,7 @@
static int loop_slave = -1;
static int loop_master = -1;
+static int doing_cleanup = 0;
static char loop_name[20];
static unsigned char inbuf[512]; /* buffer for chars read from loopback */
@@ -190,7 +191,7 @@
int flags;
if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &flags) == -1)
- fatal("ioctl(PPPIOCGFLAGS): %m");
+ fatal("%s: ioctl(PPPIOCGFLAGS): %m", __func__);
SYSDEBUG((LOG_DEBUG, "get flags = %x\n", flags));
return flags;
@@ -204,7 +205,7 @@
SYSDEBUG((LOG_DEBUG, "set flags = %x\n", flags));
if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &flags) == -1)
- fatal("ioctl(PPPIOCSFLAGS, %x): %m", flags, errno);
+ fatal("%s: ioctl(PPPIOCSFLAGS, %x): %m", __func__, flags, errno);
}
/*
@@ -215,7 +216,7 @@
{
/* Get an internet socket for doing socket ioctl's on. */
if ((sock_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- fatal("Couldn't create IP socket: %m");
+ fatal("%s: Couldn't create IP socket: %m", __func__);
#ifdef INET6
if ((sock6_fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
@@ -238,6 +239,7 @@
{
struct ifreq ifr;
+ doing_cleanup = 1;
if (if_is_up) {
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr) >= 0
@@ -252,6 +254,7 @@
cifdefaultroute(0, 0, default_route_gateway);
if (proxy_arp_addr)
cifproxyarp(0, proxy_arp_addr);
+ doing_cleanup = 0;
}
/*
@@ -280,7 +283,8 @@
{
#ifndef CDTRCTS
if (crtscts == 2) {
- warn("DTR/CTS flow control is not supported on this system");
+ warn("%s: DTR/CTS flow control is not supported on this system",
+ __func__);
return 0;
}
#endif
@@ -302,20 +306,20 @@
(void)memset(&ifcr, 0, sizeof(ifcr));
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- fatal("socket: %m");
+ fatal("%s: socket: %m", __func__);
if (ioctl(s, SIOCIFGCLONERS, &ifcr) == -1)
- fatal("ioctl(get cloners): %m");
+ fatal("%s: ioctl(get cloners): %m", __func__);
buf = malloc(ifcr.ifcr_total * IFNAMSIZ);
if (buf == NULL)
- fatal("Unable to allocate cloner name buffer: %m");
+ fatal("%s: Unable to allocate cloner name buffer: %m", __func__);
ifcr.ifcr_count = ifcr.ifcr_total;
ifcr.ifcr_buffer = buf;
if (ioctl(s, SIOCIFGCLONERS, &ifcr) == -1)
- fatal("ioctl(get cloners): %m");
+ fatal("%s: ioctl(get cloners): %m", __func__);
(void)close(s);
/*
@@ -358,19 +362,19 @@
* Demand mode - prime the old ppp device to relinquish the unit.
*/
if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0)
- fatal("ioctl(transfer ppp unit): %m");
+ fatal("%s: ioctl(transfer ppp unit): %m", __func__);
}
/*
* Save the old line discipline of fd, and set it to PPP.
*/
if (ioctl(fd, TIOCGETD, &initdisc) < 0)
- fatal("ioctl(TIOCGETD): %m");
+ fatal("%s: ioctl(TIOCGETD): %m", __func__);
if (ioctl(fd, TIOCSETD, &pppdisc) < 0)
- fatal("ioctl(TIOCSETD): %m");
+ fatal("%s: ioctl(TIOCSETD): %m", __func__);
if (ioctl(fd, PPPIOCGUNIT, &x) < 0)
- fatal("ioctl(PPPIOCGUNIT): %m");
+ fatal("%s: ioctl(PPPIOCGUNIT): %m", __func__);
if (!demand) {
/*
* Find out which interface we were given.
@@ -381,10 +385,11 @@
* Check that we got the same unit again.
*/
if (x != ifunit)
- fatal("transfer_ppp failed: wanted unit %d, got %d", ifunit, x);
+ fatal("%s: transfer_ppp failed: wanted unit %d, got %d",
+ __func__, ifunit, x);
x = TTYDISC;
if (ioctl(loop_slave, TIOCSETD, &x) == -1)
- fatal("ioctl(TIOCGETD): %m");
+ fatal("%s: ioctl(TIOCGETD): %m", __func__);
}
ppp_fd = fd;
@@ -403,7 +408,7 @@
*/
if ((initfdflags = fcntl(fd, F_GETFL)) == -1
|| fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
- warn("Couldn't set device to non-blocking mode: %m");
+ warn("%s: Couldn't set device to non-blocking mode: %m", __func__);
}
return fd;
@@ -421,18 +426,19 @@
* Transfer the ppp interface back to the loopback.
*/
if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0)
- fatal("ioctl(transfer ppp unit): %m");
+ fatal("%s: ioctl(transfer ppp unit): %m", __func__);
x = PPPDISC;
if (ioctl(loop_slave, TIOCSETD, &x) < 0)
- fatal("ioctl(TIOCSETD): %m");
+ fatal("%s: ioctl(TIOCSETD): %m", __func__);
/*
* Check that we got the same unit again.
*/
if (ioctl(loop_slave, PPPIOCGUNIT, &x) < 0)
- fatal("ioctl(PPPIOCGUNIT): %m");
+ fatal("%s: ioctl(PPPIOCGUNIT): %m", __func__);
if (x != ifunit)
- fatal("transfer_ppp failed: wanted unit %d, got %d", ifunit, x);
+ fatal("%s: transfer_ppp failed: wanted unit %d, got %d", __func__,
+ ifunit, x);
ppp_fd = loop_slave;
}
@@ -451,24 +457,26 @@
tty_disestablish_ppp(fd)
int fd;
{
- if (demand)
+ if (!doing_cleanup && demand)
restore_loop();
if (!hungup || demand) {
-
/* Flush the tty output buffer so that the TIOCSETD doesn't hang. */
if (tcflush(fd, TCIOFLUSH) < 0)
- warn("tcflush failed: %m");
+ if (!doing_cleanup)
+ warn("%s: tcflush failed: %m", __func__);
/* Restore old line discipline. */
if (initdisc >= 0 && ioctl(fd, TIOCSETD, &initdisc) < 0)
- error("ioctl(TIOCSETD): %m");
+ if (!doing_cleanup)
+ error("%s: ioctl(TIOCSETD): %m", __func__);
initdisc = -1;
/* Reset non-blocking mode on fd. */
if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
- warn("Couldn't restore device fd flags: %m");
+ if (!doing_cleanup)
+ warn("%s: Couldn't restore device fd flags: %m", __func__);
}
initfdflags = -1;
@@ -493,7 +501,7 @@
/* set the mrru, mtu and flags */
if (ioctl(ppp_dev_fd, PPPIOCSMRRU, &mrru) < 0)
- error("Couldn't set MRRU: %m");
+ error("%s: Couldn't set MRRU: %m", __func__);
flags = get_flags(ppp_dev_fd);
flags &= ~(SC_MP_SHORTSEQ | SC_MP_XSHORTSEQ);
flags |= (rssn? SC_MP_SHORTSEQ: 0) | (tssn? SC_MP_XSHORTSEQ: 0)
@@ -503,7 +511,7 @@
/* connect up the channel */
if (ioctl(ppp_fd, PPPIOCCONNECT, &ifunit) < 0)
- fatal("Couldn't attach to PPP unit %d: %m", ifunit);
+ fatal("%s: Couldn't attach to PPP unit %d: %m", __func__, ifunit);
add_fd(ppp_dev_fd);
#endif
}
@@ -547,10 +555,10 @@
if (ioctl(ppp_dev_fd, PPPIOCATTACH, &ifnum) < 0) {
if (errno == ENXIO)
return 0; /* doesn't still exist */
- fatal("Couldn't attach to interface unit %d: %m\n", ifnum);
+ fatal("%s: Couldn't attach to interface unit %d: %m", __func__, ifnum);
}
if (ioctl(ppp_fd, PPPIOCCONNECT, &ifnum) < 0)
- fatal("Couldn't connect to interface unit %d: %m", ifnum);
+ fatal("%s: Couldn't connect to interface unit %d: %m", __func__, ifnum);
set_flags(ppp_dev_fd, get_flags(ppp_dev_fd) | SC_MULTILINK);
ifunit = ifnum;
@@ -601,16 +609,17 @@
struct ppp_rawin win;
char buf[4 * sizeof(win.buf) + 1];
int i;
- warn("Serial link is not 8-bit clean:");
- warn("All received characters had %s", s);
+ warn("%s: Serial link is not 8-bit clean:", __func__);
+ warn("%s: All received characters had %s", __func__, s);
if (ioctl(ppp_fd, PPPIOCGRAWIN, &win) == -1) {
- warn("ioctl(PPPIOCGRAWIN): %s", strerror(errno));
+ warn("%s: ioctl(PPPIOCGRAWIN): %s", __func__, strerror(errno));
return;
}
for (i = 0; i < sizeof(win.buf); i++)
win.buf[i] = win.buf[i] & 0x7f;
strvisx(buf, (char *)win.buf, win.count, VIS_CSTYLE);
- warn("Last %d characters were: %s", (int)win.count, buf);
+ warn("%s: Last %d characters were: %s", __func__, (int)win.count,
+ buf);
}
}
}
@@ -628,7 +637,7 @@
struct termios tios;
if (tcgetattr(fd, &tios) < 0)
- fatal("tcgetattr: %m");
+ fatal("%s: tcgetattr: %m", __func__);
if (!restore_term) {
inittermios = tios;
@@ -675,12 +684,13 @@
* since that implies that the serial port is disabled.
*/
if (inspeed == 0)
- fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
+ fatal("%s: Baud rate for %s is 0; need explicit baud rate",
+ __func__, devnam);
}
baud_rate = inspeed;
if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
- fatal("tcsetattr: %m");
+ fatal("%s: tcsetattr: %m", __func__);
restore_term = 1;
}
@@ -703,7 +713,7 @@
}
if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
if (errno != ENXIO)
- warn("tcsetattr: %m");
+ warn("%s: tcsetattr: %m", __func__);
ioctl(fd, TIOCSWINSZ, &wsinfo);
restore_term = 0;
}
@@ -733,14 +743,14 @@
struct in6_aliasreq addreq6;
if (sock6_fd < 0) {
- fatal("No IPv6 socket available");
+ fatal("%s: No IPv6 socket available", __func__);
/*NOTREACHED*/
}
/* actually, this part is not kame local - RFC2553 conformant */
ifindex = if_nametoindex(ifname);
if (ifindex == 0) {
- error("sifaddr6: no interface %s", ifname);
+ error("%s: sifaddr6: no interface %s", __func__, ifname);
return 0;
}
@@ -778,7 +788,7 @@
addreq6.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
if (ioctl(sock6_fd, SIOCAIFADDR_IN6, &addreq6) < 0) {
- error("sif6addr: ioctl(SIOCAIFADDR_IN6): %m");
+ error("%s: sif6addr: ioctl(SIOCAIFADDR_IN6): %m", __func__);
return 0;
}
@@ -789,14 +799,14 @@
struct in6_rtmsg rt6;
if (sock6_fd < 0) {
- fatal("No IPv6 socket available");
+ fatal("%s: No IPv6 socket available", __func__);
/*NOTREACHED*/
}
memset(&ifr, 0, sizeof (ifr));
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(sock6_fd, SIOCGIFINDEX, (caddr_t) &ifr) < 0) {
- error("sif6addr: ioctl(SIOCGIFINDEX): %m");
+ error("%s: sif6addr: ioctl(SIOCGIFINDEX): %m", __func__);
return 0;
}
@@ -807,7 +817,7 @@
ifr6.ifr6_prefixlen = 10;
if (ioctl(sock6_fd, SIOCSIFADDR, &ifr6) < 0) {
- error("sif6addr: ioctl(SIOCSIFADDR): %m");
+ error("%s: sif6addr: ioctl(SIOCSIFADDR): %m", __func__);
return 0;
}
@@ -820,7 +830,7 @@
rt6.rtmsg_metric = 1;
if (ioctl(sock6_fd, SIOCADDRT, &rt6) < 0) {
- error("sif6addr: ioctl(SIOCADDRT): %m");
+ error("%s: sif6addr: ioctl(SIOCADDRT): %m", __func__);
return 0;
}
@@ -840,14 +850,14 @@
struct in6_ifreq delreq6;
if (sock6_fd < 0) {
- fatal("No IPv6 socket available");
+ fatal("%s: No IPv6 socket available", __func__);
/*NOTREACHED*/
}
/* actually, this part is not kame local - RFC2553 conformant */
ifindex = if_nametoindex(ifname);
if (ifindex == 0) {
- error("cifaddr6: no interface %s", ifname);
+ error("%s: cifaddr6: no interface %s", __func__, ifname);
return 0;
}
@@ -866,7 +876,7 @@
htons(ifindex);
if (ioctl(sock6_fd, SIOCDIFADDR_IN6, &delreq6) < 0) {
- error("cif6addr: ioctl(SIOCDIFADDR_IN6): %m");
+ error("%s: cif6addr: ioctl(SIOCDIFADDR_IN6): %m", __func__);
return 0;
}
@@ -876,14 +886,14 @@
struct in6_ifreq ifr6;
if (sock6_fd < 0) {
- fatal("No IPv6 socket available");
+ fatal("%s: No IPv6 socket available", __func__);
/*NOTREACHED*/
}
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(sock6_fd, SIOCGIFINDEX, (caddr_t) &ifr) < 0) {
- error("cif6addr: ioctl(SIOCGIFINDEX): %m");
+ error("%s: cif6addr: ioctl(SIOCGIFINDEX): %m", __func__);
return 0;
}
@@ -895,10 +905,10 @@
if (ioctl(sock6_fd, SIOCDIFADDR, &ifr6) < 0) {
if (errno != EADDRNOTAVAIL) {
if (! ok_error (errno))
- error("cif6addr: ioctl(SIOCDIFADDR): %m");
+ error("%s: cif6addr: ioctl(SIOCDIFADDR): %m", __func__);
}
else {
- warn("cif6addr: ioctl(SIOCDIFADDR): No such address");
+ warn("%s: cif6addr: ioctl(SIOCDIFADDR): No such address", __func__);
}
return (0);
}
@@ -928,9 +938,9 @@
tios.c_oflag = 0;
tios.c_lflag = 0;
if (tcsetattr(*slave_fdp, TCSAFLUSH, &tios) < 0)
- warn("couldn't set attributes on pty: %m");
+ warn("%s: couldn't set attributes on pty: %m", __func__);
} else
- warn("couldn't get attributes on pty: %m");
+ warn("%s: couldn't get attributes on pty: %m", __func__);
return 1;
}
@@ -949,7 +959,7 @@
int pppdisc = PPPDISC;
if (openpty(&loop_master, &loop_slave, loop_name, NULL, NULL) < 0)
- fatal("No free pty for loopback");
+ fatal("%s: No free pty for loopback", __func__);
SYSDEBUG(("using %s for loopback", loop_name));
if (tcgetattr(loop_slave, &tios) == 0) {
@@ -959,22 +969,22 @@
tios.c_oflag = 0;
tios.c_lflag = 0;
if (tcsetattr(loop_slave, TCSAFLUSH, &tios) < 0)
- warn("couldn't set attributes on loopback: %m");
+ warn("%s: couldn't set attributes on loopback: %m", __func__);
}
if ((flags = fcntl(loop_master, F_GETFL)) != -1)
if (fcntl(loop_master, F_SETFL, flags | O_NONBLOCK) == -1)
- warn("couldn't set loopback to nonblock: %m");
+ warn("%s: couldn't set loopback to nonblock: %m", __func__);
ppp_fd = loop_slave;
if (ioctl(ppp_fd, TIOCSETD, &pppdisc) < 0)
- fatal("ioctl(TIOCSETD): %m");
+ fatal("%s: ioctl(TIOCSETD): %m", __func__);
/*
* Find out which interface we were given.
*/
if (ioctl(ppp_fd, PPPIOCGUNIT, &ifunit) < 0)
- fatal("ioctl(PPPIOCGUNIT): %m");
+ fatal("%s: ioctl(PPPIOCGUNIT): %m", __func__);
/*
* Enable debug in the driver if requested.
@@ -1000,7 +1010,7 @@
if (write(ttyfd, p, len) < 0) {
if (errno != EIO)
- error("write: %m");
+ error("%s: write: %m", __func__);
}
}
@@ -1019,7 +1029,7 @@
ready = in_fds;
n = select(max_in_fd + 1, &ready, NULL, &ready, timo);
if (n < 0 && errno != EINTR)
- fatal("select: %m");
+ fatal("%s: select: %m", __func__);
}
@@ -1029,7 +1039,7 @@
void add_fd(int fd)
{
if (fd >= FD_SETSIZE)
- fatal("descriptor too big");
+ fatal("%s: descriptor too big", __func__);
FD_SET(fd, &in_fds);
if (fd > max_in_fd)
max_in_fd = fd;
@@ -1057,11 +1067,11 @@
FD_ZERO(&ready);
if (loop_master >= FD_SETSIZE)
- fatal("descriptor too big");
+ fatal("%s: descriptor too big", __func__);
FD_SET(loop_master, &ready);
n = select(loop_master + 1, &ready, NULL, &ready, timo);
if (n < 0 && errno != EINTR)
- fatal("select: %m");
+ fatal("%s: select: %m", __func__);
}
@@ -1076,7 +1086,7 @@
n = select(0, NULL, NULL, NULL, timo);
if (n < 0 && errno != EINTR)
- fatal("select: %m");
+ fatal("%s: select: %m", __func__);
}
#endif
@@ -1092,7 +1102,7 @@
if ((len = read(ttyfd, buf, PPP_MTU + PPP_HDRLEN)) < 0) {
if (errno == EWOULDBLOCK || errno == EINTR)
return -1;
- fatal("read: %m");
+ fatal("%s: read: %m", __func__);
}
return len;
}
@@ -1115,9 +1125,9 @@
}
if (n == 0)
- fatal("eof on loopback");
+ fatal("%s: eof on loopback", __func__);
if (n == -1 && errno != EWOULDBLOCK)
- fatal("read from loopback: %m");
+ fatal("%s: read from loopback: %m", __func__);
return rv;
}
@@ -1138,7 +1148,7 @@
ifr.ifr_mtu = mtu;
if (ifunit >= 0 && ioctl(sock_fd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
- fatal("ioctl(SIOCSIFMTU): %m");
+ fatal("%s: ioctl(SIOCSIFMTU): %m", __func__);
}
/*
@@ -1153,7 +1163,7 @@
strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
if (ifunit >= 0 && ioctl(sock_fd, SIOCGIFMTU, (caddr_t) &ifr) < 0) {
- error("ioctl(SIOCGIFMTU): %m (line %d)", __LINE__);
+ error("%s: ioctl(SIOCGIFMTU): %m", __func__);
return 0;
}
return ifr.ifr_mtu;
@@ -1173,7 +1183,7 @@
#endif
if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0)
- fatal("ioctl(PPPIOCSASYNCMAP): %m");
+ fatal("%s: ioctl(PPPIOCSASYNCMAP): %m", __func__);
x = get_flags(ppp_fd);
x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
@@ -1190,7 +1200,7 @@
tty_set_xaccm(ext_accm accm)
{
if (ioctl(ppp_fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
- warn("ioctl(set extended ACCM): %m");
+ warn("%s: ioctl(set extended ACCM): %m", __func__);
}
@@ -1204,9 +1214,9 @@
int x;
if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0)
- fatal("ioctl(PPPIOCSMRU): %m");
+ fatal("%s: ioctl(PPPIOCSMRU): %m", __func__);
if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0)
- fatal("ioctl(PPPIOCSRASYNCMAP): %m");
+ fatal("%s: ioctl(PPPIOCSRASYNCMAP): %m", __func__);
x = get_flags(ppp_fd);
x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
set_flags(ppp_fd, x);
@@ -1279,7 +1289,7 @@
memset (&req, 0, sizeof (req));
strlcpy(req.ifr_name, ifname, sizeof(req.ifr_name));
if (ioctl(sock_fd, SIOCGPPPSTATS, &req) < 0) {
- error("Couldn't get PPP statistics: %m");
+ error("%s: Couldn't get PPP statistics: %m", __func__);
return 0;
}
stats->bytes_in = req.stats.p.ppp_ibytes;
@@ -1302,28 +1312,28 @@
if (pass_in->bf_len > 0) {
if (ioctl(ppp_fd, PPPIOCSIPASS, pass_in) < 0) {
- error("Couldn't set pass-filter-in in kernel: %m");
+ error("%s: Couldn't set pass-filter-in in kernel: %m", __func__);
ret = 0;
}
}
if (pass_out->bf_len > 0) {
if (ioctl(ppp_fd, PPPIOCSOPASS, pass_out) < 0) {
- error("Couldn't set pass-filter-out in kernel: %m");
+ error("%s: Couldn't set pass-filter-out in kernel: %m", __func__);
ret = 0;
}
}
if (active_in->bf_len > 0) {
if (ioctl(ppp_fd, PPPIOCSIACTIVE, active_in) < 0) {
- error("Couldn't set active-filter-in in kernel: %m");
+ error("%s: Couldn't set active-filter-in in kernel: %m", __func__);
ret = 0;
}
}
if (active_out->bf_len > 0) {
if (ioctl(ppp_fd, PPPIOCSOACTIVE, active_out) < 0) {
- error("Couldn't set active-filter-out in kernel: %m");
+ error("%s: Couldn't set active-filter-out in kernel: %m", __func__);
ret = 0;
}
}
@@ -1345,7 +1355,7 @@
x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID;
set_flags(ppp_fd, x);
if (vjcomp && ioctl(ppp_fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) {
- error("ioctl(PPPIOCSMAXCID): %m");
+ error("%s: ioctl(PPPIOCSMAXCID): %m", __func__);
return 0;
}
return 1;
@@ -1361,12 +1371,12 @@
strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
if (ioctl(sock_fd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
- error("ioctl (SIOCGIFFLAGS): %m");
+ error("%s: ioctl (SIOCGIFFLAGS): %m", __func__);
return 0;
}
ifr.ifr_flags |= IFF_UP;
if (ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
- error("ioctl(SIOCSIFFLAGS): %m");
+ error("%s: ioctl(SIOCSIFFLAGS): %m", __func__);
return 0;
}
if_is_up = 1;
@@ -1384,7 +1394,7 @@
npi.protocol = proto;
npi.mode = mode;
if (ioctl(ppp_fd, PPPIOCSNPMODE, &npi) < 0) {
- error("ioctl(set NP %d mode to %d): %m", proto, mode);
+ error("%s: ioctl(set NP %d mode to %d): %m", __func__, proto, mode);
return 0;
}
return 1;
@@ -1408,12 +1418,12 @@
strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
if (ioctl(sock_fd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
- error("ioctl (SIOCGIFFLAGS): %m");
+ error("%s: ioctl (SIOCGIFFLAGS): %m", __func__);
rv = 0;
} else {
ifr.ifr_flags &= ~IFF_UP;
if (ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
- error("ioctl(SIOCSIFFLAGS): %m");
+ error("%s: ioctl(SIOCSIFFLAGS): %m", __func__);
rv = 0;
} else
if_is_up = 0;
@@ -1453,14 +1463,15 @@
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(sock_fd, SIOCDIFADDR, (caddr_t) &ifr) < 0) {
if (errno != EADDRNOTAVAIL)
- warn("Couldn't remove interface address: %m");
+ warn("%s: Couldn't remove interface address: %m", __func__);
}
if (ioctl(sock_fd, SIOCAIFADDR, (caddr_t) &ifra) < 0) {
if (errno != EEXIST) {
- error("Couldn't set interface address: %m");
+ error("%s: Couldn't set interface address: %m", __func__);
return 0;
}
- warn("Couldn't set interface address: Address %I already exists", o);
+ warn("%s: Couldn't set interface address: Address %I already exists",
+ __func__, o);
}
ifaddrs[0] = o;
ifaddrs[1] = h;
@@ -1484,8 +1495,8 @@
((struct sockaddr_in *) &ifra.ifra_broadaddr)->sin_addr.s_addr = h;
BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask));
if (ioctl(sock_fd, SIOCDIFADDR, (caddr_t) &ifra) < 0) {
- if (errno != EADDRNOTAVAIL)
- warn("Couldn't delete interface address: %m");
+ if (!doing_cleanup && errno != EADDRNOTAVAIL)
+ warn("%s: Couldn't delete interface address: %m", __func__);
return 0;
}
return 1;
@@ -1525,8 +1536,9 @@
} rtmsg;
if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
- error("Couldn't %s default route: socket: %m",
- cmd == 's' ? "add" : "delete");
+ if (!doing_cleanup)
+ error("%s: Couldn't %s default route: socket: %m", __func__,
+ cmd == 's' ? "add" : "delete");
return 0;
}
@@ -1558,8 +1570,9 @@
rtmsg.hdr.rtm_msglen = sizeof(rtmsg);
if (write(routes, &rtmsg, sizeof(rtmsg)) < 0) {
- error("Couldn't %s default route: %m",
- cmd == 's' ? "add" : "delete");
+ if (!doing_cleanup)
+ error("%s: Couldn't %s default route: %m", __func__,
+ cmd == 's' ? "add" : "delete");
close(routes);
return 0;
}
@@ -1594,12 +1607,12 @@
*/
memset(&arpmsg, 0, sizeof(arpmsg));
if (!get_ether_addr(hisaddr, &arpmsg.hwa)) {
- error("Cannot determine ethernet address for proxy ARP");
+ error("%s: Cannot determine ethernet address for proxy ARP", __func__);
return 0;
}
if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
- error("Couldn't add proxy arp entry: socket: %m");
+ error("%s: Couldn't add proxy arp entry: socket: %m", __func__);
return 0;
}
@@ -1617,7 +1630,7 @@
arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg
+ RT_ROUNDUP(arpmsg.hwa.sdl_len);
if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
- error("Couldn't add proxy arp entry: %m");
+ error("%s: Couldn't add proxy arp entry: %m", __func__);
close(routes);
return 0;
}
@@ -1644,12 +1657,14 @@
arpmsg.hdr.rtm_seq = ++rtm_seq;
if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
- error("Couldn't delete proxy arp entry: socket: %m");
+ if (!doing_cleanup)
+ error("%s: Couldn't delete proxy arp entry: socket: %m", __func__);
return 0;
}
if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
- error("Couldn't delete proxy arp entry: %m");
+ if (!doing_cleanup)
+ error("%s: Couldn't delete proxy arp entry: %m", __func__);
close(routes);
return 0;
}
@@ -1680,7 +1695,7 @@
* as our local address.
*/
if (!get_ether_addr(hisaddr, &dls.sdl)) {
- error("Cannot determine ethernet address for proxy ARP");
+ error("%s: Cannot determine ethernet address for proxy ARP", __func__);
return 0;
}
@@ -1691,7 +1706,7 @@
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
arpreq.arp_flags = ATF_PERM | ATF_PUBL;
if (ioctl(sock_fd, SIOCSARP, (caddr_t)&arpreq) < 0) {
- error("Couldn't add proxy arp entry: %m");
+ error("%s: Couldn't add proxy arp entry: %m", __func__);
return 0;
}
@@ -1711,7 +1726,7 @@
SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
if (ioctl(sock_fd, SIOCDARP, (caddr_t)&arpreq) < 0) {
- warn("Couldn't delete proxy arp entry: %m");
+ warn("%s: Couldn't delete proxy arp entry: %m", __func__);
return 0;
}
proxy_arp_addr = 0;
@@ -1736,7 +1751,7 @@
* address on the same subnet as `ipaddr'.
*/
if (getifaddrs(&ifap) != 0) {
- error("getifaddrs: %m");
+ error("%s: getifaddrs: %m", __func__);
return 0;
}
@@ -1838,7 +1853,7 @@
* Scan through the system's network interfaces.
*/
if (getifaddrs(&ifap) != 0) {
- warn("getifaddrs: %m");
+ warn("%s: getifaddrs: %m", __func__);
return NULL;
}
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
@@ -1889,7 +1904,7 @@
* Scan through the system's network interfaces.
*/
if (getifaddrs(&ifap) != 0) {
- warn("getifaddrs: %m");
+ warn("%s: getifaddrs: %m", __func__);
return 0;
}
@@ -1967,7 +1982,8 @@
/* Read the lock file to find out who has the device locked */
n = read(fd, hdb_lock_buffer, 11);
if (n <= 0) {
- error("Can't read pid from lock file %s", lock_file);
+ error("%s: Can't read pid from lock file %s", __func__,
+ lock_file);
close(fd);
} else {
hdb_lock_buffer[n] = 0;
@@ -1976,19 +1992,19 @@
/* pid no longer exists - remove the lock file */
if (unlink(lock_file) == 0) {
close(fd);
- notice("Removed stale lock on %s (pid %d)",
- dev, pid);
+ notice("%s: Removed stale lock on %s (pid %d)",
+ __func__, dev, pid);
continue;
} else
- warn("Couldn't remove stale lock on %s",
- dev);
+ warn("%s: Couldn't remove stale lock on %s", __func__,
+ dev);
} else
- notice("Device %s is locked by pid %d",
+ notice("%s: Device %s is locked by pid %d", __func__,
dev, pid);
}
close(fd);
} else
- error("Can't create lock file %s: %m", lock_file);
+ error("%s: Can't create lock file %s: %m", __func__, lock_file);
free(lock_file);
lock_file = NULL;
return -1;