mirror of
https://github.com/sheumann/hush.git
synced 2024-09-12 00:55:11 +00:00
inotify: add x, o, and u events
This commit is contained in:
parent
249d948e39
commit
a09a42cd83
@ -1846,7 +1846,7 @@
|
|||||||
"\nwith the parameters:" \
|
"\nwith the parameters:" \
|
||||||
"\n1. actual event(s)" \
|
"\n1. actual event(s)" \
|
||||||
"\n2. file name" \
|
"\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." \
|
"\ninotifyd waits for agent to exit." \
|
||||||
"\nEvents:" \
|
"\nEvents:" \
|
||||||
"\n a File is accessed" \
|
"\n a File is accessed" \
|
||||||
@ -1855,12 +1855,16 @@
|
|||||||
"\n w Writtable file is closed" \
|
"\n w Writtable file is closed" \
|
||||||
"\n 0 Unwrittable file is closed" \
|
"\n 0 Unwrittable file is closed" \
|
||||||
"\n r File is opened" \
|
"\n r File is opened" \
|
||||||
"\n m File is moved from X" \
|
"\n D File is deleted" \
|
||||||
"\n y File is moved to Y" \
|
"\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 n Subfile is created" \
|
||||||
"\n d Subfile is deleted" \
|
"\n d Subfile is deleted" \
|
||||||
"\n D Self is deleted" \
|
|
||||||
"\n M Self is moved" \
|
|
||||||
|
|
||||||
#define insmod_trivial_usage \
|
#define insmod_trivial_usage \
|
||||||
USE_FEATURE_2_4_MODULES("[OPTION]... ") "MODULE [symbol=value]..."
|
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" // 0x00000200 Subfile was deleted
|
||||||
"D" // 0x00000400 Self was deleted
|
"D" // 0x00000400 Self was deleted
|
||||||
"M" // 0x00000800 Self was moved
|
"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_init(void);
|
||||||
extern int inotify_add_watch(int fd, const char *path, uint32_t mask);
|
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
|
// convert mask names to mask bitset
|
||||||
mask = 0;
|
mask = 0;
|
||||||
while (*++masks) {
|
while (*++masks) {
|
||||||
int i = strchr(mask_names, *masks) - mask_names;
|
const char *found;
|
||||||
if (i >= 0) {
|
found = memchr(mask_names, *masks, MASK_BITS);
|
||||||
mask |= (1 << i);
|
if (found)
|
||||||
}
|
mask |= (1 << (found - mask_names));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// add watch
|
// add watch
|
||||||
@ -124,21 +131,23 @@ int inotifyd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
// process events. N.B. events may vary in length
|
// process events. N.B. events may vary in length
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
int i;
|
int i;
|
||||||
char events[sizeof(mask_names)];
|
// cache relevant events mask
|
||||||
|
unsigned m = ie->mask & ((1 << MASK_BITS) - 1);
|
||||||
|
if (m) {
|
||||||
|
char events[MASK_BITS + 1];
|
||||||
char *s = events;
|
char *s = events;
|
||||||
unsigned m = ie->mask;
|
for (i = 0; i < MASK_BITS; ++i, m >>= 1) {
|
||||||
|
if ((m & 1) && (mask_names[i] != '\0'))
|
||||||
for (i = 0; i < sizeof(mask_names)-1; ++i, m >>= 1) {
|
|
||||||
if (m & 1)
|
|
||||||
*s++ = mask_names[i];
|
*s++ = mask_names[i];
|
||||||
}
|
}
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
//bb_error_msg("exec %s %08X\t%s\t%s\t%s", agent,
|
// bb_error_msg("exec %s %08X\t%s\t%s\t%s", args[0],
|
||||||
// ie->mask, events, watched[ie->wd], ie->len ? ie->name : "");
|
// ie->mask, events, watched[ie->wd], ie->len ? ie->name : "");
|
||||||
args[1] = events;
|
args[1] = events;
|
||||||
args[2] = watched[ie->wd];
|
args[2] = watched[ie->wd];
|
||||||
args[3] = ie->len ? ie->name : NULL;
|
args[3] = ie->len ? ie->name : NULL;
|
||||||
wait4pid(xspawn((char **)args));
|
wait4pid(xspawn((char **)args));
|
||||||
|
}
|
||||||
// next event
|
// next event
|
||||||
i = sizeof(struct inotify_event) + ie->len;
|
i = sizeof(struct inotify_event) + ie->len;
|
||||||
len -= i;
|
len -= i;
|
||||||
|
Loading…
Reference in New Issue
Block a user