diff mbox series

[v3,1/2] Add tst_gettid wrapper around gettid syscall

Message ID 20230908102315.8163-2-andrea.cervesato@suse.de
State Superseded
Headers show
Series Rewrite exit_group01 test | expand

Commit Message

Andrea Cervesato Sept. 8, 2023, 10:23 a.m. UTC
From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/tst_pid.h | 8 ++++++++
 lib/tst_pid.c     | 5 +++++
 2 files changed, 13 insertions(+)

Comments

Cyril Hrubis Nov. 1, 2023, 12:29 p.m. UTC | #1
Hi!
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  include/tst_pid.h | 8 ++++++++
>  lib/tst_pid.c     | 5 +++++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/include/tst_pid.h b/include/tst_pid.h
> index 774c845ce..6958d5d23 100644
> --- a/include/tst_pid.h
> +++ b/include/tst_pid.h
> @@ -50,4 +50,12 @@ static inline int tst_get_free_pids(void (*cleanup_fn)(void))
>   */
>  pid_t tst_getpid(void);
>  
> +/*
> + * Direct gettid() syscall. Some glibc versions cache gettid() return value
> + * which can cause confusing issues for example in processes created by
> + * direct clone() syscall (without using the glibc wrapper). Use this function
> + * whenever the current process may be a child of the main test process.
                                              ^
					      thread spawned from the main ...
> + */
> +pid_t tst_gettid(void);
> +
>  #endif /* TST_PID_H__ */
> diff --git a/lib/tst_pid.c b/lib/tst_pid.c
> index cfaa5db36..4e9dc7a52 100644
> --- a/lib/tst_pid.c
> +++ b/lib/tst_pid.c
> @@ -166,3 +166,8 @@ pid_t tst_getpid(void)
>  {
>  	return syscall(SYS_getpid);
>  }
> +
> +pid_t tst_gettid(void)
> +{
> +	return syscall(SYS_gettid);
> +}
> -- 
> 2.35.3
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp
diff mbox series

Patch

diff --git a/include/tst_pid.h b/include/tst_pid.h
index 774c845ce..6958d5d23 100644
--- a/include/tst_pid.h
+++ b/include/tst_pid.h
@@ -50,4 +50,12 @@  static inline int tst_get_free_pids(void (*cleanup_fn)(void))
  */
 pid_t tst_getpid(void);
 
+/*
+ * Direct gettid() syscall. Some glibc versions cache gettid() return value
+ * which can cause confusing issues for example in processes created by
+ * direct clone() syscall (without using the glibc wrapper). Use this function
+ * whenever the current process may be a child of the main test process.
+ */
+pid_t tst_gettid(void);
+
 #endif /* TST_PID_H__ */
diff --git a/lib/tst_pid.c b/lib/tst_pid.c
index cfaa5db36..4e9dc7a52 100644
--- a/lib/tst_pid.c
+++ b/lib/tst_pid.c
@@ -166,3 +166,8 @@  pid_t tst_getpid(void)
 {
 	return syscall(SYS_getpid);
 }
+
+pid_t tst_gettid(void)
+{
+	return syscall(SYS_gettid);
+}