subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2007 SWSoft. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 20 | * with this program; if not, write the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 22 | * |
| 23 | * Started by Andrew Vagin <avagin@sw.ru> |
| 24 | * |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 25 | * DESCRIPTION |
| 26 | * Check that inotify work for a directory |
| 27 | * |
| 28 | * ALGORITHM |
| 29 | * Execute sequence file's operation and check return events |
Cyril Hrubis | 26aa0a8 | 2013-08-08 14:58:42 +0200 | [diff] [blame] | 30 | */ |
subrata_modak | c59422e | 2007-06-04 10:39:59 +0000 | [diff] [blame] | 31 | |
subrata_modak | 86faed4 | 2008-12-29 12:11:50 +0000 | [diff] [blame] | 32 | #include "config.h" |
| 33 | |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 34 | #include <stdio.h> |
| 35 | #include <sys/stat.h> |
| 36 | #include <sys/types.h> |
| 37 | #include <sys/fcntl.h> |
| 38 | #include <errno.h> |
| 39 | #include <string.h> |
subrata_modak | c59422e | 2007-06-04 10:39:59 +0000 | [diff] [blame] | 40 | #include <sys/syscall.h> |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 41 | #include "test.h" |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 42 | #include "linux_syscall_numbers.h" |
Garrett Cooper | 3bf3cb1 | 2012-05-20 10:51:55 -0700 | [diff] [blame] | 43 | #include "inotify.h" |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 44 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 45 | #if defined(HAVE_SYS_INOTIFY_H) |
subrata_modak | 3e9f094 | 2008-08-22 21:32:50 +0000 | [diff] [blame] | 46 | #include <sys/inotify.h> |
subrata_modak | c59422e | 2007-06-04 10:39:59 +0000 | [diff] [blame] | 47 | |
subrata_modak | 3d72679 | 2007-10-25 14:09:01 +0000 | [diff] [blame] | 48 | #ifndef IN_MOVE_SELF |
| 49 | #define IN_MOVE_SELF 0x00000800 |
| 50 | #endif |
| 51 | |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 52 | #define EVENT_MAX 1024 |
| 53 | /* size of the event structure, not counting name */ |
| 54 | #define EVENT_SIZE (sizeof (struct inotify_event)) |
| 55 | /* reasonable guess as to size of 1024 events */ |
| 56 | #define EVENT_BUF_LEN (EVENT_MAX * (EVENT_SIZE + 16)) |
| 57 | |
Cyril Hrubis | 26aa0a8 | 2013-08-08 14:58:42 +0200 | [diff] [blame] | 58 | static void setup(void); |
| 59 | static void cleanup(void); |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 60 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 61 | char *TCID = "inotify02"; |
| 62 | int TST_TOTAL = 9; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 63 | |
| 64 | #define BUF_SIZE 256 |
Cyril Hrubis | 26aa0a8 | 2013-08-08 14:58:42 +0200 | [diff] [blame] | 65 | static char fname1[BUF_SIZE], fname2[BUF_SIZE], fname3[BUF_SIZE]; |
Cyril Hrubis | 04f2177 | 2014-12-09 14:26:23 +0100 | [diff] [blame] | 66 | static int fd, fd_notify, reap_wd; |
Cyril Hrubis | 26aa0a8 | 2013-08-08 14:58:42 +0200 | [diff] [blame] | 67 | static int wd; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 68 | |
| 69 | struct event_t { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 70 | char name[BUF_SIZE]; |
Andrey Vagin | 6550b7a | 2014-09-10 14:00:53 +0400 | [diff] [blame] | 71 | unsigned int mask; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 72 | }; |
| 73 | #define FILE_NAME1 "test_file1" |
| 74 | #define FILE_NAME2 "test_file2" |
| 75 | |
Cyril Hrubis | 26aa0a8 | 2013-08-08 14:58:42 +0200 | [diff] [blame] | 76 | static struct event_t event_set[EVENT_MAX]; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 77 | |
Cyril Hrubis | 26aa0a8 | 2013-08-08 14:58:42 +0200 | [diff] [blame] | 78 | static char event_buf[EVENT_BUF_LEN]; |
vapier | 03b05a0 | 2008-04-07 18:33:46 +0000 | [diff] [blame] | 79 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 80 | int main(int ac, char **av) |
| 81 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 82 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 83 | const char *msg; |
Jan Kara | 1ea2821 | 2014-02-20 18:16:17 +0100 | [diff] [blame] | 84 | unsigned int stored_cookie = UINT_MAX; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 85 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 86 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 87 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 88 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 89 | setup(); |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 90 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 91 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 92 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 93 | tst_count = 0; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 94 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 95 | /* |
| 96 | * generate sequence of events |
| 97 | */ |
| 98 | if (chmod(".", 0755) < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 99 | tst_brkm(TBROK | TERRNO, cleanup, |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 100 | "chmod(\".\", 0755) failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 101 | } |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 102 | event_set[tst_count].mask = IN_ISDIR | IN_ATTRIB; |
| 103 | strcpy(event_set[tst_count].name, ""); |
| 104 | tst_count++; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 105 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 106 | if ((fd = creat(FILE_NAME1, 0755)) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 107 | tst_brkm(TBROK | TERRNO, cleanup, |
| 108 | "creat(\"%s\", 755) failed", FILE_NAME1); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 109 | } |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 110 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 111 | event_set[tst_count].mask = IN_CREATE; |
| 112 | strcpy(event_set[tst_count].name, FILE_NAME1); |
| 113 | tst_count++; |
| 114 | event_set[tst_count].mask = IN_OPEN; |
| 115 | strcpy(event_set[tst_count].name, FILE_NAME1); |
| 116 | tst_count++; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 117 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 118 | if (close(fd) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 119 | tst_brkm(TBROK | TERRNO, cleanup, |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 120 | "close(%s) failed", FILE_NAME1); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 121 | } |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 122 | event_set[tst_count].mask = IN_CLOSE_WRITE; |
| 123 | strcpy(event_set[tst_count].name, FILE_NAME1); |
| 124 | tst_count++; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 125 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 126 | if (rename(FILE_NAME1, FILE_NAME2) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 127 | tst_brkm(TBROK | TERRNO, cleanup, |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 128 | "rename(%s, %s) failed", |
| 129 | FILE_NAME1, FILE_NAME2); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 130 | } |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 131 | event_set[tst_count].mask = IN_MOVED_FROM; |
| 132 | strcpy(event_set[tst_count].name, FILE_NAME1); |
| 133 | tst_count++; |
| 134 | event_set[tst_count].mask = IN_MOVED_TO; |
| 135 | strcpy(event_set[tst_count].name, FILE_NAME2); |
| 136 | tst_count++; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 137 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 138 | if (getcwd(fname1, BUF_SIZE) == NULL) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 139 | tst_brkm(TBROK | TERRNO, cleanup, |
| 140 | "getcwd(%p, %d) failed", fname1, BUF_SIZE); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 141 | } |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 142 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 143 | snprintf(fname2, BUF_SIZE, "%s.rename1", fname1); |
| 144 | if (rename(fname1, fname2) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 145 | tst_brkm(TBROK | TERRNO, cleanup, |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 146 | "rename(%s, %s) failed", fname1, fname2); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 147 | } |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 148 | event_set[tst_count].mask = IN_MOVE_SELF; |
| 149 | strcpy(event_set[tst_count].name, ""); |
| 150 | tst_count++; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 151 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 152 | if (unlink(FILE_NAME2) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 153 | tst_brkm(TBROK | TERRNO, cleanup, |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 154 | "unlink(%s) failed", FILE_NAME2); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 155 | } |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 156 | event_set[tst_count].mask = IN_DELETE; |
| 157 | strcpy(event_set[tst_count].name, FILE_NAME2); |
| 158 | tst_count++; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 159 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 160 | /* |
| 161 | * test that duplicate events will be coalesced into |
| 162 | * a single event. This test case should be last, that |
| 163 | * we can correct determine kernel bug which exist before |
| 164 | * 2.6.25. See comment below. |
| 165 | */ |
| 166 | snprintf(fname3, BUF_SIZE, "%s.rename2", fname1); |
| 167 | if (rename(fname2, fname3) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 168 | tst_brkm(TBROK | TERRNO, cleanup, |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 169 | "rename(%s, %s) failed", fname2, fname3); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 170 | } |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 171 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 172 | if (rename(fname3, fname1) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 173 | tst_brkm(TBROK | TERRNO, cleanup, |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 174 | "rename(%s, %s) failed", fname3, fname1); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 175 | } |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 176 | event_set[tst_count].mask = IN_MOVE_SELF; |
| 177 | strcpy(event_set[tst_count].name, ""); |
| 178 | tst_count++; |
subrata_modak | 9a4c409 | 2008-03-28 08:28:50 +0000 | [diff] [blame] | 179 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 180 | if (tst_count != TST_TOTAL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 181 | tst_brkm(TBROK, cleanup, |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 182 | "tst_count and TST_TOTAL are not equal"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 183 | } |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 184 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 185 | tst_count = 0; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 186 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 187 | int len, i = 0, test_num = 0; |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 188 | if ((len = read(fd_notify, event_buf, EVENT_BUF_LEN)) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 189 | tst_brkm(TBROK | TERRNO, cleanup, |
Markos Chandras | f4539c6 | 2012-01-03 09:41:10 +0000 | [diff] [blame] | 190 | "read(%d, buf, %zu) failed", |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 191 | fd_notify, EVENT_BUF_LEN); |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 192 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 193 | } |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 194 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 195 | while (i < len) { |
| 196 | struct inotify_event *event; |
| 197 | event = (struct inotify_event *)&event_buf[i]; |
| 198 | if (test_num >= TST_TOTAL) { |
| 199 | if (tst_kvercmp(2, 6, 25) < 0 |
| 200 | && event_set[TST_TOTAL - 1].mask == |
| 201 | event->mask) |
| 202 | tst_resm(TWARN, |
| 203 | "This may be kernel bug. " |
| 204 | "Before kernel 2.6.25, a kernel bug " |
| 205 | "meant that the kernel code that was " |
| 206 | "intended to coalesce successive identical " |
| 207 | "events (i.e., the two most recent " |
| 208 | "events could potentially be coalesced " |
| 209 | "if the older had not yet been read) " |
| 210 | "instead checked if the most recent event " |
| 211 | "could be coalesced with the oldest " |
| 212 | "unread event. This has been fixed by commit" |
| 213 | "1c17d18e3775485bf1e0ce79575eb637a94494a2."); |
| 214 | tst_resm(TFAIL, |
| 215 | "get unnecessary event: " |
| 216 | "wd=%d mask=%x cookie=%u len=%u" |
Andrey Vagin | d1e94ff | 2014-09-11 18:18:12 +0400 | [diff] [blame] | 217 | "name=\"%.*s\"", event->wd, event->mask, |
| 218 | event->cookie, event->len, event->len, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 219 | event->name); |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 220 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 221 | } else if ((event_set[test_num].mask == event->mask) |
| 222 | && |
| 223 | (!strncmp |
| 224 | (event_set[test_num].name, event->name, |
| 225 | event->len))) { |
Jan Kara | 1ea2821 | 2014-02-20 18:16:17 +0100 | [diff] [blame] | 226 | int fail = 0; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 227 | |
Jan Kara | 1ea2821 | 2014-02-20 18:16:17 +0100 | [diff] [blame] | 228 | if (event->mask == IN_MOVED_FROM) { |
| 229 | if (event->cookie == 0) |
| 230 | fail = 1; |
| 231 | else |
| 232 | stored_cookie = event->cookie; |
| 233 | } else if (event->mask == IN_MOVED_TO) { |
| 234 | if (event->cookie != stored_cookie) |
| 235 | fail = 1; |
| 236 | else |
| 237 | stored_cookie = UINT_MAX; |
| 238 | } else { |
| 239 | if (event->cookie != 0) |
| 240 | fail = 1; |
| 241 | } |
| 242 | if (!fail) { |
| 243 | tst_resm(TPASS, |
| 244 | "get event: wd=%d mask=%x " |
Andrey Vagin | d1e94ff | 2014-09-11 18:18:12 +0400 | [diff] [blame] | 245 | "cookie=%u len=%u name=\"%.*s\"", |
Jan Kara | 1ea2821 | 2014-02-20 18:16:17 +0100 | [diff] [blame] | 246 | event->wd, event->mask, |
| 247 | event->cookie, event->len, |
Andrey Vagin | d1e94ff | 2014-09-11 18:18:12 +0400 | [diff] [blame] | 248 | event->len, event->name); |
Jan Kara | 1ea2821 | 2014-02-20 18:16:17 +0100 | [diff] [blame] | 249 | } else { |
| 250 | tst_resm(TFAIL, |
| 251 | "get event: wd=%d mask=%x " |
| 252 | "cookie=%u (wrong) len=%u " |
| 253 | "name=\"%s\"", |
| 254 | event->wd, event->mask, |
| 255 | event->cookie, event->len, |
| 256 | event->name); |
| 257 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 258 | } else { |
| 259 | tst_resm(TFAIL, "get event: wd=%d mask=%x " |
| 260 | "(expected %x) cookie=%u len=%u " |
| 261 | "name=\"%s\" (expected \"%s\") %d", |
| 262 | event->wd, event->mask, |
| 263 | event_set[test_num].mask, |
| 264 | event->cookie, event->len, event->name, |
| 265 | event_set[test_num].name, |
| 266 | strcmp(event_set[test_num].name, |
| 267 | event->name)); |
| 268 | } |
| 269 | test_num++; |
| 270 | i += EVENT_SIZE + event->len; |
| 271 | } |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 272 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 273 | for (; test_num < TST_TOTAL; test_num++) { |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 274 | tst_resm(TFAIL, "didn't get event: mask=%x ", |
| 275 | event_set[test_num].mask); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 276 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 277 | } |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 278 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 279 | cleanup(); |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 280 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 281 | } |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 282 | |
Cyril Hrubis | 26aa0a8 | 2013-08-08 14:58:42 +0200 | [diff] [blame] | 283 | static void setup(void) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 284 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 285 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 286 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 287 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 288 | TEST_PAUSE; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 289 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 290 | tst_tmpdir(); |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 291 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 292 | if ((fd_notify = myinotify_init()) < 0) { |
| 293 | if (errno == ENOSYS) { |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 294 | tst_brkm(TCONF, cleanup, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 295 | "inotify is not configured in this kernel."); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 296 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 297 | tst_brkm(TBROK | TERRNO, cleanup, |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 298 | "inotify_init () failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 299 | } |
| 300 | } |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 301 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 302 | if ((wd = myinotify_add_watch(fd_notify, ".", IN_ALL_EVENTS)) < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 303 | tst_brkm(TBROK | TERRNO, cleanup, |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 304 | "inotify_add_watch (%d, \".\", IN_ALL_EVENTS) failed", |
| 305 | fd_notify); |
Cyril Hrubis | 04f2177 | 2014-12-09 14:26:23 +0100 | [diff] [blame] | 306 | reap_wd = 1; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 307 | }; |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 308 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 309 | } |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 310 | |
Cyril Hrubis | 26aa0a8 | 2013-08-08 14:58:42 +0200 | [diff] [blame] | 311 | static void cleanup(void) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 312 | { |
Cyril Hrubis | 04f2177 | 2014-12-09 14:26:23 +0100 | [diff] [blame] | 313 | if (reap_wd && myinotify_rm_watch(fd_notify, wd) < 0) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 314 | tst_resm(TWARN, |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 315 | "inotify_rm_watch (%d, %d) failed,", fd_notify, wd); |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 316 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 317 | } |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 318 | |
Cyril Hrubis | 04f2177 | 2014-12-09 14:26:23 +0100 | [diff] [blame] | 319 | if (fd_notify > 0 && close(fd_notify)) |
Garrett Cooper | 766f33c | 2010-11-22 14:53:00 -0800 | [diff] [blame] | 320 | tst_resm(TWARN, "close(%d) failed", fd_notify); |
subrata_modak | 73e6ce7 | 2007-05-24 10:00:45 +0000 | [diff] [blame] | 321 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 322 | tst_rmdir(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 323 | } |
subrata_modak | c59422e | 2007-06-04 10:39:59 +0000 | [diff] [blame] | 324 | |
| 325 | #else |
| 326 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 327 | char *TCID = "inotify02"; |
| 328 | int TST_TOTAL = 0; |
subrata_modak | c59422e | 2007-06-04 10:39:59 +0000 | [diff] [blame] | 329 | |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 330 | int main(void) |
subrata_modak | c59422e | 2007-06-04 10:39:59 +0000 | [diff] [blame] | 331 | { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 332 | tst_brkm(TCONF, NULL, "system doesn't have required inotify support"); |
subrata_modak | c59422e | 2007-06-04 10:39:59 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Markos Chandras | f4539c6 | 2012-01-03 09:41:10 +0000 | [diff] [blame] | 335 | #endif |