diff --git a/bin/linux/fsnotifier b/bin/linux/fsnotifier index 37430c7dc675..f79a688a18bd 100755 Binary files a/bin/linux/fsnotifier and b/bin/linux/fsnotifier differ diff --git a/bin/linux/fsnotifier64 b/bin/linux/fsnotifier64 index 1bd81797640c..a967353d6294 100755 Binary files a/bin/linux/fsnotifier64 and b/bin/linux/fsnotifier64 differ diff --git a/native/fsNotifier/linux/fsnotifier.h b/native/fsNotifier/linux/fsnotifier.h index 0bcfaa5f9644..087246e98644 100644 --- a/native/fsNotifier/linux/fsnotifier.h +++ b/native/fsNotifier/linux/fsnotifier.h @@ -67,7 +67,7 @@ enum { }; bool init_inotify(); -void set_inotify_callback(void (* callback)(char*, int)); +void set_inotify_callback(void (* callback)(const char*, int)); int get_inotify_fd(); int watch(const char* root, array* mounts); void unwatch(int id); diff --git a/native/fsNotifier/linux/inotify.c b/native/fsNotifier/linux/inotify.c index 77536dc3dcba..713d09c54a38 100644 --- a/native/fsNotifier/linux/inotify.c +++ b/native/fsNotifier/linux/inotify.c @@ -50,7 +50,7 @@ static int inotify_fd = -1; static int watch_count = 0; static table* watches; static bool limit_reached = false; -static void (* callback)(char*, int) = NULL; +static void (* callback)(const char*, int) = NULL; #define EVENT_SIZE (sizeof(struct inotify_event)) #define EVENT_BUF_LEN (2048 * (EVENT_SIZE + 16)) @@ -112,7 +112,7 @@ static void read_watch_descriptors_count() { } -inline void set_inotify_callback(void (* _callback)(char*, int)) { +inline void set_inotify_callback(void (* _callback)(const char*, int)) { callback = _callback; } @@ -346,15 +346,19 @@ static bool process_inotify_event(struct inotify_event* event) { bool is_dir = (event->mask & IN_ISDIR) == IN_ISDIR; userlog(LOG_DEBUG, "inotify: wd=%d mask=%d dir=%d name=%s", event->wd, event->mask & (~IN_ISDIR), is_dir, node->path); - memcpy(path_buf, node->path, node->path_len + 1); int path_len = node->path_len; + memcpy(path_buf, node->path, path_len + 1); if (event->len > 0) { - path_buf[node->path_len] = '/'; + path_buf[path_len] = '/'; int name_len = strlen(event->name); memcpy(path_buf + path_len + 1, event->name, name_len + 1); path_len += name_len + 1; } + if (callback != NULL) { + (*callback)(path_buf, event->mask); + } + if (is_dir && event->mask & (IN_CREATE | IN_MOVED_TO)) { int result = walk_tree(path_len, node, true, NULL); if (result < 0 && result != ERR_IGNORE && result != ERR_CONTINUE) { @@ -373,10 +377,6 @@ static bool process_inotify_event(struct inotify_event* event) { } } - if (callback != NULL) { - (*callback)(path_buf, event->mask); - } - return true; } diff --git a/native/fsNotifier/linux/main.c b/native/fsNotifier/linux/main.c index 3cd65e28fc54..95a22b415683 100644 --- a/native/fsNotifier/linux/main.c +++ b/native/fsNotifier/linux/main.c @@ -36,7 +36,7 @@ #define LOG_ENV_ERROR "error" #define LOG_ENV_OFF "off" -#define VERSION "20130617.1935" +#define VERSION "20130715.1353" #define VERSION_MSG "fsnotifier " VERSION "\n" #define USAGE_MSG \ @@ -79,11 +79,11 @@ static bool update_roots(array* new_roots); static void unregister_roots(); static bool register_roots(array* new_roots, array* unwatchable, array* mounts); static array* unwatchable_mounts(); -static void inotify_callback(char* path, int event); -static void report_event(char* event, char* path); +static void inotify_callback(const char* path, int event); +static void report_event(const char* event, const char* path); static void output(const char* format, ...); static void check_missing_roots(); -static void check_root_removal(char*); +static void check_root_removal(const char*); int main(int argc, char** argv) { @@ -434,7 +434,7 @@ static array* unwatchable_mounts() { } -static void inotify_callback(char* path, int event) { +static void inotify_callback(const char* path, int event) { if (event & (IN_CREATE | IN_MOVED_TO)) { report_event("CREATE", path); report_event("CHANGE", path); @@ -457,21 +457,32 @@ static void inotify_callback(char* path, int event) { } } -static void report_event(char* event, char* path) { +static void report_event(const char* event, const char* path) { userlog(LOG_DEBUG, "%s: %s", event, path); - int len = strlen(path); - for (char* p = path; *p != '\0'; p++) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wincompatible-pointer-types" + char* copy = path, *p; + for (p = copy; *p != '\0'; ++p) { if (*p == '\n') { + if (copy == path) { + copy = strdup(path); + p = copy + (p - path); + } *p = '\0'; } } +#pragma clang diagnostic pop fputs(event, stdout); fputc('\n', stdout); - fwrite(path, len, 1, stdout); + fwrite(copy, (p - copy), 1, stdout); fputc('\n', stdout); + if (copy != path) { + free(copy); + } + fflush(stdout); } @@ -506,7 +517,7 @@ static void check_missing_roots() { } } -static void check_root_removal(char* path) { +static void check_root_removal(const char* path) { for (int i=0; iid >= 0 && strcmp(path, UNFLATTEN(root->path)) == 0) {