Commit 671c3c49 by Christian Brauner Committed by Stéphane Graber

lxc_user_nic: use lxc_preserve_ns()

parent 377d0119
...@@ -673,25 +673,21 @@ again: ...@@ -673,25 +673,21 @@ again:
static int rename_in_ns(int pid, char *oldname, char **newnamep) static int rename_in_ns(int pid, char *oldname, char **newnamep)
{ {
char nspath[MAXPATHLEN];
int fd = -1, ofd = -1, ret, ifindex = -1; int fd = -1, ofd = -1, ret, ifindex = -1;
bool grab_newname = false; bool grab_newname = false;
ret = snprintf(nspath, MAXPATHLEN, "/proc/%d/ns/net", getpid()); ofd = lxc_preserve_ns(getpid(), "net");
if (ret < 0 || ret >= MAXPATHLEN) if (ofd < 0) {
return -1; fprintf(stderr, "Failed opening network namespace path for '%d'.", getpid());
if ((ofd = open(nspath, O_RDONLY)) < 0) {
fprintf(stderr, "Opening %s\n", nspath);
return -1; return -1;
} }
ret = snprintf(nspath, MAXPATHLEN, "/proc/%d/ns/net", pid);
if (ret < 0 || ret >= MAXPATHLEN)
goto out_err;
if ((fd = open(nspath, O_RDONLY)) < 0) { fd = lxc_preserve_ns(pid, "net");
fprintf(stderr, "Opening %s\n", nspath); if (fd < 0) {
goto out_err; fprintf(stderr, "Failed opening network namespace path for '%d'.", pid);
return -1;
} }
if (setns(fd, 0) < 0) { if (setns(fd, 0) < 0) {
fprintf(stderr, "setns to container network namespace\n"); fprintf(stderr, "setns to container network namespace\n");
goto out_err; goto out_err;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment