1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/* Copyright (C) 2006-2025 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <intprops.h>
#include <support/check.h>
#include <support/support.h>
#include <support/xsignal.h>
#include <support/xunistd.h>
#include <support/xtime.h>
#include <stdlib.h>
static volatile int handler_called;
static void
handler (int sig)
{
handler_called = 1;
}
static void
test_pselect_basic (void)
{
struct sigaction sa;
sa.sa_handler = handler;
sa.sa_flags = 0;
sigemptyset (&sa.sa_mask);
xsigaction (SIGUSR1, &sa, NULL);
sa.sa_handler = SIG_IGN;
xsigaction (SIGCHLD, &sa, NULL);
sigset_t ss_usr1;
sigemptyset (&ss_usr1);
sigaddset (&ss_usr1, SIGUSR1);
TEST_COMPARE (sigprocmask (SIG_BLOCK, &ss_usr1, NULL), 0);
int fds[2][2];
xpipe (fds[0]);
xpipe (fds[1]);
fd_set rfds;
FD_ZERO (&rfds);
sigset_t ss;
TEST_COMPARE (sigprocmask (SIG_SETMASK, NULL, &ss), 0);
sigdelset (&ss, SIGUSR1);
struct timespec to = { .tv_sec = 0, .tv_nsec = 500000000 };
pid_t parent = getpid ();
pid_t p = xfork ();
if (p == 0)
{
xclose (fds[0][1]);
xclose (fds[1][0]);
FD_SET (fds[0][0], &rfds);
int e;
do
{
if (getppid () != parent)
FAIL_EXIT1 ("getppid()=%d != parent=%d", getppid(), parent);
errno = 0;
e = pselect (fds[0][0] + 1, &rfds, NULL, NULL, &to, &ss);
}
while (e == 0);
TEST_COMPARE (e, -1);
TEST_COMPARE (errno, EINTR);
TEMP_FAILURE_RETRY (write (fds[1][1], "foo", 3));
exit (0);
}
xclose (fds[0][0]);
xclose (fds[1][1]);
FD_SET (fds[1][0], &rfds);
TEST_COMPARE (kill (p, SIGUSR1), 0);
int e = pselect (fds[1][0] + 1, &rfds, NULL, NULL, NULL, &ss);
TEST_COMPARE (e, 1);
TEST_VERIFY (FD_ISSET (fds[1][0], &rfds));
}
static void
test_pselect_large_timeout (void)
{
support_create_timer (0, 100000000, false, NULL);
int fds[2];
xpipe (fds);
fd_set rfds;
FD_ZERO (&rfds);
FD_SET (fds[0], &rfds);
sigset_t ss;
TEST_COMPARE (sigprocmask (SIG_SETMASK, NULL, &ss), 0);
sigdelset (&ss, SIGALRM);
struct timespec ts = { TYPE_MAXIMUM (time_t), 0 };
TEST_COMPARE (pselect (fds[0] + 1, &rfds, NULL, NULL, &ts, &ss), -1);
TEST_VERIFY (errno == EINTR || errno == EOVERFLOW);
}
static int
do_test (void)
{
test_pselect_basic ();
test_pselect_large_timeout ();
return 0;
}
#include <support/test-driver.c>
|