inotify: add x, o, and u events
No binary (build failed)
—
(log yok)
| @@ -1846,7 +1846,7 @@ | |
| "\nwith the parameters:" \ | |
| "\n1. actual event(s)" \ | |
| "\n2. file name" \ | |
| - | "\n3. name of subfile (if any), in case of watching a directory" \ |
| + | "\n3. name of subfile (if any)" \ |
| "\ninotifyd waits for agent to exit." \ | |
| "\nEvents:" \ | |
| "\n a File is accessed" \ | |
| @@ -1855,12 +1855,16 @@ | |
| "\n w Writtable file is closed" \ | |
| "\n 0 Unwrittable file is closed" \ | |
| "\n r File is opened" \ | |
| - | "\n m File is moved from X" \ |
| - | "\n y File is moved to Y" \ |
| + | "\n D File is deleted" \ |
| + | "\n M File is moved" \ |
| + | "\n u Backing fs is unmounted" \ |
| + | "\n o Event queue overflowed" \ |
| + | "\n x File can't be watched anymore" \ |
| + | "\nIf watching a directory:" \ |
| + | "\n m Subfile is moved into dir" \ |
| + | "\n y Subfile is moved out of dir" \ |
| "\n n Subfile is created" \ | |
| "\n d Subfile is deleted" \ | |
| - | "\n D Self is deleted" \ |
| - | "\n M Self is moved" \ |
| #define insmod_trivial_usage \ | |
| USE_FEATURE_2_4_MODULES("[OPTION]... ") "MODULE [symbol=value]..." | |
| @@ -43,7 +43,14 @@ static const char mask_names[] ALIGN1 = | |
| "d" // 0x00000200 Subfile was deleted | |
| "D" // 0x00000400 Self was deleted | |
| "M" // 0x00000800 Self was moved | |
| + | "\0" // 0x00001000 (unused) |
| + | "u" // 0x00002000 Backing fs was unmounted |
| + | "o" // 0x00004000 Event queued overflowed |
| + | "x" // 0x00008000 File is no longer watched (usually deleted) |
| ; | |
| + | enum { |
| + | MASK_BITS = sizeof(mask_names) - 1 |
| + | }; |
| extern int inotify_init(void); | |
| extern 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) | |
| // convert mask names to mask bitset | |
| mask = 0; | |
| while (*++masks) { | |
| - | int i = strchr(mask_names, *masks) - mask_names; |
| - | if (i >= 0) { |
| - | mask |= (1 << i); |
| - | } |
| + | const char *found; |
| + | found = memchr(mask_names, *masks, MASK_BITS); |
| + | if (found) |
| + | mask |= (1 << (found - mask_names)); |
| } | |
| } | |
| // add watch | |
| @@ -124,21 +131,23 @@ int inotifyd_main(int argc UNUSED_PARAM, char **argv) | |
| // process events. N.B. events may vary in length | |
| while (len > 0) { | |
| int i; | |
| - | char events[sizeof(mask_names)]; |
| - | char *s = events; |
| - | unsigned m = ie->mask; |
| - | |
| - | for (i = 0; i < sizeof(mask_names)-1; ++i, m >>= 1) { |
| - | if (m & 1) |
| - | *s++ = mask_names[i]; |
| + | // cache relevant events mask |
| + | unsigned m = ie->mask & ((1 << MASK_BITS) - 1); |
| + | if (m) { |
| + | char events[MASK_BITS + 1]; |
| + | char *s = events; |
| + | for (i = 0; i < MASK_BITS; ++i, m >>= 1) { |
| + | if ((m & 1) && (mask_names[i] != '\0')) |
| + | *s++ = mask_names[i]; |
| + | } |
| + | *s = '\0'; |
| + | // bb_error_msg("exec %s %08X\t%s\t%s\t%s", args[0], |
| + | // ie->mask, events, watched[ie->wd], ie->len ? ie->name : ""); |
| + | args[1] = events; |
| + | args[2] = watched[ie->wd]; |
| + | args[3] = ie->len ? ie->name : NULL; |
| + | wait4pid(xspawn((char **)args)); |
| } | |
| - | *s = '\0'; |
| - | //bb_error_msg("exec %s %08X\t%s\t%s\t%s", agent, |
| - | // ie->mask, events, watched[ie->wd], ie->len ? ie->name : ""); |
| - | args[1] = events; |
| - | args[2] = watched[ie->wd]; |
| - | args[3] = ie->len ? ie->name : NULL; |
| - | wait4pid(xspawn((char **)args)); |
| // next event | |
| i = sizeof(struct inotify_event) + ie->len; | |
| len -= i; | |