Skip to contentSkip to conversation

mq_timedreceive/5-3: Prevent override of errno

PATCH New Joerg Vehlow 2 participants 4 messages Feb 3, 2021 – Feb 12, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mq_timedreceive/5-3: Prevent override of errno

From: Joerg Vehlow <[email protected]>

wait can override the errno set by mq_timedreceive and the check for EINTR might fail or not fail if it should.

---
 .../conformance/interfaces/mq_timedreceive/5-3.c           | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/5-3.c +4 -3
index e773aeb14..3f252a196 100644
@@ -74,16 +74,17 @@ int main(void)
 		ts.tv_nsec = 0;
 
 		if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) == -1) {
-			wait(NULL);
 			if (EINTR != errno) {
 				printf("errno != EINTR\n");
 				failure = 1;
 			}
 		} else {
-			wait(NULL);
-			printf("mq_timedreceive() succeed unexpectly\n");
+			printf("mq_timedreceive() succeeded unexpectedly\n");
 			failure = 1;
 		}
+		
+		wait(NULL);
+
 		if (mq_close(mqdes) != 0) {
 			perror("mq_close() did not return success");
 			unresolved = 1;
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 mq_timedreceive_5-3: Fix test for timestamp after INT32_MAX

From: Joerg Vehlow <[email protected]>

The timeout for mq_timedreceive is absolute. Using INT32_MAX breaks this test after 2038-01-19.

---
 .../conformance/interfaces/mq_timedreceive/5-3.c               | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/5-3.c +2 -1
index 3f252a196..89d40721e 100644
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <time.h>
 #include "posixtest.h"
 
 #define TEST "5-3"
@@ -70,7 +71,7 @@ int main(void)
 		sigemptyset(&act.sa_mask);
 		sigaction(SIGABRT, &act, 0);
 
-		ts.tv_sec = INT32_MAX;
+		ts.tv_sec = time(NULL) + 5;
 		ts.tv_nsec = 0;
 
 		if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) == -1) {
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 mq_timedreceive_5-3: Fix test for timestamp after INT32_MAX

Just FYI:

Quoted 4 lines · Joerg Vehlow

From: Joerg Vehlow <[email protected]>

The timeout for mq_timedreceive is absolute. Using INT32_MAX breaks this test after 2038-01-19.

Funny thing is, that the other bug fixed in the first patch hid this bug. mq_timedreceive returned with ETIMEDOUT immediately, but wait blocked, until it was interrupted by the signal -> erno was EINTR and the test passed.

J?rg

#3 lore raw

PATCH 2/2 mq_timedreceive_5-3: Fix test for timestamp after INT32_MAX

Hi!
Good catch, I've removed trailing whitespaces from the first patch and pushed both, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]