sigrelse01: Check if signal 34 is available for musl compat
PATCH 1/1 sigrelse01: Check if signal 34 is available for musl compat
Do not select signal 34 when the test is run using musl. Signal 34 is used internally by musl as SIGSYNCCALL. Consequently, musl's signal() will return with an error status and errno set to EINVAL when trying to setup a signal handler for signal 34, causing the sigrelse01 test to fail.
Since musl provides no preprocessor macro, we check for the availability of signal 34 by attempting to setup a signal handler. If signal() returns SIG_ERR with errno set to EINVAL then we assume the signal is unavailable. Knowing signal 34 is available with glibc, we perform this check only if __GLIBC__ is not defined.
--- .../kernel/syscalls/sigrelse/sigrelse01.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+)
testcases/kernel/syscalls/sigrelse/sigrelse01.c +28 -0
@@ -98,11 +98,14 @@* ***************************************************************************/ +#define _GNU_SOURCE +#include <sys/types.h> #include <sys/wait.h> #include <errno.h> #include <fcntl.h> #include <signal.h> +#include <stdbool.h> #include <stdlib.h> #include <string.h> #include <time.h>
@@ -177,6 +180,8 @@ static int sig_caught; /* flag TRUE if signal caught *//* array of counters for signals caught by handler() */ static int sig_array[NUMSIGS ]; +static bool sig34_available = true;/* Signal 34 is unavailable on e.g., musl */ +/*********************************************************************** * M A I N ***********************************************************************/
@@ -736,6 +741,8 @@ int choose_sig(int sig)case SIGSWAP :#endif return 0 ; +case 34 : +return sig34_available; }
@@ -773,6 +780,27 @@ void setup(void)if (fcntl (pipe_fd2[0 ],F_SETFL ,O_NONBLOCK ) ==-1 )tst_brkm (TBROK |TERRNO , cleanup,"fcntl(Fds[0], F_SETFL, O_NONBLOCK) failed" ); + +#ifndef __GLIBC__ +/* +* Check if signal 34 is available. Some libc implementations do +* not support signal 34. For example, musl uses signal 34 as +* internal signal (SIGSYNCCALL). +*/ +sighandler_t previous =signal (34 , handler); +if (previous ==SIG_ERR ) { +if (errno ==EINVAL ) + sig34_available = false; +else +tst_brkm (TBROK |TERRNO , cleanup, +"signal(34, handler) failed" ); + }else { +/* Restore the original handler */ +if (signal (34 , previous) ==SIG_ERR ) +tst_brkm (TBROK |TERRNO , cleanup, +"signal(34, handler) failed" ); + } +#endif }void cleanup (void )
Signature · 5 lines
2.49.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Florian,
Quoted 11 lines
Do not select signal 34 when the test is run using musl. Signal 34 is used internally by musl as SIGSYNCCALL. Consequently, musl's
signal()will return with an error status and errno set to EINVAL when trying to setup a signal handler for signal 34, causing the sigrelse01 test to fail.Since musl provides no preprocessor macro, we check for the availability of signal 34 by attempting to setup a signal handler. If
signal()returnsSIG_ERRwith errno set to EINVAL then we assume the signal is unavailable. Knowing signal 34 is available with glibc, we perform this check only if__GLIBC__is not defined.
...
Quoted 3 lines
+++
b/testcases/kernel/syscalls/sigrelse/sigrelse01.c+#define
_GNU_SOURCE
Unfortunately +#define _GNU_SOURCE causes test to hang, at least on glibc. And I see for musl it is necessary to get sighandler_t.
Until you fix glibc with _GNU_SOURCE NACK.
But on glibc it also brought a warning, which means _GNU_SOURCE really switches something on:
sigrelse01.c: In function ‘child’:
sigrelse01.c:397:33: warning: ‘sighold’ is deprecated: Use the sigprocmask function instead [-Wdeprecated-declarations]
397 | if ((rv = sighold(sig)) != 0) {
| ^~
In file included from /usr/include/sys/wait.h:36,
from sigrelse01.c:104:
/usr/include/signal.h:355:12: note: declared here
355 | extern int sighold (int __sig) __THROW
| ^~~~~~~
sigrelse01.c:472:25: warning: ‘sigrelse’ is deprecated: Use the sigprocmask function instead [-Wdeprecated-declarations]
472 | if ((rv = sigrelse(sig)) != 0) {
| ^~
/usr/include/signal.h:359:12: note: declared here
359 | extern int sigrelse (int __sig) __THROW
| ^~~~~~~~
sigrelse01.c: In function ‘timeout’:
sigrelse01.c:675:25: warning: unused parameter ‘sig’ [-Wunused-parameter]
675 | static void timeout(int sig)
| ~~~~^~~Also this is a very old test, which needs cleanup and rewrite to new LTP API (e.g. remove old unixes, e.g. VAX and get test more reliable). I suppose handling signals with LTP legacy API is broken.
testcases/kernel/syscalls/sigrelse/sigrelse01.c line 108
Quoted 7 lines
testcases/kernel/syscalls/sigrelse/sigrelse01.c +2
-0+#include <sys/types.h> #include <sys/wait.h> #include <errno.h> #include <fcntl.h> #include <signal.h> +#include <stdbool.h>
nit: I would postpone this after conversion this to new LTP API. Script already uses legacy definitions
#define TRUE 1
#define FALSE 0
and on a different place happily returns 0 or 1. Mixing that with <stdbool.h> makes even more mess.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 1 line · Petr Vorel
Hi Florian,
Hi Petr,
thanks for your review.
Quoted 12 lines
Quoted 11 lines
Do not select signal 34 when the test is run using musl. Signal 34 is used internally by musl as SIGSYNCCALL. Consequently, musl's
signal()will return with an error status and errno set to EINVAL when trying to setup a signal handler for signal 34, causing the sigrelse01 test to fail.Since musl provides no preprocessor macro, we check for the availability of signal 34 by attempting to setup a signal handler. If
signal()returnsSIG_ERRwith errno set to EINVAL then we assume the signal is unavailable. Knowing signal 34 is available with glibc, we perform this check only if__GLIBC__is not defined.
Quoted 6 lines
...
Quoted 3 lines
+++
b/testcases/kernel/syscalls/sigrelse/sigrelse01.c+#define
_GNU_SOURCEUnfortunately +#define
_GNU_SOURCEcauses test to hang, at least on glibc.
I don't think it hangs, but takes ages to complete. At least, that is what I found.
Quoted 2 lines
And I see for musl it is necessary to get
sighandler_t. Until you fix glibc with_GNU_SOURCENACK.
I think I can get rid of the _GNU_SOURCE. IIRC it was just needed to use the sighandler_t type. Without _GNU_SOURCE, declaring the return value of signal() as void* should also work.
Quoted 27 lines
But on glibc it also brought a warning, which means
_GNU_SOURCEreally switches something on:
sigrelse01.c: In function ‘child’:
sigrelse01.c:397:33: warning: ‘sighold’ is deprecated: Use the sigprocmask function instead [-Wdeprecated-declarations]397 | if ((rv = sighold(sig)) != 0) { | ^~ In file included from /usr/include/sys/wait.h:36, from sigrelse01.c:104: /usr/include/signal.h:355:12: note: declared here 355 | extern int sighold (int __sig) __THROW | ^~~~~~~ sigrelse01.c:472:25: warning: ‘sigrelse’ is deprecated: Use the sigprocmask function instead [-Wdeprecated-declarations] 472 | if ((rv = sigrelse(sig)) != 0) { | ^~ /usr/include/signal.h:359:12: note: declared here 359 | extern int sigrelse (int __sig) __THROW | ^~~~~~~~ sigrelse01.c: In function ‘timeout’: sigrelse01.c:675:25: warning: unused parameter ‘sig’ [-Wunused-parameter] 675 | static void timeout(int sig) | ~~~~^~~Also this is a very old test, which needs cleanup and rewrite to new LTP API (e.g. remove old unixes, e.g. VAX and get test more reliable). I suppose handling signals with LTP legacy API is broken.
Quoted 14 lines
testcases/kernel/syscalls/sigrelse/sigrelse01.c line 108
Quoted 7 lines
testcases/kernel/syscalls/sigrelse/sigrelse01.c +2
-0+#include <sys/types.h> #include <sys/wait.h> #include <errno.h> #include <fcntl.h> #include <signal.h> +#include <stdbool.h> nit: I would postpone this after conversion this to new LTP API. Script already uses legacy definitions
#define TRUE 1
#define FALSE 0
and on a different place happily returns 0 or 1. Mixing that with <stdbool.h> makes even more mess.
Agreed.
I am going send a v2 that does not use _GNU_SOURCE nor stdbool.h after checking that it still fixes musl compat for us while not introducing a regression on glibc.
- Florian
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Florian,
Quoted 6 lines · Petr Vorel
Quoted 1 line
Hi Florian,
Hi Petr,
thanks for your review.
yw, thanks for your work on LTP for musl.
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
Do not select signal 34 when the test is run using musl. Signal 34 is used internally by musl as SIGSYNCCALL. Consequently, musl's
signal()will return with an error status and errno set to EINVAL when trying to setup a signal handler for signal 34, causing the sigrelse01 test to fail.Since musl provides no preprocessor macro, we check for the availability of signal 34 by attempting to setup a signal handler. If
signal()returnsSIG_ERRwith errno set to EINVAL then we assume the signal is unavailable. Knowing signal 34 is available with glibc, we perform this check only if__GLIBC__is not defined....
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
+++
b/testcases/kernel/syscalls/sigrelse/sigrelse01.c+#define
_GNU_SOURCEUnfortunately +#define
_GNU_SOURCEcauses test to hang, at least on glibc.I don't think it hangs, but takes ages to complete. At least, that is what I found.
Yeah, you're more precise :). Nevertheless the result for the patchset remains => NACK when runtime drastically changes like this :(.
Quoted 6 lines
Quoted 2 lines
And I see for musl it is necessary to get
sighandler_t. Until you fix glibc with_GNU_SOURCENACK.I think I can get rid of the
_GNU_SOURCE. IIRC it was just needed to use thesighandler_ttype. Without_GNU_SOURCE, declaring the return value ofsignal()as void* should also work.
I suspect there is something else going wrong (test should not start magically using sighold() on glibc), but let's try a workaround.
Quoted 42 lines
Quoted 27 lines
But on glibc it also brought a warning, which means
_GNU_SOURCEreally switches something on:
sigrelse01.c: In function ‘child’:
sigrelse01.c:397:33: warning: ‘sighold’ is deprecated: Use the sigprocmask function instead [-Wdeprecated-declarations]397 | if ((rv = sighold(sig)) != 0) { | ^~ In file included from /usr/include/sys/wait.h:36, from sigrelse01.c:104: /usr/include/signal.h:355:12: note: declared here 355 | extern int sighold (int __sig) __THROW | ^~~~~~~ sigrelse01.c:472:25: warning: ‘sigrelse’ is deprecated: Use the sigprocmask function instead [-Wdeprecated-declarations] 472 | if ((rv = sigrelse(sig)) != 0) { | ^~ /usr/include/signal.h:359:12: note: declared here 359 | extern int sigrelse (int __sig) __THROW | ^~~~~~~~ sigrelse01.c: In function ‘timeout’: sigrelse01.c:675:25: warning: unused parameter ‘sig’ [-Wunused-parameter] 675 | static void timeout(int sig) | ~~~~^~~Also this is a very old test, which needs cleanup and rewrite to new LTP API (e.g. remove old unixes, e.g. VAX and get test more reliable). I suppose handling signals with LTP legacy API is broken.
Quoted 14 lines
testcases/kernel/syscalls/sigrelse/sigrelse01.c line 108
Quoted 7 lines
testcases/kernel/syscalls/sigrelse/sigrelse01.c +2
-0+#include <sys/types.h> #include <sys/wait.h> #include <errno.h> #include <fcntl.h> #include <signal.h> +#include <stdbool.h> nit: I would postpone this after conversion this to new LTP API. Script already uses legacy definitions
#define TRUE 1
#define FALSE 0
and on a different place happily returns 0 or 1. Mixing that with <stdbool.h> makes even more mess.
Quoted 5 lines
Agreed.
I am going send a v2 that does not use
_GNU_SOURCEnorstdbool.hafter checking that it still fixes musl compat for us while not introducing a regression on glibc.
+1, please document the reason for a workaround.
If you had more time, the best would be to rewrite the test to the new LTP API. I bet the problem with _GNU_SOURCE would go away. I don't expect you have more time, but if you do, here are links:
https://github.com/linux-test-project/ltp/blob/master/doc/old/C-Test-API.asciidoc
https://linux-test-project.readthedocs.io/en/latest/developers/api_c_tests.html
https://linux-test-project.readthedocs.io/en/latest/developers/test_case_tutorial.html
(We are in the middle of a doc transition into readthedocs, IMHO the old doc is still the best what we have.)
Also, 3 tests even don't compile on musl, here is the current list:
https://github.com/linux-test-project/ltp/blob/master/ci/alpine.sh#L32
Helping to fix them is more than welcome.
Kind regards,
Petr
Quoted 1 line
- Florian
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp