Welcome to mirror list, hosted at ThFree Co, Russian Federation.

checksignal.c « winsup.api « testsuite « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: edf720c8781fb74385a9503db1781c5bd51fc792 (plain)
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
#include <errno.h>
#include <signal.h>

#include "test.h"
#include "usctest.h"

const char *TCID = "checksignal";    	/* Test program identifier. */
int TST_TOTAL = 3;              /* Total number of test cases. */
extern int Tst_count;           /* Test Case counter for tst_* routines */

void
sig_handler (int signo)
{
  errno = EINVAL;
}

int
main ()
{
  int n, ret;
  int fds[2];
  char buf[10];
  struct sigaction act;

  Tst_count = 0;

  if (pipe (fds) < 0)
    tst_brk (TBROK, NULL, NULL, "Create pipe");

  /* Reset SA_RESTART flag. */
  while ((ret = sigaction (SIGALRM, NULL, &act)) == EINTR)
    ;
  if (ret)
    tst_brk (TBROK, NULL, NULL, "Get signal action structure");
  act.sa_flags &= ~SA_RESTART;
  while ((ret = sigaction (SIGALRM, &act, NULL)) == EINTR)
    ;
  if (ret)
    tst_brk (TBROK, NULL, NULL, "Reset SA_RESTART");

  /* Set signal handler using signal(2) call... */
  if (signal (SIGALRM, sig_handler) < 0)
    tst_brk (TBROK, NULL, NULL, "Call signal() to install signal handler");
  /* ...and check if signal(2) sets SA_RESTART again. */
  while ((ret = sigaction (SIGALRM, NULL, &act)) == EINTR)
    ;
  if (ret)
    tst_brk (TBROK, NULL, NULL, "Get signal action structure");
  tst_resm (act.sa_flags & SA_RESTART ? TPASS : TFAIL,
	    "signal() sets SA_RESTART");

  /* Reset SA_RESTART flag again. */
  act.sa_handler = sig_handler;
  act.sa_flags &= ~SA_RESTART;
  while ((ret = sigaction (SIGALRM, &act, NULL)) == EINTR)
    ;
  if (ret)
    tst_brk (TBROK, NULL, NULL, "Reset SA_RESTART");

  /* Start timer to force a SIGALRM. */
  alarm (1);

  /* Call read(2) to check if the EINTR errno is correctly preserved,
     even if the signal handler routine changes errno. */
  n = read(fds[0], buf, 10);
  tst_resm (n < 0 && errno == EINTR ? TPASS : TFAIL,
	    "Set EINTR on interrupted read() call");

  /* Check if another errno is correctly returned (here EBADF). */
  close (fds[0]);
  n = read(fds[0], buf, 10);
  tst_resm (n < 0 && errno == EBADF ? TPASS : TFAIL,
  	    "Set EBADF on closed file descriptor");

  tst_exit ();
}