From f10251e66c1e8c5fdcdc510c212eb6d78fb05ab7 Mon Sep 17 00:00:00 2001 From: Pavel Tikhomirov Date: Mon, 29 May 2017 18:21:03 +0300 Subject: [PATCH] pstree: make equal_pid handle sid comparison between nested pidnses If process belonging to some session is in different pidns than leader of these session, it will have zeroes on all aditional levels in sid, so though levels for these process and leader does not match - sids do. v2: change to static inline function as there is no more pr_err Signed-off-by: Pavel Tikhomirov Signed-off-by: Andrei Vagin --- criu/include/pid.h | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/criu/include/pid.h b/criu/include/pid.h index 72f36360f..04549022e 100644 --- a/criu/include/pid.h +++ b/criu/include/pid.h @@ -46,21 +46,27 @@ struct pid { } ns[1]; /* Must be at the end of struct pid */ }; -#define equal_pid(a, b) \ -({ \ - int ___i, ___ret = true; \ - if (a->level == b->level) { \ - for (___i = 0; ___i < a->level; ___i++) \ - if (a->ns[___i].virt != b->ns[___i].virt) { \ - ___ret = false; \ - ___i = a->level; /* break */ \ - } \ - } else { \ - pr_err("Wrong pid nesting level\n"); \ - ___ret = false; \ - } \ - ___ret; \ -}) +static inline bool equal_pid(struct pid *a, struct pid *b) +{ + struct pid *t; + int i; + + if (a->level > b->level) { + t = a; + a = b; + b = t; + } + + for(i = 0; i < b->level; i++) { + if (i < a->level) { + if (a->ns[i].virt != b->ns[i].virt) + return false; + } else if (b->ns[i].virt != 0) + return false; + } + + return true; +} static inline pid_t last_level_pid(struct pid *pid) {