cmdline.o: cmdline.h common.h log.h util.h
contain.o: contain.h common.h log.h mount.h net.h util.h uts.h
log.o: log.h common.h
-net.o: net.h common.h log.h
mount.o: mount.h common.h log.h
-user.o: user.h common.h log.h util.h
-subproc.o: subproc.h common.h contain.h log.h net.h sandbox.h user.h util.h
+net.o: net.h common.h log.h
sandbox.o: sandbox.h common.h log.h seccomp/bpf-helper.h
+subproc.o: subproc.h common.h contain.h log.h net.h sandbox.h user.h util.h
+user.o: user.h common.h log.h util.h
util.o: util.h common.h log.h
uts.o: uts.h common.h log.h
seccomp/bpf-helper.o: seccomp/bpf-helper.h
#define ARRAYSIZE(array) (sizeof(array) / sizeof(*array))
+/* Go-style defer implementation */
#define __STRMERGE(a, b) a##b
#define _STRMERGE(a, b) __STRMERGE(a, b)
(*dfunc) ();
}
-#define defer(a) void (^_STRMERGE(__df_, __COUNTER__))(void) __attribute__((cleanup(_clang_cleanup_func))) __attribute__((unused)) = ^{ a; }
+#define DEFER(a) void (^_STRMERGE(__defer_f_, __COUNTER__))(void) __attribute__((cleanup(_clang_cleanup_func))) __attribute__((unused)) = ^{ a; }
#else
#define __block
-#define defer(a) void _STRMERGE(_cleanup_func_, __LINE__)(void *_STRMERGE(_cleanup_unused_, __LINE__) __attribute__((unused))) { a; } ; int _STRMERGE(_cleanup_var_, __LINE__) __attribute__((cleanup(_STRMERGE(_cleanup_func_, __LINE__)))) __attribute__((unused))
+#define _DEFER(a, count) void _STRMERGE(__defer_f_, count)(void *_defer_arg __attribute__((unused))) { a; } ; \
+ int _STRMERGE(_defer_var_, count) __attribute__((cleanup(_STRMERGE(__defer_f_, count)))) __attribute__((unused))
+#define DEFER(a) _DEFER(a, __COUNTER__)
#endif
struct pids_t {
PLOG_D("opendir('/proc/self/fd')");
return false;
}
- defer(closedir(dir));
+ DEFER(closedir(dir));
for (;;) {
errno = 0;
struct dirent *entry = readdir(dir);
LOG_E("Could not allocate socket with nl_socket_alloc()");
return false;
}
- defer(nl_socket_free(sk));
+ DEFER(nl_socket_free(sk));
int err;
if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) {
LOG_E("rtnl_link_macvlan_alloc(): %s", nl_geterror(err));
return false;
}
- defer(rtnl_link_put(rmv));
+ DEFER(rtnl_link_put(rmv));
struct nl_cache *link_cache;
if ((err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache)) < 0) {
LOG_E("rtnl_link_alloc_cache(): %s", nl_geterror(err));
return false;
}
- defer(nl_cache_free(link_cache));
+ DEFER(nl_cache_free(link_cache));
int master_index = rtnl_link_name2i(link_cache, nsjconf->iface);
if (master_index == 0) {
PLOG_E("socket(AF_INET, SOCK_STREAM, IPPROTO_IP)");
return false;
}
- defer(close(sock));
+ DEFER(close(sock));
struct ifreq ifr;
memset(&ifr, '\0', sizeof(ifr));
PLOG_E("socket(AF_INET, SOCK_STREAM, IPPROTO_IP)");
return false;
}
- defer(close(sock));
+ DEFER(close(sock));
if (inet_pton(AF_INET, nsjconf->iface_vs_ip, &addr) != 1) {
PLOG_E("Cannot convert '%s' into an IPv4 address", nsjconf->iface_vs_ip);
if (listenfd == -1) {
return;
}
- defer(close(listenfd));
+ DEFER(close(listenfd));
for (;;) {
if (nsjailSigFatal > 0) {
subprocKillAll(nsjconf);
return;
}
int subproc_sock = sv[1];
- defer(close(subproc_sock));
+ DEFER(close(subproc_sock));
pid_t pid = syscall(__NR_clone, (uintptr_t) flags, NULL, NULL, NULL, (uintptr_t) 0);
if (pid == 0) {
PLOG_E("Couldn't open '%s' for R/O", filename);
return false;
}
- defer(close(fd));
+ DEFER(close(fd));
if (utilWriteToFd(fd, buf, len) == false) {
PLOG_E("Couldn't write '%zu' bytes to file '%s' (fd='%d')", len, filename, fd);