sleepy_penguin.git  about / heads / tags
Linux I/O events for Ruby
blob e22250e2aa59b646d367ba21958c5f557d38b3f9 1176 bytes (raw)
$ git show pu:ext/sleepy_penguin/missing_inotify.h	# shows this blob on the CLI

 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
 
#ifndef IN_CLOEXEC
#  define IN_CLOEXEC 02000000
#endif
#ifndef IN_NONBLOCK
#  define IN_NONBLOCK O_NONBLOCK
#endif
#ifndef IN_ATTRIB
#  define IN_ATTRIB 0x00000004
#endif
#ifndef IN_ONLYDIR
#  define IN_ONLYDIR 0x01000000
#endif
#ifndef IN_DONT_FOLLOW
#  define IN_DONT_FOLLOW 0x02000000
#endif
#ifndef IN_EXCL_UNLINK
#  define IN_EXCL_UNLINK 0x04000000
#endif
#ifndef IN_MASK_ADD
#  define IN_MASK_ADD 0x20000000
#endif
#ifndef IN_ONESHOT
#  define IN_ONESHOT 0x80000000
#endif

#ifndef HAVE_INOTIFY_INIT1
/*
 * fake inotify_init1() since some systems don't have it
 * Don't worry about thread-safety since current Ruby 1.9 won't
 * call this without GVL.
 */
static int my_inotify_init1(int flags)
{
	int fd = inotify_init();
	int tmp;

	if (fd < 0)
		return fd;
	if ((flags & IN_CLOEXEC) && (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0))
		goto fcntl_err;
	if (flags & IN_NONBLOCK) {
		tmp = fcntl(fd, F_GETFL);
		if (tmp == -1)
			goto fcntl_err;
		if ((fcntl(fd, F_SETFL, tmp | O_NONBLOCK) < 0))
			goto fcntl_err;
	}

	return fd;
fcntl_err:
	tmp = errno;
	close(fd);
	errno = tmp;
	rb_sys_fail("fcntl");
}
# define inotify_init1 my_inotify_init1
#endif /* HAVE_INOTIFY_INIT1 */

git clone https://yhbt.net/sleepy_penguin.git