Add Syscall numbers for pidfd_send_signal
PATCH 1/4 Add Syscall numbers for pidfd_send_signal
--- include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + 13 files changed, 13 insertions(+)
include/lapi/syscalls/aarch64.in +1 -0
@@ -265,4 +265,5 @@ mlock2 284 copy_file_range 285 preadv2 286 pwritev2 287 +pidfd_send_signal 424 _sysctl 1078
include/lapi/syscalls/arm.in +1 -0
@@ -350,3 +350,4 @@ copy_file_range (__NR_SYSCALL_BASE+391) preadv2 (__NR_SYSCALL_BASE+392) pwritev2 (__NR_SYSCALL_BASE+393) statx (__NR_SYSCALL_BASE+397) +pidfd_send_signal (__NR_SYSCALL_BASE+424)
include/lapi/syscalls/hppa.in +1 -0
@@ -25,3 +25,4 @@ mlock2 345 copy_file_range 346 preadv2 347 pwritev2 348 +pidfd_send_signal 424
include/lapi/syscalls/i386.in +1 -0
@@ -348,3 +348,4 @@ copy_file_range 377 preadv2 378 pwritev2 379 statx 383 +pidfd_send_signal 424
include/lapi/syscalls/ia64.in +1 -0
@@ -305,3 +305,4 @@ mlock2 1346 copy_file_range 1347 preadv2 1348 pwritev2 1349 +pidfd_send_signal 1448
include/lapi/syscalls/powerpc.in +1 -0
@@ -355,3 +355,4 @@ copy_file_range 379 preadv2 380 pwritev2 381 statx 383 +pidfd_send_signal 424
include/lapi/syscalls/powerpc64.in +1 -0
@@ -355,3 +355,4 @@ copy_file_range 379 preadv2 380 pwritev2 381 statx 383 +pidfd_send_signal 424
include/lapi/syscalls/s390.in +1 -0
@@ -338,3 +338,4 @@ mlock2 374 copy_file_range 375 preadv2 376 pwritev2 377 +pidfd_send_signal 424
include/lapi/syscalls/s390x.in +1 -0
@@ -337,3 +337,4 @@ mlock2 374 copy_file_range 375 preadv2 376 pwritev2 377 +pidfd_send_signal 424
include/lapi/syscalls/sh.in +1 -0
@@ -369,3 +369,4 @@ mlock2 390 copy_file_range 391 preadv2 392 pwritev2 393 +pidfd_send_signal 424
include/lapi/syscalls/sparc.in +1 -0
@@ -343,3 +343,4 @@ mlock2 356 copy_file_range 357 preadv2 358 pwritev2 359 +pidfd_send_signal 424
include/lapi/syscalls/sparc64.in +1 -0
@@ -319,3 +319,4 @@ mlock2 356 copy_file_range 357 preadv2 358 pwritev2 359 +pidfd_send_signal 424
include/lapi/syscalls/x86_64.in +1 -0
@@ -315,3 +315,4 @@ copy_file_range 326 preadv2 327 pwritev2 328 statx 332 +pidfd_send_signal 424
Signature · 1 line
2.16.4
PATCH 2/4 syscalls/pidfd_send_signal01
Add testcase to check if pidfd_send_signal() can provide the same functionality as rt_sigqueueinfo().
--- runtest/syscalls | 2 + .../kernel/syscalls/pidfd_send_signal/.gitignore | 1 + .../kernel/syscalls/pidfd_send_signal/Makefile | 14 +++ .../syscalls/pidfd_send_signal/pidfd_send_signal.h | 20 ++++ .../pidfd_send_signal/pidfd_send_signal01.c | 110 +++++++++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 testcases/kernel/syscalls/pidfd_send_signal/.gitignore create mode 100644 testcases/kernel/syscalls/pidfd_send_signal/Makefile create mode 100644 testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal.h create mode 100644 testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c
runtest/syscalls +2 -0
@@ -838,6 +838,8 @@ pause03 pause03 personality01 personality01 personality02 personality02 +pidfd_send_signal01 pidfd_send_signal01 + pipe01 pipe01 pipe02 pipe02 pipe03 pipe03
testcases/kernel/syscalls/pidfd_send_signal/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/pidfd_send_signal01
testcases/kernel/syscalls/pidfd_send_signal/Makefile new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (c) 2019 SUSE LLC +# +# Author: Christian Amann <[email protected]> +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk + +pidfd_send_signal01: CFLAGS += -pthread
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal.h new file +20 -0
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 SUSE LLC +* Author: Christian Amann <[email protected]> +*/ + +#ifndef __PIDFD_SEND_SIGNAL_H__ +#define __PIDFD_SEND_SIGNAL_H__ + +#include "tst_test.h" +#include "lapi/syscalls.h" + +static int tst_pidfd_send_signal (int pidfd,int sig,siginfo_t *info, +unsigned int flags) +{ +return tst_syscall (__NR_pidfd_send_signal, pidfd, sig, info, flags); +} + + +#endif /* __PIDFD_SEND_SIGNAL_H__ */
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +110 -0
110 lines not on this page · raw message
Signature · 1 line
2.16.4
PATCH 2/4 syscalls/pidfd_send_signal01
Hi!
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal.h line 8
Quoted 13 lines
new file mode 100644
index 000000000..3553c5464testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal.h new file +8
-0@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 SUSE LLC +* Author: Christian Amann <[email protected]> +*/ + +#ifndef __PIDFD_SEND_SIGNAL_H__ +#define __PIDFD_SEND_SIGNAL_H__
^
Plese don't use undescores at the beginning of identifiers.
Identifiers starting with _ and __ are reserved for the system, i.e. libc and compiler.
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal.h line 14
Quoted 5 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal.h new file +5
-0+#include "tst_test.h" +#include "lapi/syscalls.h" + +static int tst_pidfd_send_signal (int pidfd,int sig,siginfo_t *info, +unsigned int flags)
We probably should not use the tst_ prefix here as this is not a test library code.
I guess that we can make this future proof with a configure check for pidfd_send_signal() that will get included in glibc later on.
Quoted 12 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal.h new file +6
-0+{ +return tst_syscall (__NR_pidfd_send_signal, pidfd, sig, info, flags); +} + + +#endif /* __PIDFD_SEND_SIGNAL_H__ */ testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +0
-0
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c line 7
Quoted 7 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +7
-0@@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 SUSE LLC +* Author: Christian Amann <[email protected]> +*/ +/* +* Tests if the pidfd_send_signal systemcall behaves
^
Should either be one of:
* syscall
* system call
Quoted 19 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +19
-0+* like rt_sigqueueinfo when a pointer to a siginfo_t +* struct is passed. +*/ + +#define _GNU_SOURCE + +#include <signal.h> +#include <stdlib.h> +#include "tst_safe_pthread.h" +#include "pidfd_send_signal.h" + +#define SIGNAL SIGUSR1 +#define DATA 777 + +static struct sigaction *sig_action; +static int sig_rec; +static siginfo_t *uinfo; +static int pidfd; +
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c line 36
Quoted 10 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +10
-0+static void received_signal (int sig,siginfo_t *info,void *ucontext) +{ +if (info && ucontext) { +if (sig ==SIGNAL && uinfo->si_value.sival_int ==DATA ) { +tst_res (TPASS ,"Received correct signal and data!" ); + sig_rec =1 ; + }else +tst_res (TFAIL ,"Received wrong signal and/or data!" ); + }else +tst_res (TFAIL ,"Signal handling went wrong!" );
This is a very minor however LKML coding style prefers to have curly braces around both blocks if they have to be over one of them.
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c line 39
Quoted 3 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +3
-0+} + +static void *handle_thread(void *arg LTP_ATTRIBUTE_UNUSED)
^
You do return arg at the end of this function, there is no point in the ATTRIBUTE_UNUSED
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c line 45
Quoted 6 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +6
-0+{ +int ret; + + ret =sigaction (SIGNAL , sig_action,NULL ); +if (ret) +tst_brk (TBROK |TTERRNO ,"Failed to set sigaction" );
Why not SAFE_SIGACTION() ?
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c line 48
Quoted 2 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +2
-0+TST_CHECKPOINT_WAKE (0 ); +TST_CHECKPOINT_WAIT (1 );
We do have TST_CHECKPOINT_WAKE_AND_WAIT().
Quoted 13 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +13
-0+return arg; +} + +static void verify_pidfd_send_signal (void ) +{ +pthread_t thr; + +SAFE_PTHREAD_CREATE (&thr,NULL , handle_thread,NULL ); + +TST_CHECKPOINT_WAIT (0 ); + +TEST (tst_pidfd_send_signal (pidfd,SIGNAL , uinfo,0 )); +if (TST_RET !=0 ) {
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c line 71
Quoted 10 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +10
-0+tst_res (TFAIL |TTERRNO ,"pidfd_send_signal() failed" ); +return ; + } + +TST_CHECKPOINT_WAKE (1 ); +SAFE_PTHREAD_JOIN (thr,NULL ); + +if (sig_rec) +tst_res (TPASS , +"pidfd_send_signal() behaved like rt_sigqueueinfo()" );
Very minor as well, LKML coding style prefers curly braces around multiline statements like this one.
Quoted 28 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +28
-0+} + +static void setup (void ) +{ + pidfd =SAFE_OPEN ("/proc/self" ,O_DIRECTORY |O_CLOEXEC ); + + sig_action =SAFE_MALLOC (sizeof (struct sigaction )); + +memset (sig_action,0 ,sizeof (*sig_action)); + sig_action->sa_sigaction = received_signal; + sig_action->sa_flags =SA_SIGINFO ; + + uinfo =SAFE_MALLOC (sizeof (siginfo_t)); + +memset (uinfo,0 ,sizeof (*uinfo)); + uinfo->si_signo =SIGNAL ; + uinfo->si_code =SI_QUEUE ; + uinfo->si_pid =getpid (); + uinfo->si_uid =getuid (); + uinfo->si_value.sival_int =DATA ; + + sig_rec =0 ; +} + +static void cleanup (void ) +{ +free (uinfo); +free (sig_action);
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c line 109
Quoted 10 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +10
-0+if (pidfd >0 ) +SAFE_CLOSE (pidfd); +} + +static struct tst_test test = { + .test_all = verify_pidfd_send_signal, + .setup = setup, + .cleanup = cleanup, + .needs_checkpoints =1 , + .timeout =20 ,
Please do not change the default timeout unless it's needed.
There are actually only two situations where this makese sense:
* The test is expected to run for a long time
=> timeout needs to be increased
* The test goes into an infinit loop on a buggy kernel => timeout has to be set low, so that we do not waste time
Quoted 3 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file +1
-0+};Signature · 1 line
2.16.4
Other than the minor comments, the test looks good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/4 syscalls/pidfd_send_signal02
In reply to Christian AmannAdd test to check basic error handling of the syscall.
--- runtest/syscalls | 1 + .../kernel/syscalls/pidfd_send_signal/.gitignore | 1 + .../pidfd_send_signal/pidfd_send_signal02.c | 104 +++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c
runtest/syscalls +1 -0
@@ -839,6 +839,7 @@ personality01 personality01 personality02 personality02 pidfd_send_signal01 pidfd_send_signal01 +pidfd_send_signal02 pidfd_send_signal02 pipe01 pipe01 pipe02 pipe02
testcases/kernel/syscalls/pidfd_send_signal/.gitignore +1 -0
@@ -1 +1,2 @@ /pidfd_send_signal01 +/pidfd_send_signal02
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
2.16.4
PATCH 3/4 syscalls/pidfd_send_signal02
Hi!
Quoted 4 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c new file +4
-0+static void verify_pidfd_send_signal (unsigned int n) +{ +struct tcase *tc = &tcases[n]; +
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c line 65
Quoted 10 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c new file +10
-0+TEST (tst_pidfd_send_signal (*tc->fd, tc->signal, tc->siginf, tc->flags)); +if (tc->exp_err !=TST_ERR ) { +tst_res (TFAIL |TTERRNO , +"pidfd_send_signal() did not fail with %s but" , +tst_strerrno (tc->exp_err)); +return ; + } + +tst_res (TPASS , +"pidfd_send_signal() failed as expected!" );
I tend to pass TTERRNO to the passing message for negative testcases like this one so that the output has some information about what has been tested.
I would have done something as here:
tst_res(TPASS | TTERRNO, "pidfd_send_signal() failed");
Other than this the test looks good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 4/4 syscalls/pidfd_send_signal03
In reply to Christian AmannAdd testcase to check if the syscall will send a signal to a process with the same PID as the targeted process.
--- runtest/syscalls | 1 + .../kernel/syscalls/pidfd_send_signal/.gitignore | 1 + .../pidfd_send_signal/pidfd_send_signal03.c | 118 +++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c
runtest/syscalls +1 -0
@@ -840,6 +840,7 @@ personality02 personality02 pidfd_send_signal01 pidfd_send_signal01 pidfd_send_signal02 pidfd_send_signal02 +pidfd_send_signal03 pidfd_send_signal03 pipe01 pipe01 pipe02 pipe02
testcases/kernel/syscalls/pidfd_send_signal/.gitignore +1 -0
@@ -1,2 +1,3 @@ /pidfd_send_signal01 /pidfd_send_signal02 +/pidfd_send_signal03
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.16.4
PATCH 4/4 syscalls/pidfd_send_signal03
Hi!
Quoted 28 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c new file +28
-0+#define _GNU_SOURCE + +#include <signal.h> +#include <stdio.h> +#include <unistd.h> +#include "pidfd_send_signal.h" +#include "tst_safe_pthread.h" + +#define PIDTRIES 3 + +static char *last_pid_file; +static int pidfd, last_pidfd; + +static void verify_pidfd_send_signal (void ) +{ +pid_t pid, new_pid; +char pid_filename[32 ]; +char pid_str[16 ]; +int i, fail; + + fail =1 ; +for (i =1 ; i <=PIDTRIES ; i++) { + pid =SAFE_FORK (); +if (pid ==0 ) { +TST_CHECKPOINT_WAIT (0 ); +return ; + } +
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c line 55
Quoted 10 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c new file +10
-0+sprintf (pid_filename,"/proc/%d" , pid); + pidfd =SAFE_OPEN (pid_filename,O_DIRECTORY |O_CLOEXEC ); + +TST_CHECKPOINT_WAKE (0 ); +tst_reap_children (); + +/* Manipulate PID for next process */ +sprintf (pid_str,"%d" , pid -1 ); +SAFE_LSEEK (last_pidfd,0 ,SEEK_SET ); +SAFE_WRITE (1 , last_pidfd, pid_str,strlen (pid_str));
We do have SAFE_FILE_PRINTF() for this purpose.
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c line 61
Quoted 5 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c new file +5
-0+ new_pid =SAFE_FORK (); +if (new_pid ==0 ) { +TST_CHECKPOINT_WAIT (i); +return ; + }else if (new_pid == pid) {
No need for else here if you do return in the if above.
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c line 70
Quoted 9 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c new file +9
-0+ fail =0 ; +break ; + } + +if (i <PIDTRIES ) +tst_res (TINFO , +"Failed to set correct PID, trying again..." ); +SAFE_CLOSE (pidfd); +TST_CHECKPOINT_WAKE (i);
Do we really need to use checkpoint i here? The checkpoint 0 should be unused at this point...
Quoted 4 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c new file +4
-0+tst_reap_children (); + } +if (fail) + tst_brk(TBROK,
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c line 84
Quoted 10 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c new file +10
-0+ "Could not set new child to same PID as the old one!"); + +TEST (tst_pidfd_send_signal (pidfd,SIGUSR1 ,NULL ,0 )); +if (TST_RET ==-1 &&TST_ERR ==ESRCH ) { +tst_res (TPASS , +"Did not send signal to wrong process with same PID!" ); + }else +tst_res (TFAIL |TTERRNO , +"pidf_send_signal() ended unexpectedly - return value: %ld, error" , +TST_RET );
Other obvious test would be opening the pidfd of the new pid and comparing if they point out to the same file by comparing i-nodes, see ioctl_ns05.c.
Quoted 39 lines
testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c new file +33
-0+TST_CHECKPOINT_WAKE (i); +tst_reap_children (); + +SAFE_CLOSE (pidfd); +} + +static void setup (void ) +{ + last_pid_file ="/proc/sys/kernel/ns_last_pid" ; +if (access (last_pid_file,F_OK ) ==-1 ) +tst_brk (TCONF ,"%s does not exist, cannot set PIDs" , + last_pid_file); + last_pidfd =SAFE_OPEN (last_pid_file,O_RDWR ); +} + +static void cleanup (void ) +{ +tst_reap_children (); +if (pidfd >0 ) +SAFE_CLOSE (pidfd); +if (last_pidfd >0 ) +SAFE_CLOSE (last_pidfd); +} + +static struct tst_test test = { + .test_all = verify_pidfd_send_signal, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .needs_checkpoints =1 , + .forks_child =1 , + .timeout =20 , +};Signature · 5 lines
2.16.4 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/4 Add Syscall numbers for pidfd_send_signal
In reply to Christian AmannHi Christian,
Quoted 1 line
Signed-off-by Christian Amann <[email protected]>
Kind regards,
Petr