Fix abort when dmon_watch_rm remove a wd

This commit is contained in:
Francesco Abbate 2021-09-26 22:43:13 +02:00
parent 9198e48fec
commit 958703de02
1 changed files with 12 additions and 10 deletions

View File

@ -892,7 +892,6 @@ _DMON_PRIVATE const char* dmon__find_subdir(const dmon__watch_state* watch, int
}
}
DMON_ASSERT(0);
return NULL;
}
@ -1129,18 +1128,21 @@ static void* dmon__thread(void* arg)
while (offset < len) {
struct inotify_event* iev = (struct inotify_event*)&buff[offset];
char filepath[DMON_MAX_PATH];
dmon__strcpy(filepath, sizeof(filepath), dmon__find_subdir(watch, iev->wd));
dmon__strcat(filepath, sizeof(filepath), iev->name);
const char *subdir = dmon__find_subdir(watch, iev->wd);
if (subdir) {
char filepath[DMON_MAX_PATH];
dmon__strcpy(filepath, sizeof(filepath), subdir);
dmon__strcat(filepath, sizeof(filepath), iev->name);
// TODO: ignore directories if flag is set
// TODO: ignore directories if flag is set
if (stb_sb_count(_dmon.events) == 0) {
usecs_elapsed = 0;
if (stb_sb_count(_dmon.events) == 0) {
usecs_elapsed = 0;
}
dmon__inotify_event dev = { { 0 }, iev->mask, iev->cookie, watch->id, false };
dmon__strcpy(dev.filepath, sizeof(dev.filepath), filepath);
stb_sb_push(_dmon.events, dev);
}
dmon__inotify_event dev = { { 0 }, iev->mask, iev->cookie, watch->id, false };
dmon__strcpy(dev.filepath, sizeof(dev.filepath), filepath);
stb_sb_push(_dmon.events, dev);
offset += sizeof(struct inotify_event) + iev->len;
}