int getNotified(char *pathname1, char *pathname2){
int length, i = 0, fd, wd;
char buffer[EVENT_BUF_LEN];
fd = inotify_init();
wd1 = inotify_add_watch(fd, pathname1, IN_MODIFY);
wd2 = inotify_add_watch(fd, pathname2, 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(choose event triggered){
printf( "Pathname1 '%s' is modified.\n", event->name);
break;
}
else if(choose event triggered){
printf( "Pathname2 '%s' is modified.\n", event->name);
break;
}
}
}
i += EVENT_SIZE + event->len;
}
inotify_rm_watch(fd, wd1);
inotify_rm_watch(fd, wd2);
close(fd);
}
What I have tried:
In this code, I have two paths that are basically two directories. In these directories, I have two files (filename is same). I am watching these two directores at the same time. But when it comes to monitoring these files, I just want to put conditions in both paths that in which path, the event is triggered/watched.
It means that if the file1 is modified then it should give me the message of Pathname1 'filename' is modified. Similar to pathname2 but I don't know what to put in if condition?