[PATCH v4 1/7] PID namespace translation support

Dmitry V. Levin ldv at altlinux.org
Fri Jul 31 19:50:52 UTC 2020


On Fri, Jul 31, 2020 at 09:41:30PM +0200, Ákos Uzonyi wrote:
> On Fri, 31 Jul 2020 at 20:41, Dmitry V. Levin <ldv at altlinux.org> wrote:
> > On Mon, Jul 27, 2020 at 08:54:04PM +0200, Ákos Uzonyi wrote:
> [...]
> > > +static bool
> > > +is_proc_ours(void)
> > > +{
> > > +     static int cached_val = -1;
> > > +
> > > +     if (cached_val < 0)
> > > +             cached_val = get_id_list(0, NULL, PT_TID) == 1;
> > > +
> > > +     return cached_val;
> > > +}
> > > +
> > > +static uint64_t
> > > +get_ns(struct tcb *tcp)
> > > +{
> > > +     if (!tcp->pid_ns_inited) {
> > > +             int proc_pid = 0;
> > > +
> > > +             if (is_proc_ours())
> > > +                     proc_pid = tcp->pid;
> > > +             else
> > > +                     translate_pid(NULL, tcp->pid, PT_TID, &proc_pid);
> > > +
> > > +             if (proc_pid)
> > > +                     get_ns_hierarchy(proc_pid, &tcp->pid_ns, 1);
> > > +
> > > +             tcp->pid_ns_inited = true;
> > > +     }
> > > +
> > > +     return tcp->pid_ns;
> > > +}
> > > +
> > > +static uint64_t
> > > +get_our_ns(void)
> > > +{
> > > +     static uint64_t our_ns = 0;
> > > +     static bool our_ns_initialised = false;
> > > +
> > > +     if (!our_ns_initialised) {
> > > +             get_ns_hierarchy(0, &our_ns, 1);
> > > +             our_ns_initialised = true;
> > > +     }
> > > +
> > > +     return our_ns;
> > > +}
> >
> > Could you add some short comments describing the purpose of these
> > functions, similar to other functions in this file, please?
> 
> Ok, I'll add short documentations to these functions, and maybe some
> other functions as well.
> 
> In case of non-static functions where is it more appropriate to place
> the documentation: above the implementation or the declaration
> (defs.h)? I see both being used in strace.

I'd say above the declaration would be more appropriate, but
we haven't been consistent in following this rule.


-- 
ldv


More information about the Strace-devel mailing list