1 | /* Check for large timeout with mq_timedsend and mq_timedreceive. |
2 | Copyright (C) 2021-2024 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <errno.h> |
20 | #include <intprops.h> |
21 | #include <mqueue.h> |
22 | #include <stdio.h> |
23 | #include <support/check.h> |
24 | #include <support/support.h> |
25 | #include <support/temp_file.h> |
26 | #include <unistd.h> |
27 | |
28 | static char name[sizeof "/tst-mqueue10-" + INT_BUFSIZE_BOUND (pid_t)]; |
29 | |
30 | static void |
31 | do_cleanup (void) |
32 | { |
33 | mq_unlink (name: name); |
34 | } |
35 | #define CLEANUP_HANDLER do_cleanup |
36 | |
37 | static int |
38 | do_test (void) |
39 | { |
40 | snprintf (s: name, maxlen: sizeof (name), format: "/tst-mqueue10-%u" , getpid ()); |
41 | |
42 | char msg[8] = { 0x55 }; |
43 | |
44 | struct mq_attr attr = { .mq_maxmsg = 1, .mq_msgsize = sizeof (msg) }; |
45 | mqd_t q = mq_open (name: name, O_CREAT | O_EXCL | O_RDWR, 0600, &attr); |
46 | |
47 | if (q == (mqd_t) -1) |
48 | { |
49 | if (errno == ENOSYS) |
50 | FAIL_UNSUPPORTED ("mq_open not supported" ); |
51 | |
52 | printf (format: "mq_open failed with: %m\n" ); |
53 | return 1; |
54 | } |
55 | |
56 | struct timespec ts = { TYPE_MAXIMUM (time_t), 0 }; |
57 | |
58 | { |
59 | timer_t timer = support_create_timer (sec: 0, nsec: 100000000, false, NULL); |
60 | TEST_COMPARE (mq_timedreceive (q, msg, sizeof (msg), NULL, &ts), -1); |
61 | TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); |
62 | support_delete_timer (timer); |
63 | } |
64 | |
65 | { |
66 | timer_t timer = support_create_timer (sec: 0, nsec: 100000000, false, NULL); |
67 | /* Fill the internal buffer first. */ |
68 | TEST_COMPARE (mq_timedsend (q, msg, sizeof (msg), 0, |
69 | &(struct timespec) { 0, 0 }), 0); |
70 | TEST_COMPARE (mq_timedsend (q, msg, sizeof (msg), 0, &ts), -1); |
71 | TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); |
72 | support_delete_timer (timer); |
73 | } |
74 | |
75 | mq_unlink (name: name); |
76 | |
77 | return 0; |
78 | } |
79 | |
80 | #include <support/test-driver.c> |
81 | |