Skip to content

Commit

Permalink
add fallback for inotify_init1
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Russon <[email protected]>
  • Loading branch information
Gero Treuner and flatcap committed Oct 14, 2019
1 parent 3df237a commit 42fcf7e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
8 changes: 4 additions & 4 deletions auto.def
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,10 @@ if {[get-define want-gpgme]} {
###############################################################################
# INOTIFY
if {[get-define want-inotify]} {
if {[cc-check-functions inotify_add_watch inotify_init1 inotify_rm_watch]} {
if {[cc-check-includes sys/inotify.h]} {
define USE_INOTIFY
}
if {[cc-check-functions inotify_add_watch inotify_init inotify_rm_watch]} {
define USE_INOTIFY
cc-check-functions inotify_init1
cc-check-includes sys/inotify.h
}
}

Expand Down
15 changes: 15 additions & 0 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#include "context.h"
#include "curs_lib.h"
#include "globals.h"
#ifndef HAVE_INOTIFY_INIT1
#include <fcntl.h>
#endif

bool MonitorFilesChanged = false;
bool MonitorContextChanged = false;
Expand Down Expand Up @@ -154,12 +157,24 @@ static int monitor_init(void)
{
if (INotifyFd == -1)
{
#if HAVE_INOTIFY_INIT1
INotifyFd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
if (INotifyFd == -1)
{
mutt_debug(LL_DEBUG2, "inotify_init1 failed, errno=%d %s\n", errno, strerror(errno));
return -1;
}
#else
INotifyFd = inotify_init();
if (INotifyFd == -1)
{
mutt_debug(LL_DEBUG2, "monitor: inotify_init failed, errno=%d %s\n",
errno, strerror(errno));
return -1;
}
fcntl(INotifyFd, F_SETFL, O_NONBLOCK);
fcntl(INotifyFd, F_SETFD, FD_CLOEXEC);
#endif
mutt_poll_fd_add(0, POLLIN);
mutt_poll_fd_add(INotifyFd, POLLIN);
}
Expand Down
2 changes: 1 addition & 1 deletion monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Monitor files for changes
*
* @authors
* Copyright (C) 2018 Gero Treuer <[email protected]>
* Copyright (C) 2018 Gero Treuner <[email protected]>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
Expand Down

0 comments on commit 42fcf7e

Please sign in to comment.