Merge pull request #150 from mdiluz/fix-inotify

inotify fix
This commit is contained in:
Alex Smith 2019-05-29 15:36:19 +01:00 committed by GitHub
commit 7ebe633026

View File

@ -374,7 +374,7 @@ static void load_config_files(GameModeConfig *self)
/* Register for inotify */ /* Register for inotify */
/* Watch for modification, deletion, moves, or attribute changes */ /* Watch for modification, deletion, moves, or attribute changes */
uint32_t fileflags = IN_MODIFY | IN_DELETE_SELF | IN_MOVE_SELF | IN_ATTRIB; uint32_t fileflags = IN_MODIFY | IN_DELETE_SELF | IN_MOVE_SELF;
if ((self->inotwd[i] = inotify_add_watch(self->inotfd, path, fileflags)) == -1) { if ((self->inotwd[i] = inotify_add_watch(self->inotfd, path, fileflags)) == -1) {
LOG_ERROR("Failed to watch %s, error: %s", path, strerror(errno)); LOG_ERROR("Failed to watch %s, error: %s", path, strerror(errno));
} }
@ -506,23 +506,23 @@ bool config_needs_reload(GameModeConfig *self)
/* The directory itself changed, trigger a reload */ /* The directory itself changed, trigger a reload */
need = true; need = true;
break; break;
}
} else if (event->mask & IN_CREATE || event->mask & IN_MOVED_TO) { } else {
/* A new file has appeared, check the file name */ /* When the event has a filename (ie. is from a dir watch), check the name */
if (event->len > 0) {
if (strncmp(basename(event->name), CONFIG_NAME, strlen(CONFIG_NAME)) == 0) { if (strncmp(basename(event->name), CONFIG_NAME, strlen(CONFIG_NAME)) == 0) {
/* This is a gamemode config file, trigger a reload */ /* This is a gamemode config file, trigger a reload */
need = true; need = true;
break; break;
} }
}
} else { } else {
/* When the event isn't a dir event - one of our files has been interacted with /* Otherwise this is for one of our watches on a specific config file, so
* in some way, so let's reload regardless of the details * trigger the reload regardless */
*/
need = true; need = true;
break; break;
} }
}
i += sizeof(struct inotify_event) + event->len; i += sizeof(struct inotify_event) + event->len;
} }