Removed undefined behaviour by using `poll` over `select`.

This commit is contained in:
Adam Harrison 2022-05-09 23:12:43 -04:00
parent 6229f74ccd
commit 0315d397bd
1 changed files with 3 additions and 6 deletions

View File

@ -1,8 +1,8 @@
#include <sys/inotify.h>
#include <sys/select.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
struct dirmonitor_internal {
@ -30,11 +30,8 @@ void deinit_dirmonitor(struct dirmonitor_internal* monitor) {
int get_changes_dirmonitor(struct dirmonitor_internal* monitor, char* buffer, int length) {
fd_set set;
FD_ZERO(&set);
FD_SET(monitor->fd, &set);
FD_SET(monitor->sig[0], &set);
select(FD_SETSIZE, &set, NULL, NULL, NULL);
struct pollfd fds[2] = { { .fd = monitor->fd, .events = POLLIN | POLLERR, .revents = 0 }, { .fd = monitor->sig[0], .events = POLLIN | POLLERR, .revents = 0 } };
poll(fds, 2, -1);
return read(monitor->fd, buffer, length);
}