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
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------------------
*
* Created: swmr_common.c
*
* Purpose: Utility functions for the SWMR test code.
*
*-------------------------------------------------------------------------
*/
/***********/
/* Headers */
/***********/
#include <err.h> /* for err(3) */
#include "h5test.h"
#include "vfd_swmr_common.h"
void
block_signals(sigset_t *oldset)
{
sigset_t fullset;
if (sigfillset(&fullset) == -1) {
err(EXIT_FAILURE, "%s.%d: could not initialize signal masks",
__func__, __LINE__);
}
if (sigprocmask(SIG_BLOCK, &fullset, oldset) == -1)
err(EXIT_FAILURE, "%s.%d: sigprocmask", __func__, __LINE__);
}
void
restore_signals(sigset_t *oldset)
{
if (sigprocmask(SIG_SETMASK, oldset, NULL) == -1)
err(EXIT_FAILURE, "%s.%d: sigprocmask", __func__, __LINE__);
}
void
await_signal(hid_t fid)
{
sigset_t sleepset;
struct timespec tick = {.tv_sec = 0, .tv_nsec = 1000000000 / 100};
if (sigemptyset(&sleepset) == -1 ||
sigaddset(&sleepset, SIGUSR1) == -1) {
err(EXIT_FAILURE, "%s.%d: could not initialize signal masks",
__func__, __LINE__);
}
for (;;) {
const int rc = sigtimedwait(&sleepset, NULL, &tick);
if (rc == SIGUSR1) {
printf("Cancelled by SIGUSR1.\n");
break;
} else if (rc == -1 && errno == EAGAIN) {
H5E_auto_t efunc;
void *edata;
(void)H5Eget_auto(H5E_DEFAULT, &efunc, &edata);
(void)H5Eset_auto(H5E_DEFAULT, NULL, NULL);
(void)H5Aexists_by_name(fid, "nonexistent", "nonexistent",
H5P_DEFAULT);
(void)H5Eset_auto(H5E_DEFAULT, efunc, edata);
} else if (rc == -1)
err(EXIT_FAILURE, "%s: sigtimedwait", __func__);
}
}
|