Skip to content

Commit

Permalink
Merge pull request #159 from flreinhard/fix-mqtt-inotify
Browse files Browse the repository at this point in the history
Current implementation missed motion events on GK-200MP2-B
  • Loading branch information
roleoroleo authored Dec 22, 2023
2 parents 4b85364 + 9e45ace commit 98256f5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/mqtt/mqtt-sonoff/src/inotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ static void handle_events(int fd)

event = (const struct inotify_event *) ptr;

/* Print event type. */

if (event->mask & IN_CREATE) {
/* Handle "File created", "Metadata change, e.g. Timestamp" and "File modified" evets */
if (event->mask & (IN_CREATE|IN_MODIFY|IN_ATTRIB)) {
/* Don't handle directories */
if ((event->mask & IN_ISDIR) != IN_ISDIR) {
/* Print the name of the file. */
/* Filename (event->name) length is gt 0 */
if (event->len) {
if (debug) fprintf(stderr, "IN_CREATE: %s\n", event->name);
if (strcmp(NOTI_FILE, event->name) == 0)
/* Is it the file to watch? */
if (strcmp(NOTI_FILE, event->name) == 0) {
if (debug) fprintf(stderr, "inotify: evt %08x on %s\n", event->mask, event->name);
handle_inotify_motion_start();
}
}
}
}
Expand All @@ -117,7 +119,7 @@ static void *inotify_thread(void *arg)
}

/* Add watch to the directory. */
wd = inotify_add_watch(fd, TMP_DIR, IN_CREATE);
wd = inotify_add_watch(fd, TMP_DIR, IN_CREATE|IN_MODIFY|IN_ATTRIB);
if (wd == -1) {
fprintf(stderr, "Cannot watch '%s': %s\n", TMP_DIR, strerror(errno));
return NULL;
Expand Down

0 comments on commit 98256f5

Please sign in to comment.