plugins: pidfile: tricky zebra doesn't close its pid file

This patch fixes a few really hard problems wrt PID files:

 1. Listening for IN_CREATE events means we get notified immediately by
    the kernel when someone calls open()/fopen() on a PID file.  Reading
    the contents returns 0, thank you atoi() ... so we drop IN_CREATE
    and instead look for IN_CLOSE_WRITE, there fixed it!  Not quite ...

 2. Some programs, like Zebra, and other Quagga/Frr daemons, don't
    close() their PID files after creation.  Instead they ftruncate()
    and keep them open, and locked.  Presumably to get a mechanism to
    detect already running instances -- messes life up a bit for the
    rest of us though.  So we need to read files after IN_MODIFY too.

 3. We also want to track IN_DELETE so we can deassert conditions when
    services exit gracefully and clean up their PID files

The rest fo the commit is debug instrumentation changes.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2021-03-11 11:44:23 +01:00
1 parent 05ac9c18c9
commit 2711b27971
2 files changed
+8 -13

No files matched your search

+3 -1
View File
@@ -415,8 +415,10 @@ svc_t *svc_find_by_pidfile(char *fn)
pid_t pid;
pid = pid_file_read(fn);
if (pid == -1)
if (pid <= 0) {
_d("pid_file_read(%s) => %d", fn, pid);
return NULL;
}
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
if (svc->pid != pid)