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
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* 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 files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* crasher HDF5 API module of the trecover test program.
*
* Creator: Albert Cheng, Jan 28, 2008.
*/
#include "trecover.h"
/* Crasher
* Two crash modes:
* SyncCrash: will now at once;
* AsyncCrash: schedule a crash to occur in the future in the asynchronous
* fashion.
* Crash_param: used by AsyncCrash mode and ignored by SyncCrash mode.
*/
void
crasher(int crash_mode, CrasherParam_t *crash_param)
{
float fraction, integral;
struct itimerval old, new;
switch (crash_mode) {
case SyncCrash:
_exit(0);
break;
case AsyncCrash:
/* Setup a wakeup call in the future */
signal(SIGALRM, wakeup);
fraction = modff(crash_param->tinterval, &integral);
new.it_interval.tv_usec = 0;
new.it_interval.tv_sec = 0;
new.it_value.tv_usec = fraction * 1.0e6;
new.it_value.tv_sec = integral;
setitimer(ITIMER_REAL, &new, &old);
break;
default:
fprintf(stderr, "Unknown Crash Mode (%d)\n", crash_mode);
break;
}
}
void wakeup(int signum)
{
printf("wakeup, call sync crash\n");
/* call crasher with sync mode */
crasher(SyncCrash, 0);
}
|