#define EVENT_SIZE (sizeof(struct inotify_event)) #define EVENT_BUF_LEN (1024 * (EVENT_SIZE + 16)) int main(){ int length, i = 0, fd, wd1, wd2; char buffer[EVENT_BUF_LEN]; fd = inotify_init(); wd1 = inotify_add_watch(fd, "/home/user/Documents", IN_MODIFY); wd2 = inotify_add_watch(fd, "/home/user/Desktop", IN_MODIFY); length = read(fd, buffer, EVENT_BUF_LEN ); while(i < length){ struct inotify_event *event = ( struct inotify_event *)&buffer[i]; if(event->len){ if(event->mask & IN_MODIFY){ if(event->wd1){ printf("Pathname1 file '%s' modified.\n",event->name); } if(event->wd2){ printf("Pathname2 file '%s' modified.\n",event->name); } } } i += EVENT_SIZE + event->len; } inotify_rm_watch(fd, wd1); inotify_rm_watch(fd, wd2); close(fd); }
error: use of undeclared identifier 'wd1'; did you mean 'wd'? error: use of undeclared identifier 'wd2'; did you mean 'wd1'? error: no member named 'wd1' in 'struct inotify_event'; did you mean 'wd'? error: no member named 'wd2' in 'struct inotify_event'; did you mean 'wd1'?
Quote:Note: Although I declared the same wd two times for two inotify_add_watch also but it still didn't solve the problem.
wd
if (event->wd == wd1) { // the event refers to pathname1 } else if (event->wd == wd2) { // the event refers to pathname2 } else { // this should not happen }
struct
inotify_event
if(event->wd1){ ... if(event->wd2){
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)