1 |
|
---|
2 |
|
---|
3 | /*******************************************************************************
|
---|
4 | * Header Files *
|
---|
5 | *******************************************************************************/
|
---|
6 | //#define _XOPEN_SOURCE
|
---|
7 | //#define _BSD_SOURCE
|
---|
8 | #include <sys/time.h>
|
---|
9 | #include <sys/stat.h>
|
---|
10 | #include <stdio.h>
|
---|
11 | #include <signal.h>
|
---|
12 | #include <string.h>
|
---|
13 | #include <errno.h>
|
---|
14 |
|
---|
15 |
|
---|
16 | volatile unsigned long g_cInts = 0;
|
---|
17 |
|
---|
18 | static void SigAlaramHandler(int iSig)
|
---|
19 | {
|
---|
20 | g_cInts++;
|
---|
21 | (void)iSig;
|
---|
22 | }
|
---|
23 |
|
---|
24 |
|
---|
25 | int main(int argc, char **argv)
|
---|
26 | {
|
---|
27 | struct itimerval TmrVal;
|
---|
28 | void (*rcSig)(int);
|
---|
29 | int i;
|
---|
30 | int rc;
|
---|
31 | char szName[256];
|
---|
32 |
|
---|
33 | /*
|
---|
34 | * Set up the timer signal.
|
---|
35 | */
|
---|
36 | rcSig = bsd_signal(SIGALRM, SigAlaramHandler);
|
---|
37 | if (rcSig == SIG_ERR)
|
---|
38 | {
|
---|
39 | fprintf(stderr, "bsd_signal failed: %s\n", strerror(errno));
|
---|
40 | return 1;
|
---|
41 | }
|
---|
42 | if (argc == 2) /* testing... */
|
---|
43 | siginterrupt(SIGALRM, 1);
|
---|
44 |
|
---|
45 | memset(&TmrVal, '\0', sizeof(TmrVal));
|
---|
46 | TmrVal.it_interval.tv_sec = TmrVal.it_value.tv_sec = 0;
|
---|
47 | TmrVal.it_interval.tv_usec = TmrVal.it_value.tv_usec = 1;
|
---|
48 | rc = setitimer(ITIMER_REAL, &TmrVal, NULL);
|
---|
49 | if (rc != 0)
|
---|
50 | {
|
---|
51 | fprintf(stderr, "setitimer failed: %s\n", strerror(errno));
|
---|
52 | return 1;
|
---|
53 | }
|
---|
54 | printf("interval %d.%06d\n", (int)TmrVal.it_interval.tv_sec, (int)TmrVal.it_interval.tv_usec);
|
---|
55 |
|
---|
56 | /*
|
---|
57 | * Do path related stuff.
|
---|
58 | */
|
---|
59 | snprintf(szName, sizeof(szName), "%s/fooled/you", argv[0]);
|
---|
60 | for (i = 0; i < 100*1000*1000; i++)
|
---|
61 | {
|
---|
62 | struct stat St;
|
---|
63 | rc = stat(argv[0], &St);
|
---|
64 | if (rc == 0)
|
---|
65 | rc = stat(szName, &St);
|
---|
66 | if (rc != 0 && errno == EINTR)
|
---|
67 | {
|
---|
68 | printf("iteration %d: stat: %s (%u)\n", i, strerror(errno), errno);
|
---|
69 | break;
|
---|
70 | }
|
---|
71 | if ((i % 100000) == 0)
|
---|
72 | {
|
---|
73 | printf(".");
|
---|
74 | if ((i % 1000000) == 0)
|
---|
75 | printf("[%u/%lu]", i, g_cInts);
|
---|
76 | fflush(stdout);
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | if (!rc)
|
---|
81 | printf("No EINTR in %d iterations - system is working nicely!\n", i);
|
---|
82 |
|
---|
83 | TmrVal.it_interval.tv_sec = TmrVal.it_value.tv_sec = 0;
|
---|
84 | TmrVal.it_interval.tv_usec = TmrVal.it_value.tv_usec = 0;
|
---|
85 | setitimer(ITIMER_REAL, &TmrVal, NULL);
|
---|
86 |
|
---|
87 | return rc ? 1 : 0;
|
---|
88 | }
|
---|
89 |
|
---|