1*b7a2c575Schristos /* $NetBSD: h_inotify_init.c,v 1.1 2023/08/19 22:56:44 christos Exp $ */
2*b7a2c575Schristos
3*b7a2c575Schristos /*-
4*b7a2c575Schristos * Copyright (c) 2023 The NetBSD Foundation, Inc.
5*b7a2c575Schristos * All rights reserved.
6*b7a2c575Schristos *
7*b7a2c575Schristos * This code is derived from software contributed to The NetBSD Foundation
8*b7a2c575Schristos * by Theodore Preduta.
9*b7a2c575Schristos *
10*b7a2c575Schristos * Redistribution and use in source and binary forms, with or without
11*b7a2c575Schristos * modification, are permitted provided that the following conditions
12*b7a2c575Schristos * are met:
13*b7a2c575Schristos * 1. Redistributions of source code must retain the above copyright
14*b7a2c575Schristos * notice, this list of conditions and the following disclaimer.
15*b7a2c575Schristos * 2. Redistributions in binary form must reproduce the above copyright
16*b7a2c575Schristos * notice, this list of conditions and the following disclaimer in the
17*b7a2c575Schristos * documentation and/or other materials provided with the distribution.
18*b7a2c575Schristos *
19*b7a2c575Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*b7a2c575Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*b7a2c575Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*b7a2c575Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*b7a2c575Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*b7a2c575Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*b7a2c575Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*b7a2c575Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*b7a2c575Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*b7a2c575Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*b7a2c575Schristos * POSSIBILITY OF SUCH DAMAGE.
30*b7a2c575Schristos */
31*b7a2c575Schristos #include <sys/cdefs.h>
32*b7a2c575Schristos __RCSID("$NetBSD: h_inotify_init.c,v 1.1 2023/08/19 22:56:44 christos Exp $");
33*b7a2c575Schristos
34*b7a2c575Schristos #include "h_linux.h"
35*b7a2c575Schristos
36*b7a2c575Schristos #include <compat/linux/linux_syscall.h>
37*b7a2c575Schristos #include <compat/linux/common/linux_errno.h>
38*b7a2c575Schristos #include <compat/linux/common/linux_fcntl.h>
39*b7a2c575Schristos #include <compat/linux/common/linux_inotify.h>
40*b7a2c575Schristos
41*b7a2c575Schristos void
_start(void)42*b7a2c575Schristos _start(void)
43*b7a2c575Schristos {
44*b7a2c575Schristos int fd;
45*b7a2c575Schristos
46*b7a2c575Schristos /* Check that none of CLOEXEC or NONBLOCK are set. */
47*b7a2c575Schristos RS(fd = syscall(LINUX_SYS_inotify_init));
48*b7a2c575Schristos REQUIRE(fcntl(fd, LINUX_F_GETFD) == 0);
49*b7a2c575Schristos REQUIRE((fcntl(fd, LINUX_F_GETFL) & LINUX_O_NONBLOCK) == 0);
50*b7a2c575Schristos RS(close(fd));
51*b7a2c575Schristos
52*b7a2c575Schristos /* Check that only NONBLOCK is set. */
53*b7a2c575Schristos RS(fd = syscall(LINUX_SYS_inotify_init1, LINUX_IN_NONBLOCK));
54*b7a2c575Schristos REQUIRE(fcntl(fd, LINUX_F_GETFD) == 0);
55*b7a2c575Schristos REQUIRE((fcntl(fd, LINUX_F_GETFL) & LINUX_O_NONBLOCK) != 0);
56*b7a2c575Schristos RS(close(fd));
57*b7a2c575Schristos
58*b7a2c575Schristos /* Check that only CLOEXEC is set. */
59*b7a2c575Schristos RS(fd = syscall(LINUX_SYS_inotify_init1, LINUX_IN_CLOEXEC));
60*b7a2c575Schristos REQUIRE(fcntl(fd, LINUX_F_GETFD) != 0);
61*b7a2c575Schristos REQUIRE((fcntl(fd, LINUX_F_GETFL) & LINUX_O_NONBLOCK) == 0);
62*b7a2c575Schristos RS(close(fd));
63*b7a2c575Schristos
64*b7a2c575Schristos exit(0);
65*b7a2c575Schristos }
66