mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-16 13:20:41 +01:00
Merge pull request #4844 from rgerhards/tmpmaster
imfile: do_inotify() use only one blocking call
This commit is contained in:
commit
fb2695c529
@ -2444,10 +2444,11 @@ do_inotify(void)
|
||||
int rd;
|
||||
int currev;
|
||||
static int last_timeout = 0;
|
||||
struct pollfd pollfd;
|
||||
DEFiRet;
|
||||
|
||||
CHKiRet(wdmapInit());
|
||||
ino_fd = inotify_init();
|
||||
ino_fd = inotify_init1(IN_NONBLOCK);
|
||||
if(ino_fd < 0) {
|
||||
LogError(errno, RS_RET_INOTIFY_INIT_FAILED, "imfile: Init inotify "
|
||||
"instance failed ");
|
||||
@ -2458,18 +2459,26 @@ do_inotify(void)
|
||||
do_initial_poll_run();
|
||||
|
||||
while(glbl.GetGlobalInputTermState() == 0) {
|
||||
if(runModConf->haveReadTimeouts) {
|
||||
int r;
|
||||
struct pollfd pollfd;
|
||||
|
||||
pollfd.fd = ino_fd;
|
||||
pollfd.events = POLLIN;
|
||||
do {
|
||||
|
||||
if (runModConf->haveReadTimeouts)
|
||||
r = poll(&pollfd, 1, runModConf->timeoutGranularity);
|
||||
} while(r == -1 && errno == EINTR);
|
||||
else
|
||||
r = poll(&pollfd, 1, -1);
|
||||
|
||||
if (r == -1 && errno == EINTR) {
|
||||
DBGPRINTF("do_inotify interrupted while polling on ino_fd\n");
|
||||
continue;
|
||||
}
|
||||
if(r == 0) {
|
||||
DBGPRINTF("readTimeouts are configured, checking if some apply\n");
|
||||
if (runModConf->haveReadTimeouts) {
|
||||
fs_node_walk(runModConf->conf_tree, poll_timeouts);
|
||||
last_timeout = time(NULL);
|
||||
}
|
||||
continue;
|
||||
} else if (r == -1) {
|
||||
LogError(errno, RS_RET_INTERNAL_ERROR,
|
||||
@ -2484,6 +2493,14 @@ do_inotify(void)
|
||||
/* we do not abort, as this would render the whole input defunct */
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// process timeouts always, ino_fd may be too busy to ever have timeout occur from poll
|
||||
if(runModConf->haveReadTimeouts) {
|
||||
int now = time(NULL);
|
||||
if(last_timeout + (runModConf->timeoutGranularity / 1000) > now) {
|
||||
fs_node_walk(runModConf->conf_tree, poll_timeouts);
|
||||
last_timeout = time(NULL);
|
||||
}
|
||||
}
|
||||
rd = read(ino_fd, iobuf, sizeof(iobuf));
|
||||
if(rd == -1 && errno == EINTR) {
|
||||
@ -2491,6 +2508,9 @@ do_inotify(void)
|
||||
DBGPRINTF("EINTR received during inotify, restarting poll\n");
|
||||
continue;
|
||||
}
|
||||
if (rd == -1 && errno == EWOULDBLOCK) {
|
||||
continue;
|
||||
}
|
||||
if(rd < 0) {
|
||||
LogError(errno, RS_RET_IO_ERROR, "imfile: error during inotify - ignored");
|
||||
continue;
|
||||
@ -2506,10 +2526,6 @@ do_inotify(void)
|
||||
in_processEvent(savecast.ev);
|
||||
currev += sizeof(struct inotify_event) + savecast.ev->len;
|
||||
}
|
||||
int now = time(NULL);
|
||||
if(last_timeout + (runModConf->timeoutGranularity / 1000) > now) {
|
||||
fs_node_walk(runModConf->conf_tree, poll_timeouts);
|
||||
last_timeout = time(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user