About notifying parent process

Some time ago I decided to add to my preferred pdf viewer1 feature to save and restore current page between program invocations. It already had command line option to open file at specified page, but provided no simple way to know at what was current page when it exited.

I found variable that contains page number quickly, but how do I return its value to parent process? Standard streams were already used for something else, so after some though I found elegant (I think) solution: write page number to non-standard file descriptor2:

dprintf(4, "%d\n", num);

If that file descriptor is not open, nothing happens – function call silently fails. If parent setup this descriptor to be output side of a pipe, parent will be able to read value from input side of that pipe. That is exactly what I did when implementing wrapper that saves and restores current page3.

After that I recalled that the most common reason software links with libsystem is desire to notify systemd that service finished initialization, e.g:

sd_notify(1, "READY=1")
while (1) {

I have never seen situation when this is actually needed, but that is not the point. Point is that in many, many cases libsystemd could have been replaced with just at convention of notifications being written to a well-known file descriptor.

Simple, lightweight and non-invasive. Properties that are at odds with systemd project agenda.

  1. https://github.com/aligrudi/fbpdf↩︎

  2. https://git.sr.ht/~kaction/config/tree/17da553310d73b2fa8f29b3d4fdbf9b5dd12fdef/nixpkgs/overlays.d/staging.d/fbpdf/patches/current-page.patch↩︎

  3. https://git.sr.ht/~kaction/savepage/tree/af884e3e9b924fc4358e0634011824dda63258c7/savepage.exec#L26↩︎