mirror of
https://github.com/troglobit/finit.git
synced 2026-11-17 19:30:29 +00:00
tty.c: Handle EINVAL and use recommended inotify event size.
The TTY plugin might fail in read() with EINVAL if the inotify event buffer is too small. Fix: set the receive event buffer to the size recommended in inotify(7). Also add a handler for EINVAL to close and reinitialize the inotify descriptor so we do not accidentally overrun the CPU with any unhandled errors. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
f902505b5d
commit
c8f0b97d0f
2 files changed
+10
-3
No files matched your search
+8
-2
@@ -46,7 +46,10 @@ static plugin_t plugin = {
|
|||||||
|
|
||||||
static void setup(void)
|
static void setup(void)
|
||||||
{
|
{
|
||||||
plugin.io.fd = inotify_init1(IN_NONBLOCK);
|
if (plugin.io.fd)
|
||||||
|
close(plugin.io.fd);
|
||||||
|
|
||||||
|
plugin.io.fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
|
||||||
if (-1 == plugin.io.fd || inotify_add_watch(plugin.io.fd, "/dev", IN_CREATE | IN_DELETE) < 0)
|
if (-1 == plugin.io.fd || inotify_add_watch(plugin.io.fd, "/dev", IN_CREATE | IN_DELETE) < 0)
|
||||||
_e("Failed starting TTY watcher: %s", strerror(errno));
|
_e("Failed starting TTY watcher: %s", strerror(errno));
|
||||||
}
|
}
|
||||||
@@ -60,9 +63,12 @@ static void watcher(void *UNUSED(arg), int fd, int UNUSED(events))
|
|||||||
|
|
||||||
while ((len = read(fd, buf, sizeof(buf)))) {
|
while ((len = read(fd, buf, sizeof(buf)))) {
|
||||||
if (-1 == len) {
|
if (-1 == len) {
|
||||||
|
if (errno == EINVAL)
|
||||||
|
setup();
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
break;
|
|
||||||
|
break; /* Likely EAGAIN */
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(name, sizeof(name), "/dev/%s", notified->name);
|
snprintf(name, sizeof(name), "/dev/%s", notified->name);
|
||||||
|
|||||||
@@ -25,9 +25,10 @@
|
|||||||
#ifndef FINIT_TTY_H_
|
#ifndef FINIT_TTY_H_
|
||||||
#define FINIT_TTY_H_
|
#define FINIT_TTY_H_
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
#include "queue.h" /* BSD sys/queue.h API */
|
#include "queue.h" /* BSD sys/queue.h API */
|
||||||
|
|
||||||
#define EVENT_SIZE ((sizeof(struct inotify_event) + 20))
|
#define EVENT_SIZE ((sizeof(struct inotify_event) + NAME_MAX + 1))
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *name;
|
char *name;
|
||||||
|
|||||||
Reference in new issue
Block a user