-
-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for PID files created in sub-directories to /run #109
Comments
Ah, yes that's a limitation of the current pidfile.so plugin. It only monitors It should be fairly simple to extend it with automatically adding a file watcher for Your patch above may also work if you change it to use |
Yeah, i could modify the pid path of dbus, too. In my view this should be improved rather than just using workarounds, so i issued this :). |
Thanks, I'll look into it later on then :) |
This is my hack patch. It should be very easy to modify and merge :). --- finit-3.1/plugins/pidfile.c 2018-01-23 18:29:58.000000000 +0800
+++ finit-3.1/plugins/pidfile.c 2018-01-23 18:29:58.000000000 +0800
@@ -32,11 +32,20 @@
#include "plugin.h"
#include "service.h"
+#include <stdbool.h>
+struct wd {
+ TAILQ_ENTRY(wd) link;
+ char *path;
+ int wd;
+};
+
struct context {
int fd;
- int wd;
+ TAILQ_HEAD(tailhead, wd) wd_list;
};
+static struct context pidfile_ctx;
+
static char *mkcond(char *buf, size_t len, char *nm)
{
snprintf(buf, len, "svc%s%s", nm[0] != '/' ? "/" : "", nm);
@@ -62,7 +70,41 @@
for (ev = (void *)ev_buf;
sz > (ssize_t)sizeof(*ev);
len = sizeof(*ev) + ev->len, ev = (void *)ev + len, sz -= len) {
- if (!ev->mask || !strstr(ev->name, ".pid"))
+ if (!ev->mask)
+ continue;
+
+ if (ev->mask & (IN_CREATE | IN_ATTRIB | IN_MODIFY | IN_ISDIR)) {
+ // find current watcher
+ struct wd *np;
+ TAILQ_FOREACH(np, &pidfile_ctx.wd_list, link)
+ if (np->wd == ev->wd)
+ break;
+
+ // make the path
+ int len = snprintf(NULL, 0, "%s/%s", np->path, ev->name)+1;
+ char *path = malloc(len);
+ snprintf(path, len, "%s/%s", np->path, ev->name);
+
+ // check if we already have a watcher for this dir
+ int wd = inotify_add_watch(pidfile_ctx.fd, path, IN_CREATE | IN_ATTRIB | IN_DELETE | IN_MODIFY);
+ bool new = true;
+ TAILQ_FOREACH(np, &pidfile_ctx.wd_list, link)
+ if (np->wd == wd) {
+ new = false;
+ break;
+ }
+
+ // if no, watch it
+ if (new) {
+ struct wd *new_wd = malloc(sizeof(struct wd));
+ new_wd->path = path;
+ new_wd->wd = wd;
+ TAILQ_INSERT_HEAD(&pidfile_ctx.wd_list, new_wd, link);
+ } else
+ free(path);
+ }
+
+ if (!strstr(ev->name, ".pid"))
continue;
svc = svc_find_by_pidfile(ev->name);
@@ -110,10 +152,9 @@
} while (restart);
}
-static void pidfile_init(void *arg)
+static void pidfile_init()
{
char *path;
- struct context *ctx = arg;
/*
* The bootmisc plugin is responsible for setting up /var/run.
@@ -126,27 +167,29 @@
return;
}
- ctx->wd = inotify_add_watch(ctx->fd, path, IN_CREATE | IN_ATTRIB | IN_DELETE | IN_MODIFY);
- free(path);
+ TAILQ_INIT(&pidfile_ctx.wd_list);
+ struct wd *wd = malloc(sizeof(struct wd));
+ wd->path = path;
+ wd->wd = inotify_add_watch(pidfile_ctx.fd, path, IN_CREATE | IN_ATTRIB | IN_DELETE | IN_MODIFY);
- if (ctx->wd < 0) {
+ if (wd->wd < 0) {
_pe("inotify_add_watch()");
- close(ctx->fd);
+ close(pidfile_ctx.fd);
+ free(path);
return;
}
+ TAILQ_INSERT_HEAD(&pidfile_ctx.wd_list, wd, link);
_d("pidfile monitor active");
}
-static struct context pidfile_ctx;
-
/*
* We require /var/run to be set up before calling pidfile_init(),
* so the bootmisc plugin must run first.
*/
static plugin_t plugin = {
.name = __FILE__,
- .hook[HOOK_BASEFS_UP] = { .arg = &pidfile_ctx, .cb = pidfile_init },
+ .hook[HOOK_BASEFS_UP] = { .cb = pidfile_init },
.hook[HOOK_SVC_RECONF] = { .cb = pidfile_reconf },
.io = {
.cb = pidfile_callback,
@@ -169,7 +212,14 @@
PLUGIN_EXIT(plugin_exit)
{
- inotify_rm_watch(pidfile_ctx.fd, pidfile_ctx.wd);
+ struct wd *np = TAILQ_FIRST(&pidfile_ctx.wd_list), *npn = NULL;
+ while (np != NULL) {
+ npn = TAILQ_NEXT(np, link);
+ free(np->path);
+ inotify_rm_watch(pidfile_ctx.fd, np->wd);
+ free(np);
+ np = npn;
+ }
close(pidfile_ctx.fd);
plugin_unregister(&plugin); |
Cool, nicely done! :-) I really have to get back to hacking in userspace again, a bit stuck atm. in kernel land because of work. Only doing some minor artifact restoration for recreational purposes. Cannot promise any timeline, but I suspect I can merge this in a month or so. Cheers! |
Update: finit do not watch
There's also another problem, i'll stick it there when i am available. Update: OK, i find it, we also need a
|
This bug/feature took a little too long for me to fix, sorry about that! We finally needed the same feature at $DAYJOB, so I took the opportunity to fix the general case. Still haven't tested the actual case of dbus-daemon, but several others with a similar setup. What's still needed is adding 'pid:!/run/dbus/pid' to the service stanza. |
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
I want some services waiting for dbus, but no luck even with the following patch:
It just shows:
Seems, only
/run/xxx.pid
could trigger the cond, any idea?The text was updated successfully, but these errors were encountered: