[PATCH v4 1/7] PID namespace translation support
Dmitry V. Levin
ldv at altlinux.org
Fri Jul 31 18:41:27 UTC 2020
On Mon, Jul 27, 2020 at 08:54:04PM +0200, Ákos Uzonyi wrote:
[...]
> +struct trie *ns_pid_to_proc_pid[PT_COUNT];
> +struct trie *proc_data_cache;
> +
> +bool ns_get_parent_enotty = false;
Could you make these variables static, please?
[...]
> +void
> +pidns_init(void)
> +{
> + static bool inited = false;
> + if (inited)
> + return;
> +
> + for (int i = 0; i < PT_COUNT; i++)
> + ns_pid_to_proc_pid[i] = trie_create(6, 10, 10, 64, 0);
> +
> + proc_data_cache = trie_create(6, 10, 10, 64, 0);
> +
> + inited = true;
> +}
Do we need "inited" variable, or could we check "proc_data_cache" instead?
> +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?
--
ldv
More information about the Strace-devel
mailing list