Page MenuHomeFreeBSD

Add CAP_EVENT to pidfiles.
ClosedPublic

Authored by dab on Jun 19 2020, 5:43 PM.

Details

Summary

CAP_EVENT was omitted on pidfiles (in
pidfile_open()). There seems no reason why a process that creates
and writes a pidfile cannot monitor events on that file. This mod adds
the capability.

As a concrete example of why one might want to do this: at $JOB there
is a daemon that is started very early in the rc sequence; in
particular it is started before rc.d/cleanvar. When cleanvar runs, it
removes the pidfile for the daemon. If an attempt is made to start
that daemon later, it checks for the existence of the pidfile, but the
pidfile no longer (apparently) exists, so the daemon starts up and
there are now two copies of the daemon running. In order to avoid
this, I attempted to have the daemon monitor its pidfile via kevent
and re-create it if it is deleted but found that the attempt to
register the event failed since the process lacked the CAP_EVENT
capability. Adding it (as here) fixed the issue.

Test Plan

Verified working at $JOB

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

dab requested review of this revision.Jun 19 2020, 5:43 PM

I'm supportive of the capability change in general.

Do delete events actually notify on the deleted file? I would expect to receive a notification on the pid's parent directory, but am not sure about the pid file itself.

This revision is now accepted and ready to land.Jun 19 2020, 8:38 PM
In D25363#559516, @cem wrote:

Do delete events actually notify on the deleted file? I would expect to receive a notification on the pid's parent directory, but am not sure about the pid file itself.

I am getting a notice due to deletion of the file in my test.

This revision was automatically updated to reflect the committed changes.