criu: don't use a glibc cached pid

Submitted by Andrei Vagin on March 28, 2017, 1:35 a.m.

Details

Message ID 1490664930-12607-1-git-send-email-avagin@openvz.org
State New
Series "core: Implement xgetpid()"
Headers show

Commit Message

Andrei Vagin March 28, 2017, 1:35 a.m.
From: Andrei Vagin <avagin@virtuozzo.com>

In glibc 2.24, getpid() returns a parent PID, if a child was created
with the CLONE_VM flag.

https://sourceware.org/bugzilla/show_bug.cgi?id=17214
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=857909

The glibc git contains the next patch, which removes cached pid too:
 commit c579f48edba88380635ab98cb612030e3ed8691e
 Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
 Date:   Mon Oct 10 15:08:39 2016 -0300

    Remove cached PID/TID in clone

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/util.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/util.c b/criu/util.c
index 38387ff..0671853 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -1393,3 +1393,12 @@  out_close:
 out_munmap:
 	return ret;
 }
+
+/*
+ * In glibc 2.24, getpid() returns a parent PID, if a child was
+ * created with the CLONE_VM flag.
+ */
+int getpid()
+{
+       return syscall(__NR_getpid);
+}

Comments

Cyrill Gorcunov March 28, 2017, 9:05 a.m.
On Tue, Mar 28, 2017 at 04:35:30AM +0300, Andrei Vagin wrote:
> From: Andrei Vagin <avagin@virtuozzo.com>
> 
> In glibc 2.24, getpid() returns a parent PID, if a child was created
> with the CLONE_VM flag.
> 
> https://sourceware.org/bugzilla/show_bug.cgi?id=17214
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=857909
> 
> The glibc git contains the next patch, which removes cached pid too:
>  commit c579f48edba88380635ab98cb612030e3ed8691e
>  Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
>  Date:   Mon Oct 10 15:08:39 2016 -0300
> 
>     Remove cached PID/TID in clone
> 
> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
> ---
>  criu/util.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/criu/util.c b/criu/util.c
> index 38387ff..0671853 100644
> --- a/criu/util.c
> +++ b/criu/util.c
> @@ -1393,3 +1393,12 @@ out_close:
>  out_munmap:
>  	return ret;
>  }
> +
> +/*
> + * In glibc 2.24, getpid() returns a parent PID, if a child was
> + * created with the CLONE_VM flag.
> + */
> +int getpid()
> +{
> +       return syscall(__NR_getpid);
> +}

Won't it conflict with existing libc function? Or getpid is
declared as __weak()? I would rather prefer gettid() and use
it instead

pid_t gettid(void)
{
	return syscall(__NR_gettid);
}