summaryrefslogtreecommitdiff
path: root/tools/perf/util/namespaces.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/namespaces.c')
-rw-r--r--tools/perf/util/namespaces.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/tools/perf/util/namespaces.c b/tools/perf/util/namespaces.c
index 285d6f30d912..608b20c72a5c 100644
--- a/tools/perf/util/namespaces.c
+++ b/tools/perf/util/namespaces.c
@@ -66,6 +66,7 @@ int nsinfo__init(struct nsinfo *nsi)
char spath[PATH_MAX];
char *newns = NULL;
char *statln = NULL;
+ char *nspid;
struct stat old_stat;
struct stat new_stat;
FILE *f = NULL;
@@ -112,8 +113,12 @@ int nsinfo__init(struct nsinfo *nsi)
}
if (strstr(statln, "NStgid:") != NULL) {
- nsi->nstgid = (pid_t)strtol(strrchr(statln, '\t'),
- NULL, 10);
+ nspid = strrchr(statln, '\t');
+ nsi->nstgid = (pid_t)strtol(nspid, NULL, 10);
+ /* If innermost tgid is not the first, process is in a different
+ * PID namespace.
+ */
+ nsi->in_pidns = (statln + sizeof("NStgid:") - 1) != nspid;
break;
}
}
@@ -140,6 +145,7 @@ struct nsinfo *nsinfo__new(pid_t pid)
nsi->tgid = pid;
nsi->nstgid = pid;
nsi->need_setns = false;
+ nsi->in_pidns = false;
/* Init may fail if the process exits while we're trying to look
* at its proc information. In that case, save the pid but
* don't try to enter the namespace.
@@ -166,6 +172,7 @@ struct nsinfo *nsinfo__copy(struct nsinfo *nsi)
nnsi->tgid = nsi->tgid;
nnsi->nstgid = nsi->nstgid;
nnsi->need_setns = nsi->need_setns;
+ nnsi->in_pidns = nsi->in_pidns;
if (nsi->mntns_path) {
nnsi->mntns_path = strdup(nsi->mntns_path);
if (!nnsi->mntns_path) {
@@ -280,3 +287,15 @@ char *nsinfo__realpath(const char *path, struct nsinfo *nsi)
return rpath;
}
+
+int nsinfo__stat(const char *filename, struct stat *st, struct nsinfo *nsi)
+{
+ int ret;
+ struct nscookie nsc;
+
+ nsinfo__mountns_enter(nsi, &nsc);
+ ret = stat(filename, st);
+ nsinfo__mountns_exit(&nsc);
+
+ return ret;
+}