Make explicit reload also reset the inotify watch

This commit is contained in:
Matthias Schiffer 2016-02-02 08:37:39 +01:00
parent df096b4b4e
commit 709e22459b

View file

@ -31,6 +31,7 @@ static unsigned time_orig = 0;
#ifdef USE_INOTIFY #ifdef USE_INOTIFY
static int inotify_fd = -1; static int inotify_fd = -1;
static int inotify_watch = -1;
#endif #endif
#endif #endif
@ -122,6 +123,23 @@ static void load(void) {
glDeleteProgram(program); glDeleteProgram(program);
} }
#if defined(USE_INOTIFY) && !defined(GLSLWRITE)
static void reset_watch(void) {
if (inotify_watch >= 0) {
if (inotify_rm_watch(inotify_fd, inotify_watch)) {
fprintf(stderr, "unable to remove watch\n");
exit(1);
}
}
inotify_watch = inotify_add_watch(inotify_fd, filename, IN_CLOSE_WRITE);
if (inotify_watch < 0) {
fprintf(stderr, "unable to watch '%s' for changes\n", filename);
return;
}
}
#endif
static void init(void) { static void init(void) {
#if defined(USE_INOTIFY) && !defined(GLSLWRITE) #if defined(USE_INOTIFY) && !defined(GLSLWRITE)
inotify_fd = inotify_init(); inotify_fd = inotify_init();
@ -130,14 +148,9 @@ static void init(void) {
exit(1); exit(1);
} }
int watch = inotify_add_watch(inotify_fd, filename, IN_CLOSE_WRITE);
if (watch < 0) {
fprintf(stderr, "unable to watch '%s' for changes\n", filename);
exit(1);
}
fcntl(inotify_fd, F_SETFL, fcntl(inotify_fd, F_GETFL)|O_NONBLOCK); fcntl(inotify_fd, F_SETFL, fcntl(inotify_fd, F_GETFL)|O_NONBLOCK);
reset_watch();
#endif #endif
glewInit(); glewInit();
@ -266,6 +279,9 @@ int main(int argc, char *argv[]) {
#ifndef GLSLWRITE #ifndef GLSLWRITE
case SDLK_l: case SDLK_l:
#ifdef USE_INOTIFY
reset_watch();
#endif
load(); load();
break; break;