systemd: apcupsd daemon parent exits before the child creates the pid file

Bug #1967490 reported by Lorenzo Buzzi
24
This bug affects 4 people
Affects Status Importance Assigned to Milestone
apcupsd (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

The apcupsd.service file in Ubuntu 20.04 LTS (amd64) includes the following lines:
Type=forking
PIDFile=/var/run/apcupsd.pid

The systemd documentation (https://www.freedesktop.org/software/systemd/man/systemd.service.html), searching for "Type=forking", reports the following statement:
[...]
... if the process decides to write a traditional PID file, systemd will be able to read the main PID from there. Please set PIDFile= accordingly. Note that the daemon should write that file before finishing with its initialization. Otherwise, systemd might try to read the file before it exists.
[...]

The issue is that, although the daemon is started and works correctly, the "systemctl status apcupsd.service" call always reports the following:
systemd[1]: apcupsd.service: Can't open PID file /run/apcupsd.pid (yet?) after start: Operation not permitted

This glitch is due to the fact that the parent process of the daemon exits before the child has written the PID file.
I proved this statement by recompiling apcupsd from source and inserting a "sleep(1)" before the "exit(0) /* parent exits */" call in the daemon_start() function (of apcupsd.c).
It fixed the issue by keeping the parent alive for a while, giving the child enough time to call make_pid_file().

I know that sleep(1) is not a bugfix rather a test for verifying the root cause of the issue.

I reported the issue to the apcupsd developers before filling this bug. Anyway although their mailing list is alive and kicking, they do not release a new version since 2016 so I am not so confident that they will fix their source (at least not soon).

So could you please implement and apply a patch to the source that delays the exit of the parent (i.e. waiting for the PID file of the child to be created) in order to make apcupsd 100% compliant to what systemd expects?

Lorenzo Buzzi (lobuvds)
description: updated
description: updated
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in apcupsd (Ubuntu):
status: New → Confirmed
Revision history for this message
reetp (jcrisp) wrote :

Is there any other workaround for this issue?

Revision history for this message
Lorenzo Buzzi (lobuvds) wrote :

The apcupsd developers answered to my report on their mailing list.

See https://sourceforge.net/p/apcupsd/mailman/apcupsd-users/thread/CAKb_4nSxZCH_cFqXhb3N3t8ArFN_tn7ZiTTR5MCqBREDDiSyuQ%40mail.gmail.com/#msg37639690

At present time the only workaround it seems to be recompiling adding the sleep() call.

Revision history for this message
reetp (jcrisp) wrote :

How very annoying.

Was just wondering whether I could generate a PPA with the patch but not familiar with the *buntu/deb way of things (I usually only mess with RPMs).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.