]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util-ebpf: better error handling of map unlink
authorEric Leblond <eric@regit.org>
Sun, 17 Mar 2019 20:07:51 +0000 (21:07 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 18 Jun 2019 05:07:02 +0000 (07:07 +0200)
src/util-ebpf.c

index 3562378ee275b6031fa703cfbd6cb729e00666e1..b5c8ebf87c4916691e21d0bbe44b7b696016af5f 100644 (file)
@@ -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);
         }