while (getline(&statln, &linesz, f) != -1) { /* Use tgid if CONFIG_PID_NS is not defined. */ if (strstr(statln, "Tgid:") != NULL) {
*tgid = (pid_t)strtol(strrchr(statln, '\t'), NULL, 10);
*nstgid = *tgid;
}
if (strstr(statln, "NStgid:") != NULL) {
nspid = strrchr(statln, '\t');
*nstgid = (pid_t)strtol(nspid, NULL, 10); /* * If innermost tgid is not the first, process is in a different * PID namespace.
*/
*in_pidns = (statln + sizeof("NStgid:") - 1) != nspid; break;
}
}
fclose(f);
free(statln); return 0;
}
int nsinfo__init(struct nsinfo *nsi)
{ char oldns[PATH_MAX]; char spath[PATH_MAX]; char *newns = NULL; struct stat old_stat; struct stat new_stat; int rv = -1;
if (snprintf(oldns, PATH_MAX, "/proc/self/ns/mnt") >= PATH_MAX) return rv;
if (asprintf(&newns, "/proc/%d/ns/mnt", nsinfo__pid(nsi)) == -1) return rv;
if (stat(oldns, &old_stat) < 0) goto out;
if (stat(newns, &new_stat) < 0) goto out;
/* Check if the mount namespaces differ, if so then indicate that we * want to switch as part of looking up dso/map data.
*/ if (old_stat.st_ino != new_stat.st_ino) {
RC_CHK_ACCESS(nsi)->need_setns = true;
RC_CHK_ACCESS(nsi)->mntns_path = newns;
newns = NULL;
}
/* If we're dealing with a process that is in a different PID namespace, * attempt to work out the innermost tgid for the process.
*/ if (snprintf(spath, PATH_MAX, "/proc/%d/status", nsinfo__pid(nsi)) >= PATH_MAX) goto out;
RC_CHK_ACCESS(nsi)->pid = pid;
RC_CHK_ACCESS(nsi)->tgid = pid;
RC_CHK_ACCESS(nsi)->nstgid = pid;
nsinfo__clear_need_setns(nsi);
RC_CHK_ACCESS(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.
*/ if (nsinfo__init(nsi) == -1)
nsinfo__clear_need_setns(nsi);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.