Read all available inotify events
Loop reading from inotify fd in arl_handle(); requires non-blocking inotify fd.
This commit is contained in:
parent
6695cd4c34
commit
0e1a85d224
|
@ -16,6 +16,7 @@
|
||||||
* along with sxiv. If not, see <http://www.gnu.org/licenses/>.
|
* along with sxiv. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -62,11 +63,14 @@ bool arl_handle(arl_t *arl, const char *filepath)
|
||||||
char *ptr;
|
char *ptr;
|
||||||
const struct inotify_event *event;
|
const struct inotify_event *event;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
ssize_t len = read(arl->fd, buf, sizeof(buf));
|
ssize_t len = read(arl->fd, buf, sizeof(buf));
|
||||||
|
|
||||||
if (len == -1)
|
if (len == -1) {
|
||||||
return false;
|
if (errno == EINTR)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
for (ptr = buf; ptr < buf + len; ptr += sizeof(*event) + event->len) {
|
for (ptr = buf; ptr < buf + len; ptr += sizeof(*event) + event->len) {
|
||||||
event = (const struct inotify_event*) ptr;
|
event = (const struct inotify_event*) ptr;
|
||||||
|
|
||||||
|
@ -95,13 +99,14 @@ bool arl_handle(arl_t *arl, const char *filepath)
|
||||||
free(fntmp);
|
free(fntmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return reload;
|
return reload;
|
||||||
}
|
}
|
||||||
|
|
||||||
void arl_init(arl_t *arl)
|
void arl_init(arl_t *arl)
|
||||||
{
|
{
|
||||||
/* this needs to be done only once */
|
/* this needs to be done only once */
|
||||||
arl->fd = inotify_init();
|
arl->fd = inotify_init1(IN_CLOEXEC | IN_NONBLOCK);
|
||||||
arl->watching_dir = false;
|
arl->watching_dir = false;
|
||||||
if (arl->fd == -1)
|
if (arl->fd == -1)
|
||||||
error(0, 0, "Could not initialize inotify, no automatic image reloading");
|
error(0, 0, "Could not initialize inotify, no automatic image reloading");
|
||||||
|
|
Loading…
Reference in New Issue