1 /******************************************************************************/
2 /* */
3 /* Copyright (c) Ulrich Drepper <drepper@redhat.com> */
4 /* Copyright (c) International Business Machines Corp., 2009 */
5 /* */
6 /* This program is free software; you can redistribute it and/or modify */
7 /* it under the terms of the GNU General Public License as published by */
8 /* the Free Software Foundation; either version 2 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* This program is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
14 /* the GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with this program; if not, write to the Free Software */
18 /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
19 /* */
20 /******************************************************************************/
21 /******************************************************************************/
22 /* */
23 /* File: inotify_init1_01.c */
24 /* */
25 /* Description: This Program tests the new system call introduced in 2.6.27. */
26 /* Ulrich´s comment as in: */
27 /* http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=4006553b06306b34054529477b06b68a1c66249b */
28 /* says: */
29 /* This patch introduces the new syscall inotify_init1 (note: the 1 stands for*/
30 /* the one parameter the syscall takes, as opposed to no parameter before). */
31 /* The values accepted for this parameter are function-specific and defined in*/
32 /* the inotify.h header. Here the values must match the O_* flags, though. */
33 /* In this patch CLOEXEC support is introduced. */
34 /* The following test must be adjusted for architectures other */
35 /* than x86 and x86-64 and in case the syscall numbers changed. */
36 /* */
37 /* Usage: <for command-line> */
38 /* inotify_init1_01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
39 /* where, -c n : Run n copies concurrently. */
40 /* -e : Turn on errno logging. */
41 /* -i n : Execute test n times. */
42 /* -I x : Execute test for x seconds. */
43 /* -P x : Pause for x seconds between iterations. */
44 /* -t : Turn on syscall timing. */
45 /* */
46 /* Total Tests: 1 */
47 /* */
48 /* Test Name: inotify_init1_01 */
49 /* */
50 /* Author: Ulrich Drepper <drepper@redhat.com> */
51 /* */
52 /* History: Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com> */
53 /* Ported to LTP */
54 /* - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com> */
55 /******************************************************************************/
56 #include <stdio.h>
57 #include <unistd.h>
58 #include <sys/syscall.h>
59 #include <errno.h>
60
61 #include "test.h"
62 #include "lapi/fcntl.h"
63 #include "lapi/syscalls.h"
64
65 #define IN_CLOEXEC O_CLOEXEC
66
67 char *TCID = "inotify_init1_01";
68 int testno;
69 int TST_TOTAL = 1;
70
71 /* Extern Global Functions */
72 /******************************************************************************/
73 /* */
74 /* Function: cleanup */
75 /* */
76 /* Description: Performs all one time clean up for this test on successful */
77 /* completion, premature exit or failure. Closes all temporary */
78 /* files, removes all temporary directories exits the test with */
79 /* appropriate return code by calling tst_exit() function. */
80 /* */
81 /* Input: None. */
82 /* */
83 /* Output: None. */
84 /* */
85 /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
86 /* On success - Exits calling tst_exit(). With '0' return code. */
87 /* */
88 /******************************************************************************/
cleanup(void)89 void cleanup(void)
90 {
91
92 tst_rmdir();
93 }
94
95 /* Local Functions */
96 /******************************************************************************/
97 /* */
98 /* Function: setup */
99 /* */
100 /* Description: Performs all one time setup for this test. This function is */
101 /* typically used to capture signals, create temporary dirs */
102 /* and temporary files that may be used in the course of this */
103 /* test. */
104 /* */
105 /* Input: None. */
106 /* */
107 /* Output: None. */
108 /* */
109 /* Return: On failure - Exits by calling cleanup(). */
110 /* On success - returns 0. */
111 /* */
112 /******************************************************************************/
setup(void)113 void setup(void)
114 {
115 /* Capture signals if any */
116 /* Create temporary directories */
117 TEST_PAUSE;
118 tst_tmpdir();
119 }
120
main(int argc,char * argv[])121 int main(int argc, char *argv[])
122 {
123 int fd, coe;
124 int lc;
125
126 tst_parse_opts(argc, argv, NULL, NULL);
127
128 if ((tst_kvercmp(2, 6, 27)) < 0) {
129 tst_brkm(TCONF, NULL,
130 "This test can only run on kernels that are 2.6.27 "
131 "and higher");
132 }
133 setup();
134
135 for (lc = 0; TEST_LOOPING(lc); ++lc) {
136 tst_count = 0;
137 for (testno = 0; testno < TST_TOTAL; ++testno) {
138 fd = ltp_syscall(__NR_inotify_init1, 0);
139 if (fd == -1) {
140 tst_brkm(TFAIL | TERRNO, cleanup,
141 "inotify_init1(0) failed");
142 }
143 coe = fcntl(fd, F_GETFD);
144 if (coe == -1) {
145 tst_brkm(TBROK | TERRNO, cleanup,
146 "fcntl failed");
147 }
148 if (coe & FD_CLOEXEC) {
149 tst_brkm(TFAIL, cleanup,
150 "inotify_init1(0) set close-on-exit");
151 }
152 close(fd);
153
154 fd = ltp_syscall(__NR_inotify_init1, IN_CLOEXEC);
155 if (fd == -1) {
156 tst_brkm(TFAIL | TERRNO, cleanup,
157 "inotify_init1(IN_CLOEXEC) failed");
158 }
159 coe = fcntl(fd, F_GETFD);
160 if (coe == -1) {
161 tst_resm(TBROK | TERRNO, "fcntl failed");
162 } else if ((coe & FD_CLOEXEC) == 0) {
163 tst_resm(TFAIL,
164 "inotify_init1(O_CLOEXEC) did not "
165 "set close-on-exit");
166 } else {
167 close(fd);
168 tst_resm(TPASS, "inotify_init1(O_CLOEXEC) "
169 "PASSED");
170 }
171 }
172 }
173 tst_exit();
174 cleanup();
175 }
176