blob: e38a74212c5e628508f087876a41453d5e078fdb (
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
|
/***********************************************************************/
/* */
/* Objective Caml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 1996 Institut National de Recherche en Informatique et */
/* Automatique. Distributed only by permission. */
/* */
/***********************************************************************/
/* $Id$ */
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include "s.h"
int signalled;
void sigio_handler(arg)
int arg;
{
signalled = 1;
}
int main()
{
#if defined(SIGIO) && defined(FASYNC) && defined(F_SETFL) && defined(F_SETOWN)
int p[2];
int ret;
#define OUT 0
#define IN 1
if (pipe(p) == -1) return 1;
signalled = 0;
signal(SIGIO, sigio_handler);
ret = fcntl(p[OUT], F_GETFL, 0);
fcntl(p[OUT], F_SETFL, ret | FASYNC);
fcntl(p[OUT], F_SETOWN, getpid());
switch(fork()) {
case -1:
return 1;
case 0:
close(p[OUT]);
write(p[IN], "x", 1);
sleep(1);
exit(0);
default:
close(p[IN]);
while(wait(NULL) == -1 && errno == EINTR) /*nothing*/;
}
if (signalled) return 0; else return 1;
#else
return 1;
#endif
}
|