aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-02-22 12:24:24 -0800
committerGuy Harris <guy@alum.mit.edu>2016-02-22 12:24:24 -0800
commit27593e4b8d1debe7046a383fa3e43fd35fa27119 (patch)
tree3aa5cf5456a88e3865af629124bf1f564c7492e0
parent32d01a544d12ae31a093719796c62630db3ad291 (diff)
Clean up pcap_do_addexit() and calls to it.
atexit() is only specified in standards as returning "a non-zero value" on error; don't assume it returns -1, even if it's documented as doing so on some platforms. pcap_do_addexit() already fills in p->errbuf; don't do so in its callers.
-rw-r--r--pcap-bpf.c4
-rw-r--r--pcap-linux.c2
-rw-r--r--pcap.c5
3 files changed, 2 insertions, 9 deletions
diff --git a/pcap-bpf.c b/pcap-bpf.c
index 92c859f5..f49adaf6 100644
--- a/pcap-bpf.c
+++ b/pcap-bpf.c
@@ -1752,8 +1752,6 @@ pcap_activate_bpf(pcap_t *p)
* "atexit()" failed; don't create the
* interface, just give up.
*/
- pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
- "atexit failed");
close(s);
status = PCAP_ERROR;
goto bad;
@@ -2625,8 +2623,6 @@ monitor_mode(pcap_t *p, int set)
* "atexit()" failed; don't put the interface
* in monitor mode, just give up.
*/
- pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
- "atexit failed");
close(sock);
return (PCAP_ERROR);
}
diff --git a/pcap-linux.c b/pcap-linux.c
index 3cfe5686..0792f0d5 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -925,8 +925,6 @@ added:
* "atexit()" failed; don't put the interface
* in rfmon mode, just give up.
*/
- pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
- "%s: atexit failed", device);
del_mon_if(handle, sock_fd, &nlstate, device,
handlep->mondevice);
nl80211_cleanup(&nlstate);
diff --git a/pcap.c b/pcap.c
index 29459de9..70c0f063 100644
--- a/pcap.c
+++ b/pcap.c
@@ -1922,12 +1922,11 @@ pcap_do_addexit(pcap_t *p)
* "pcap_close_all()" called when we exit.
*/
if (!did_atexit) {
- if (atexit(pcap_close_all) == -1) {
+ if (atexit(pcap_close_all) != 0) {
/*
* "atexit()" failed; let our caller know.
*/
- strncpy(p->errbuf, "atexit failed",
- PCAP_ERRBUF_SIZE);
+ strlcpy(p->errbuf, "atexit failed", PCAP_ERRBUF_SIZE);
return (0);
}
did_atexit = 1;