Skip to contentSkip to conversation

openposix/twoptimers.c: Use other signal instead of SIGALRM

PATCH New Yang Xu 3 participants 5 messages Mar 18, 2020 – May 5, 2020

lore
Share & tools
lore

Yang Xu

author
#0 lore raw

PATCH 1/1 openposix/twoptimers.c: Use other signal instead of SIGALRM

Currently, run this case failed as below:

Got it! Child
Alarm clock

Parent process doesn't get SIGALRM siganl by using sigwait. It seems SIGALRM siganl is handled by system but not user.

From timer_create man-page, it said "
Specifying sevp as NULL is equivalent to specifying a pointer to a sigevent structure in which sigev_notify is SIGEV_SIGNAL, sigev_signo is SIGALRM, and sigev_value.sival_int is the timer ID".

I think this is the reason. So use SIGILL signal to avoid system caught.

---
 .../functional/timers/timers/twoptimers.c                     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/open_posix_testsuite/functional/timers/timers/twoptimers.c +2 -2
index 84bea3f0a..7e1648d5b 100644
@@ -92,13 +92,13 @@ int main(int argc, char *argv[])
 			return PTS_UNRESOLVED;
 		}
 
-		if (sigaddset(&set, SIGALRM) == -1) {
+		if (sigaddset(&set, SIGILL) == -1) {
 			perror("sigaddset() failed\n");
 			return PTS_UNRESOLVED;
 		}
 
 		ev.sigev_notify = SIGEV_SIGNAL;
-		ev.sigev_signo = SIGALRM;
+		ev.sigev_signo = SIGILL;
 		if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
 			perror("timer_create() did not return success\n");
 			return PTS_UNRESOLVED;
Signature · 1 line
2.18.1
#1 lore raw

PATCH 1/1 openposix/twoptimers.c: Use other signal instead of SIGALRM

Quoted 8 lines · Yang Xu

Currently, run this case failed as below:

Got it! Child
Alarm clock

Parent process doesn't get SIGALRM siganl by using sigwait. It seems SIGALRM siganl is handled by system but not user.

Quoted 6 lines
Quoted 1 line

From timer_create man-page, it said "

Specifying sevp as NULL is equivalent to specifying a pointer to a sigevent structure in which sigev_notify is SIGEV_SIGNAL, sigev_signo is SIGALRM, and sigev_value.sival_int is the timer ID".

I think this is the reason. So use SIGILL signal to avoid system caught.

Hi Xu,

I don't like the fix. You don't figure out the root cause of issue and just bypass it.(User can catch SIGALRM by default usually).

Perhaps, you need to reset the behavior of SIGALRM to default if it is not default.

Thanks,
Xiao Yang

Quoted 25 lines
---
  .../functional/timers/timers/twoptimers.c                     | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
testcases/open_posix_testsuite/functional/timers/timers/twoptimers.c +2 -2
index 84bea3f0a..7e1648d5b 100644
@@ -92,13 +92,13 @@ int main(int argc, char *argv[])
  			return PTS_UNRESOLVED;
  		}
 
-		if (sigaddset(&set, SIGALRM) == -1) {
+		if (sigaddset(&set, SIGILL) == -1) {
  			perror("sigaddset() failed\n");
  			return PTS_UNRESOLVED;
  		}
 
  		ev.sigev_notify = SIGEV_SIGNAL;
-		ev.sigev_signo = SIGALRM;
+		ev.sigev_signo = SIGILL;
  		if (timer_create(CLOCK_REALTIME,&ev,&tid) != 0) {
  			perror("timer_create() did not return success\n");
  			return PTS_UNRESOLVED;
author
#2 lore raw

PATCH 1/1 openposix/twoptimers.c: Use other signal instead of SIGALRM

Hi Xiao

Quoted 14 lines · Yang Xu
Quoted 13 lines

Currently, run this case failed as below:

Got it!? Child
Alarm clock

Parent process doesn't get SIGALRM siganl by using sigwait. It seems SIGALRM siganl is handled by system but not user.

Quoted 1 line

From timer_create man-page, it said "

Specifying? sevp as NULL is equivalent to specifying a pointer to a sigevent structure in which sigev_notify is SIGEV_SIGNAL, sigev_signo is SIGALRM, and sigev_value.sival_int is the timer ID".

Quoted 5 lines
Quoted 1 line

I think this is the reason. So use SIGILL signal to avoid system caught.

Hi Xu,

I don't like the fix.? You don't figure out the root cause of issue and just bypass it.(User can catch SIGALRM by default usually).

Sorry for this.
Yes. But user usually will install customized singal handler for SIGALRM by using sigaction function. On multi threads program, user will set SIGALRM signal into signal mask by using sigprocmask, so it can ensure current thread can get this signal from pending list.

So I plan to fix this bug as below:

testcases/open_posix_testsuite/functional/timers/timers/twoptimers.c +16 -5
@@ -50,7 +50,10 @@ int main(int argc, char *argv[])
                         perror("sigaddset() failed\n");
                         return PTS_UNRESOLVED;
                 }
-
+               if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
+                       perror("sigprocmask() failed\n");
+                       return PTS_UNRESOLVED;
+               }
                 ev.sigev_notify = SIGEV_SIGNAL;
                 ev.sigev_signo = SIGABRT;
                 if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
@@ -73,8 +76,10 @@ int main(int argc, char *argv[])
                         perror("sigwait() failed\n");
                         return PTS_UNRESOLVED;
                 }
-               printf("Got it!  Child\n");
-
+               if (sig == SIGABRT)
+                       printf("Got it!  Child\n");
+               else
+                       printf("Got another signal! Child\n");
                 sleep(LONGTIME);
                 return CHILDPASS;
         } else {
@@ -96,6 +101,10 @@ int main(int argc, char *argv[])
                         perror("sigaddset() failed\n");
                         return PTS_UNRESOLVED;
                 }
+               if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
+                       perror("sigprocmask() failed\n");
+                       return PTS_UNRESOLVED;
+                }
 
                 ev.sigev_notify = SIGEV_SIGNAL;
                 ev.sigev_signo = SIGALRM;
@@ -119,8 +128,10 @@ int main(int argc, char *argv[])
                         perror("sigwait() failed\n");
                         return PTS_UNRESOLVED;
                 }
-               printf("Got it!  Parent\n");
-
+               if (sig == SIGALRM)
+                       printf("Got it!  Parent\n");
+               else
+                       printf("Got another signal! Parent\n");
 

How about this?

Best Regards
Yang Xu

Quoted 36 lines

Perhaps, you need to reset the behavior of SIGALRM to default if it is not default..

Thanks,
Xiao Yang

Quoted 29 lines

---
? .../functional/timers/timers/twoptimers.c???????????????????? | 4 ++-- ? 1 file changed, 2 insertions(+), 2 deletions(-)

(quoted diff) +0 -0

a/testcases/open_posix_testsuite/functional/timers/timers/twoptimers.c b/testcases/open_posix_testsuite/functional/timers/timers/twoptimers.c index 84bea3f0a..7e1648d5b 100644
---
a/testcases/open_posix_testsuite/functional/timers/timers/twoptimers.c
+++
b/testcases/open_posix_testsuite/functional/timers/timers/twoptimers.c

(quoted diff) +2 -2
@@ -92,13 +92,13 @@ int main(int argc, char *argv[])
 ????????????? return PTS_UNRESOLVED;
 ????????? }
 
-??????? if (sigaddset(&set, SIGALRM) == -1) {
+??????? if (sigaddset(&set, SIGILL) == -1) {
 ????????????? perror("sigaddset() failed\n");
 ????????????? return PTS_UNRESOLVED;
 ????????? }
 
 ????????? ev.sigev_notify = SIGEV_SIGNAL;
-??????? ev.sigev_signo = SIGALRM;
+??????? ev.sigev_signo = SIGILL;
 ????????? if (timer_create(CLOCK_REALTIME,&ev,&tid) != 0) {
 ????????????? perror("timer_create() did not return success\n");
 ????????????? return PTS_UNRESOLVED;
author
#3 lore raw

PATCH v2 1/1 openposix/twoptimers: handle signal correctly

In reply to Xiao Yang

Usually, when we want to get a signal to handle, we should install customized signal handler function by using sigation. The other way is to block this signal and use sigwait() to get the signal from its pending list. Use sigprocmask(SIGBLOCK, &set, NULL) to make sure we can get SIGABRT/SIGALRM signal.

Test this case on 2.6.18-398.el5, it doesn't get any signal. higer versions than this only get SIGABRT signal.

---
 .../functional/timers/timers/twoptimers.c     | 20 ++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
testcases/open_posix_testsuite/functional/timers/timers/twoptimers.c +17 -3
index 84bea3f0a..b2657539c 100644
@@ -51,6 +51,10 @@ int main(int argc, char *argv[])
 			return PTS_UNRESOLVED;
 		}
 
+		if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
+			perror("sigprocmask() failed\n");
+			return PTS_UNRESOLVED;
+		}
 		ev.sigev_notify = SIGEV_SIGNAL;
 		ev.sigev_signo = SIGABRT;
 		if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
@@ -73,8 +77,10 @@ int main(int argc, char *argv[])
 			perror("sigwait() failed\n");
 			return PTS_UNRESOLVED;
 		}
-		printf("Got it!  Child\n");
-
+		if (sig == SIGABRT)
+			printf("Got it! Child\n");
+		else
+			printf("Got another signal! Child\n");
 		sleep(LONGTIME);
 		return CHILDPASS;
 	} else {
@@ -97,6 +103,11 @@ int main(int argc, char *argv[])
 			return PTS_UNRESOLVED;
 		}
 
+		if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
+			perror("sigaprocmask() failed\n");
+			return PTS_UNRESOLVED;
+		}
+
 		ev.sigev_notify = SIGEV_SIGNAL;
 		ev.sigev_signo = SIGALRM;
 		if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
@@ -119,7 +130,10 @@ int main(int argc, char *argv[])
 			perror("sigwait() failed\n");
 			return PTS_UNRESOLVED;
 		}
-		printf("Got it!  Parent\n");
+		if (sig == SIGALRM)
+			printf("Got it! Parent\n");
+		else
+			printf("Got another signal! Parent\n");
 
 		if (wait(&i) == -1) {
 			perror("Error waiting for child to exit\n");
Signature · 1 line
2.23.0
#4 lore raw

PATCH v2 1/1 openposix/twoptimers: handle signal correctly

Hi!
I've also changed the code so that the test fails if we got wrong signal and removed the useless sleep() in the child and pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]