#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

void handler(int fd, siginfo_t * siginfo, void * data)
{
	printf("received signal\n");
}

int main(int argc, char **argv)
{
	int fd, error;
	struct sigaction sig;
	
	sig.sa_sigaction = handler;
	sigemptyset(&sig.sa_mask);
	sig.sa_flags = SA_SIGINFO;

	error = sigaction(SIGIO, &sig, NULL);
	if (error < 0)
		goto out;

	fd = open(argv[1], O_RDONLY);
	if (fd < 0)
		goto out;

	error = fcntl(fd, F_SETOWN, getpid());
	if (error < 0)
		goto out;

	error = fcntl(fd, F_SETFL, O_ASYNC);
	if (error < 0)
		goto out;

	for(;;) ;
out:
	perror("dirnot");
	return 1;
}
