From: Eric Leblond Date: Sun, 17 Mar 2019 20:07:51 +0000 (+0100) Subject: util-ebpf: better error handling of map unlink X-Git-Tag: suricata-5.0.0-rc1~333 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ffd3ad2b7b1c97ecbe900f38eb4fea0c1f65cbe;p=thirdparty%2Fsuricata.git util-ebpf: better error handling of map unlink --- diff --git a/src/util-ebpf.c b/src/util-ebpf.c index 3562378ee2..b5c8ebf87c 100644 --- a/src/util-ebpf.c +++ b/src/util-ebpf.c @@ -88,13 +88,26 @@ static void BpfMapsInfoFree(void *bpf) for (i = 0; i < bpfinfo->last; i ++) { if (bpfinfo->array[i].name) { if (bpfinfo->array[i].to_unlink) { - char pinnedpath[1024]; - snprintf(pinnedpath, sizeof(pinnedpath), + char pinnedpath[PATH_MAX]; + int ret = snprintf(pinnedpath, sizeof(pinnedpath), "/sys/fs/bpf/suricata-%s-%s", bpfinfo->array[i].iface, bpfinfo->array[i].name); - /* Unlink the pinned entry */ - unlink(pinnedpath); + if (ret > 0) { + /* Unlink the pinned entry */ + ret = unlink(pinnedpath); + if (ret == -1) { + int error = errno; + SCLogWarning(SC_ERR_SYSCALL, + "Unable to remove %s: %s (%d)", + pinnedpath, + strerror(error), + error); + } + } else { + SCLogWarning(SC_ERR_SPRINTF, "Unable to remove map %s", + bpfinfo->array[i].name); + } } SCFree(bpfinfo->array[i].name); }