Skip to content
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

v239.1: PID file not removed when elogind is terminated #94

Closed
Yamakuzure opened this issue Nov 9, 2018 · 7 comments
Closed

v239.1: PID file not removed when elogind is terminated #94

Yamakuzure opened this issue Nov 9, 2018 · 7 comments
Assignees
Labels

Comments

@Yamakuzure
Copy link
Collaborator

I got an e-mail from Stefan about elogind not removing its PID file if it is shutdown using signal 15 (SIGTERM).

As /run is on tmpfs nowadays, this is of no real concern if elogind crashes on reboot or if the whole machine comes down. However, not all systems are like that and some have not put /run into RAM.

On these systems elogind fails to start on next reboot if a stale PID file exists.

There are two reasons for this:

  1. The installation of the signal handlers is not correct. This is a follow-up on issue Failed to register SIGINT handler [elogind 239.1] #90, which is not properly fixed by now.
  2. elogind does not check whether the PID in a found PID file actually points to an elogind instance, or is stale.

Stefan has already provided fixes for the 1st point, which I am currently testing.
The second point will be tackled thereafter.

@Yamakuzure Yamakuzure self-assigned this Nov 9, 2018
@Yamakuzure Yamakuzure added the bug label Nov 9, 2018
@Yamakuzure
Copy link
Collaborator Author

The second task, making elogind to actually check the PID file if one is found, is on my TODO list.

@daym
Copy link

daym commented Nov 10, 2018

Checking the PID in the PID file doesn't sound safe - what if it's coincidentially the same as it was in the previous boot (f.e. a deterministic boot process could easily make that happen every time).

Better would be not to use a pid file but something else. Doesn't elogind provide a dbus service? How come it's not enough to try to register the dbus service and if that doesn't work (because it's already there), fail?

@Yamakuzure
Copy link
Collaborator Author

Well, elogind checks the presence of a PID file, before it would create its own.

  • If the contained PID is its own, then everything is in order.
  • If the contained PID is different and belongs to an elogind[-daemon] process, then elogind is already running.
  • If the contained PID is different and belongs to something else. then it's a stale PID file that can be overwritten.

Unfortunately service managers like OpenRC need such a PID file to know where to send SIGTERM when shuting down the device.

@udeved
Copy link

udeved commented Nov 11, 2018

@Yamakuzure

Would openrc do if elogind service was supervised?
Runit doesn't need it afaik, it uses the supervisor pid.

@Yamakuzure
Copy link
Collaborator Author

@udeved : Not that I know of. The start-stop-daemon() command needs a PID file.

Well, I just noticed, that from the three points above the first two were already implemented, and the third was easy. See: 59e70b3

@markhindley
Copy link
Contributor

markhindley commented Dec 12, 2018

Sven,

I think the fix in 59e70b3 has an error. See `https://bugs.debian.org/916212.

The attached patch fixes it for me

Fix_stale_pidfile.patch.txt

Mark

@Yamakuzure
Copy link
Collaborator Author

@markhindley : Yes, you are right.

@Yamakuzure Yamakuzure reopened this Dec 12, 2018
Yamakuzure added a commit that referenced this issue Dec 12, 2018
The function accidently returned the found pid, if it didn't belong
to a running process.

Bug: #94
Signed-Off-By: Sven Eden <sven.eden@prydeworx.com>
enometh pushed a commit to enometh/elogind that referenced this issue Aug 3, 2022
* remove duplicate comment
* remove empty tabs and blank lines
* move macros and globals ontop
* comment to seprate function implementation
* fix alignment
* switch to *argv[] similar to other suckless code
* kill all empty last lines
* append comment to endif
* reuse existing ARRLEN macro
* comment fall through
* use while (true) everywhere

Co-authored-by: NRK <nrk@disroot.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants