|
@@ -18,6 +18,7 @@
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
|
|
+#include <asm/bug.h>
|
|
|
|
|
|
struct namespaces *namespaces__new(struct namespaces_event *event)
|
|
struct namespaces *namespaces__new(struct namespaces_event *event)
|
|
{
|
|
{
|
|
@@ -186,6 +187,7 @@ void nsinfo__mountns_enter(struct nsinfo *nsi,
|
|
char curpath[PATH_MAX];
|
|
char curpath[PATH_MAX];
|
|
int oldns = -1;
|
|
int oldns = -1;
|
|
int newns = -1;
|
|
int newns = -1;
|
|
|
|
+ char *oldcwd = NULL;
|
|
|
|
|
|
if (nc == NULL)
|
|
if (nc == NULL)
|
|
return;
|
|
return;
|
|
@@ -199,9 +201,13 @@ void nsinfo__mountns_enter(struct nsinfo *nsi,
|
|
if (snprintf(curpath, PATH_MAX, "/proc/self/ns/mnt") >= PATH_MAX)
|
|
if (snprintf(curpath, PATH_MAX, "/proc/self/ns/mnt") >= PATH_MAX)
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
+ oldcwd = get_current_dir_name();
|
|
|
|
+ if (!oldcwd)
|
|
|
|
+ return;
|
|
|
|
+
|
|
oldns = open(curpath, O_RDONLY);
|
|
oldns = open(curpath, O_RDONLY);
|
|
if (oldns < 0)
|
|
if (oldns < 0)
|
|
- return;
|
|
|
|
|
|
+ goto errout;
|
|
|
|
|
|
newns = open(nsi->mntns_path, O_RDONLY);
|
|
newns = open(nsi->mntns_path, O_RDONLY);
|
|
if (newns < 0)
|
|
if (newns < 0)
|
|
@@ -210,11 +216,13 @@ void nsinfo__mountns_enter(struct nsinfo *nsi,
|
|
if (setns(newns, CLONE_NEWNS) < 0)
|
|
if (setns(newns, CLONE_NEWNS) < 0)
|
|
goto errout;
|
|
goto errout;
|
|
|
|
|
|
|
|
+ nc->oldcwd = oldcwd;
|
|
nc->oldns = oldns;
|
|
nc->oldns = oldns;
|
|
nc->newns = newns;
|
|
nc->newns = newns;
|
|
return;
|
|
return;
|
|
|
|
|
|
errout:
|
|
errout:
|
|
|
|
+ free(oldcwd);
|
|
if (oldns > -1)
|
|
if (oldns > -1)
|
|
close(oldns);
|
|
close(oldns);
|
|
if (newns > -1)
|
|
if (newns > -1)
|
|
@@ -223,11 +231,16 @@ errout:
|
|
|
|
|
|
void nsinfo__mountns_exit(struct nscookie *nc)
|
|
void nsinfo__mountns_exit(struct nscookie *nc)
|
|
{
|
|
{
|
|
- if (nc == NULL || nc->oldns == -1 || nc->newns == -1)
|
|
|
|
|
|
+ if (nc == NULL || nc->oldns == -1 || nc->newns == -1 || !nc->oldcwd)
|
|
return;
|
|
return;
|
|
|
|
|
|
setns(nc->oldns, CLONE_NEWNS);
|
|
setns(nc->oldns, CLONE_NEWNS);
|
|
|
|
|
|
|
|
+ if (nc->oldcwd) {
|
|
|
|
+ WARN_ON_ONCE(chdir(nc->oldcwd));
|
|
|
|
+ zfree(&nc->oldcwd);
|
|
|
|
+ }
|
|
|
|
+
|
|
if (nc->oldns > -1) {
|
|
if (nc->oldns > -1) {
|
|
close(nc->oldns);
|
|
close(nc->oldns);
|
|
nc->oldns = -1;
|
|
nc->oldns = -1;
|