.st = &ctx->stat,
.obj = obj,
};
- int fd, ret;
+ int fd, ret = -1;
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
if (fd < 0) {
fprintf(stderr, "Cannot open socket: %s\n",
strerror(errno));
- return -1;
+ goto out;
}
strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
if (ret < 0) {
fprintf(stderr, "Cannot connect to %s: %s\n",
path, strerror(errno));
- return -1;
+ goto out;
}
ret = bpf_map_set_send(fd, &addr, sizeof(addr), &bpf_aux,
path, strerror(errno));
bpf_maps_teardown(ctx);
- close(fd);
+out:
+ if (fd >= 0)
+ close(fd);
return ret;
}
unsigned int entries)
{
struct sockaddr_un addr = { .sun_family = AF_UNIX };
- int fd, ret;
+ int fd, ret = -1;
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
if (fd < 0) {
fprintf(stderr, "Cannot open socket: %s\n",
strerror(errno));
- return -1;
+ goto out;
}
strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
if (ret < 0) {
fprintf(stderr, "Cannot bind to socket: %s\n",
strerror(errno));
- return -1;
+ goto out;
}
ret = bpf_map_set_recv(fd, fds, aux, entries);
path, strerror(errno));
unlink(addr.sun_path);
- close(fd);
+
+out:
+ if (fd >= 0)
+ close(fd);
return ret;
}