[PATCH 1/7] PID namespace translation support
Ákos Uzonyi
uzonyi.akos at gmail.com
Sat Jul 18 09:55:24 UTC 2020
On Fri, 17 Jul 2020 at 16:41, Dmitry V. Levin <ldv at altlinux.org> wrote:
> On Sun, Jul 12, 2020 at 09:46:30PM +0200, Ákos Uzonyi wrote:
> [...]
> > +/**
> > + * Returns a list of PID NS IDs for the specified PID.
> > + *
> > + * @param proc_pid PID (as present in /proc) to get information for.
> > + * @param ns_buf Pointer to buffer that is able to contain at least
> > + * MAX_NS_DEPTH items.
> > + * @param last ID of NS on which ascencion can be interrupted.
> > + * 0 for no interruption.
> > + * @return Amount of NS in list. 0 indicates error, MAX_NS_DEPTH + 1
> > + * indicates that ascension limit hasn't been reached (only
> > + * MAX_NS_DEPTH values have been written to the array, however).
> > + */
> > +static size_t
> > +get_ns_hierarchy(int proc_pid, uint64_t *ns_buf, size_t ns_buf_size)
>
> Looks like the description of get_ns_hierarchy is out of sync with the
> implementation.
Thanks, will be fixed.
> > +{
> > + char path[PATH_MAX + 1];
> > + struct stat st;
> > + ssize_t ret;
> > + size_t n = 0;
> > + int fd;
> > + int parent_fd;
> > +
> > + ret = snprintf(path, sizeof(path), "/proc/%s/ns/pid",
> > + pid_to_str(proc_pid));
> > +
> > + if ((ret < 0) || ((size_t) ret >= sizeof(path)))
> > + return 0;
> > +
> > + fd = open(path, O_RDONLY | O_NONBLOCK);
> > + if (fd < 0)
> > + return 0;
> > +
> > + while (1) {
> > + ret = fstat(fd, &st);
> > + if (ret)
> > + break;
> > +
> > + /* 32 is the hierarchy depth on modern Linux */
> > + if ((n >= MAX_NS_DEPTH) || (n >= ns_buf_size)) {
>
> Is ns_buf_size allowed to exceed MAX_NS_DEPTH?
Yes, it's allowed to be larger than MAX_NS_DEPTH. Checking (n >=
MAX_NS_DEPTH) condition is useless, however. I'm going to refactor
this function a bit.
More information about the Strace-devel
mailing list