aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/usage.h14
-rw-r--r--miscutils/inotifyd.c45
2 files changed, 36 insertions, 23 deletions
diff --git a/include/usage.h b/include/usage.h
index 67b2acf72..9c0c9d761 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1846,7 +1846,7 @@
1846 "\nwith the parameters:" \ 1846 "\nwith the parameters:" \
1847 "\n1. actual event(s)" \ 1847 "\n1. actual event(s)" \
1848 "\n2. file name" \ 1848 "\n2. file name" \
1849 "\n3. name of subfile (if any), in case of watching a directory" \ 1849 "\n3. name of subfile (if any)" \
1850 "\ninotifyd waits for agent to exit." \ 1850 "\ninotifyd waits for agent to exit." \
1851 "\nEvents:" \ 1851 "\nEvents:" \
1852 "\n a File is accessed" \ 1852 "\n a File is accessed" \
@@ -1855,12 +1855,16 @@
1855 "\n w Writtable file is closed" \ 1855 "\n w Writtable file is closed" \
1856 "\n 0 Unwrittable file is closed" \ 1856 "\n 0 Unwrittable file is closed" \
1857 "\n r File is opened" \ 1857 "\n r File is opened" \
1858 "\n m File is moved from X" \ 1858 "\n D File is deleted" \
1859 "\n y File is moved to Y" \ 1859 "\n M File is moved" \
1860 "\n u Backing fs is unmounted" \
1861 "\n o Event queue overflowed" \
1862 "\n x File can't be watched anymore" \
1863 "\nIf watching a directory:" \
1864 "\n m Subfile is moved into dir" \
1865 "\n y Subfile is moved out of dir" \
1860 "\n n Subfile is created" \ 1866 "\n n Subfile is created" \
1861 "\n d Subfile is deleted" \ 1867 "\n d Subfile is deleted" \
1862 "\n D Self is deleted" \
1863 "\n M Self is moved" \
1864 1868
1865#define insmod_trivial_usage \ 1869#define insmod_trivial_usage \
1866 USE_FEATURE_2_4_MODULES("[OPTION]... ") "MODULE [symbol=value]..." 1870 USE_FEATURE_2_4_MODULES("[OPTION]... ") "MODULE [symbol=value]..."
diff --git a/miscutils/inotifyd.c b/miscutils/inotifyd.c
index 2a1355156..656510453 100644
--- a/miscutils/inotifyd.c
+++ b/miscutils/inotifyd.c
@@ -43,7 +43,14 @@ static const char mask_names[] ALIGN1 =
43 "d" // 0x00000200 Subfile was deleted 43 "d" // 0x00000200 Subfile was deleted
44 "D" // 0x00000400 Self was deleted 44 "D" // 0x00000400 Self was deleted
45 "M" // 0x00000800 Self was moved 45 "M" // 0x00000800 Self was moved
46 "\0" // 0x00001000 (unused)
47 "u" // 0x00002000 Backing fs was unmounted
48 "o" // 0x00004000 Event queued overflowed
49 "x" // 0x00008000 File is no longer watched (usually deleted)
46; 50;
51enum {
52 MASK_BITS = sizeof(mask_names) - 1
53};
47 54
48extern int inotify_init(void); 55extern int inotify_init(void);
49extern int inotify_add_watch(int fd, const char *path, uint32_t mask); 56extern int inotify_add_watch(int fd, const char *path, uint32_t mask);
@@ -76,10 +83,10 @@ int inotifyd_main(int argc UNUSED_PARAM, char **argv)
76 // convert mask names to mask bitset 83 // convert mask names to mask bitset
77 mask = 0; 84 mask = 0;
78 while (*++masks) { 85 while (*++masks) {
79 int i = strchr(mask_names, *masks) - mask_names; 86 const char *found;
80 if (i >= 0) { 87 found = memchr(mask_names, *masks, MASK_BITS);
81 mask |= (1 << i); 88 if (found)
82 } 89 mask |= (1 << (found - mask_names));
83 } 90 }
84 } 91 }
85 // add watch 92 // add watch
@@ -124,21 +131,23 @@ int inotifyd_main(int argc UNUSED_PARAM, char **argv)
124 // process events. N.B. events may vary in length 131 // process events. N.B. events may vary in length
125 while (len > 0) { 132 while (len > 0) {
126 int i; 133 int i;
127 char events[sizeof(mask_names)]; 134 // cache relevant events mask
128 char *s = events; 135 unsigned m = ie->mask & ((1 << MASK_BITS) - 1);
129 unsigned m = ie->mask; 136 if (m) {
130 137 char events[MASK_BITS + 1];
131 for (i = 0; i < sizeof(mask_names)-1; ++i, m >>= 1) { 138 char *s = events;
132 if (m & 1) 139 for (i = 0; i < MASK_BITS; ++i, m >>= 1) {
133 *s++ = mask_names[i]; 140 if ((m & 1) && (mask_names[i] != '\0'))
141 *s++ = mask_names[i];
142 }
143 *s = '\0';
144// bb_error_msg("exec %s %08X\t%s\t%s\t%s", args[0],
145// ie->mask, events, watched[ie->wd], ie->len ? ie->name : "");
146 args[1] = events;
147 args[2] = watched[ie->wd];
148 args[3] = ie->len ? ie->name : NULL;
149 wait4pid(xspawn((char **)args));
134 } 150 }
135 *s = '\0';
136 //bb_error_msg("exec %s %08X\t%s\t%s\t%s", agent,
137 // ie->mask, events, watched[ie->wd], ie->len ? ie->name : "");
138 args[1] = events;
139 args[2] = watched[ie->wd];
140 args[3] = ie->len ? ie->name : NULL;
141 wait4pid(xspawn((char **)args));
142 // next event 151 // next event
143 i = sizeof(struct inotify_event) + ie->len; 152 i = sizeof(struct inotify_event) + ie->len;
144 len -= i; 153 len -= i;