mirror of
https://github.com/troglobit/finit.git
synced 2026-10-24 11:54:36 +00:00
plugins: pidfile: simplify, use constructs from src/conf.c
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
8790fcabf3
commit
ea278a6370
1 file changed
+7
-19
+7
-19
@@ -149,36 +149,26 @@ static void pidfile_handle_dir(struct iwatch *iw, char *dir, char *name, int mas
|
|||||||
|
|
||||||
static void pidfile_callback(void *arg, int fd, int events)
|
static void pidfile_callback(void *arg, int fd, int events)
|
||||||
{
|
{
|
||||||
|
static char ev_buf[8 *(sizeof(struct inotify_event) + NAME_MAX + 1) + 1];
|
||||||
struct inotify_event *ev;
|
struct inotify_event *ev;
|
||||||
ssize_t sz, off;
|
ssize_t sz, off;
|
||||||
size_t buflen = 8 *(sizeof(struct inotify_event) + NAME_MAX + 1) + 1;
|
|
||||||
char *buf;
|
|
||||||
|
|
||||||
buf= malloc(buflen);
|
sz = read(fd, ev_buf, sizeof(ev_buf) - 1);
|
||||||
if (!buf) {
|
|
||||||
_pe("Failed allocating buffer for inotify events");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_d("Entering ... reading %zu bytes into ev_buf[]", buflen - 1);
|
|
||||||
sz = read(fd, buf, buflen - 1);
|
|
||||||
if (sz <= 0) {
|
if (sz <= 0) {
|
||||||
_pe("invalid inotify event");
|
_pe("invalid inotify event");
|
||||||
goto done;
|
return;
|
||||||
}
|
}
|
||||||
buf[sz] = 0;
|
ev_buf[sz] = 0;
|
||||||
_d("Read %zd bytes, processing ...", sz);
|
|
||||||
|
|
||||||
off = 0;
|
|
||||||
for (off = 0; off < sz; off += sizeof(*ev) + ev->len) {
|
for (off = 0; off < sz; off += sizeof(*ev) + ev->len) {
|
||||||
struct iwatch_path *iwp;
|
struct iwatch_path *iwp;
|
||||||
|
|
||||||
ev = (struct inotify_event *)&buf[off];
|
ev = (struct inotify_event *)&ev_buf[off];
|
||||||
|
|
||||||
_d("path %s, event: 0x%08x", ev->name, ev->mask);
|
|
||||||
if (!ev->mask)
|
if (!ev->mask)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
_d("name %s, event: 0x%08x", ev->name, ev->mask);
|
||||||
|
|
||||||
/* Find base path for this event */
|
/* Find base path for this event */
|
||||||
iwp = iwatch_find_by_wd(&iw_pidfile, ev->wd);
|
iwp = iwatch_find_by_wd(&iw_pidfile, ev->wd);
|
||||||
if (!iwp)
|
if (!iwp)
|
||||||
@@ -197,8 +187,6 @@ static void pidfile_callback(void *arg, int fd, int events)
|
|||||||
if (ev->mask & (IN_CREATE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO))
|
if (ev->mask & (IN_CREATE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO))
|
||||||
pidfile_update_conds(iwp->path, ev->name, ev->mask);
|
pidfile_update_conds(iwp->path, ev->name, ev->mask);
|
||||||
}
|
}
|
||||||
done:
|
|
||||||
free(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in new issue
Block a user