return true;
}
- struct nl_sock *sk;
- struct nl_cache *link_cache;
int err, master_index;
- bool ret = false;
- sk = nl_socket_alloc();
+ struct nl_sock *sk = nl_socket_alloc();
+ defer(nl_socket_free(sk));
+
if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) {
LOG_E("Unable to connect socket: %s", nl_geterror(err));
- goto out_sock;
+ return false;
}
- struct rtnl_link *rmv = rtnl_link_macvlan_alloc();
-
+ __block struct rtnl_link *rmv = rtnl_link_macvlan_alloc();
if (rmv == NULL) {
LOG_E("rtnl_link_macvlan_alloc(): %s", nl_geterror(err));
- goto out_sock;
+ return false;
}
+ rtnl_link_put(rmv);
+ _block 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));
- goto out_link;
+ return false;
}
+ defer(nl_cache_free(link_cache));
if (!(master_index = rtnl_link_name2i(link_cache, nsjconf->iface))) {
LOG_E("rtnl_link_name2i(): Did not find '%s' interface", nsjconf->iface);
- goto out_cache;
+ return false;
}
rtnl_link_set_name(rmv, IFACE_NAME);
if ((err = rtnl_link_add(sk, rmv, NLM_F_CREATE)) < 0) {
LOG_E("rtnl_link_add(): %s", nl_geterror(err));
- goto out_cache;
+ return false;
}
- ret = true;
- out_cache:
- nl_cache_free(link_cache);
- out_link:
- rtnl_link_put(rmv);
- out_sock:
- nl_socket_free(sk);
- return ret;
+ return true;
}
#else // defined(NSJAIL_NL3_WITH_MACVLAN)
static bool netSystemSbinIp(struct nsjconf_t *nsjconf, char *const *argv)
PLOG_E("socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC) failed");
return;
}
+ __block int subproc_sock = sv[1];
+ defer(close(subproc_sock));
pid_t pid = syscall(__NR_clone, (uintptr_t) flags, NULL, NULL, NULL, (uintptr_t) 0);
if (pid == 0) {
"doesn't support CLONE_NEWUSER. Alternatively, you might want to recompile your "
"kernel with support for namespaces or check the setting of the "
"kernel.unprivileged_userns_clone sysctl", flags);
- close(sv[1]);
return;
}
subprocAdd(nsjconf, pid, fd_in);
if (subprocInitParent(nsjconf, pid, sv[1]) == false) {
- close(sv[1]);
return;
}
log_buf[sz] = '\0';
logDirectlyToFD(log_buf);
}
- close(sv[1]);
}
PLOG_E("Couldn't open '%s' for R/O", filename);
return false;
}
+ defer(close(fd));
if (utilWriteToFd(fd, buf, len) == false) {
PLOG_E("Couldn't write '%zu' bytes to file '%s' (fd='%d')", len, filename, fd);
- close(fd);
unlink(filename);
return false;
}
- close(fd);
LOG_D("Written '%zu' bytes to '%s'", len, filename);