Click here to Skip to main content
14,982,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 4-Feb-21 6:10am

1 solution

The watch identifier (event->wd) should identify which one it is. See inotify(7) - Linux manual page[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900