troglobit / finit

Fast init for Linux. Cookies included
https://troglobit.com/projects/finit/
MIT License
622 stars 61 forks source link

Add plugin hook after unmount #302

Closed hongkongkiwi closed 1 year ago

hongkongkiwi commented 1 year ago

Hi, I am looking into creating a plugin that's run after the system is unmounted. I'm going to make it using the normal plugin architecture because it's nice and clean and I can use the official finit branch.

Is it possible to add an extra hook so I can run some code to send something to serial port after unmount has been completed? e.g. HOOK_UNMOUNT_COMPLETE or something?

Maybe it's there and I missed it but according to the docs there's only HOOK_SHUTDOWN

Presumably it probably would hook in at this point?

I could see this being useful to create a cleanup hook for some embedded devices which need to set a particular state when cleanly powering down. In my case I will send out a serial message to let the co-processor know that we are OK to hard power off but I could imagine other people would find uses as a "Last will and testament feature".

hongkongkiwi commented 1 year ago

Well, I guess if I'm asking for something new, maybe it makes sense to have two new hooks:

troglobit commented 1 year ago

Hmm, it's a little bit tricky. The point you reference is after we've unloaded the plugins in plugins_exit(), and we need to unload as much as possible to be able to unmount ... but I guess for the latter hook you could use a "hook script", right?

hongkongkiwi commented 1 year ago

I took a look at the hook script plugin, but that just runs scripts based on the hooks and HOOK_SHUTDOWN is the only hook that's available ?

An external script is totally fine, I can put the C code in an externally called program.

troglobit commented 1 year ago

Yeah, I meant add the hook point to the code, after all the umounts, but then it would only be possible to run scripts there. So a limitation for that specific (very late) hook point.

hongkongkiwi commented 1 year ago

That would be great and solve my issue.

But ahh one thing.... I do need access to a serial device ? (/dev/ttyS1) does /dev get unmounted?

troglobit commented 1 year ago

Hmm, /dev is usually a devtmpfs these days ... currently Finit unmounts that too, but I think that (devtmpfs) would be OK to add an exception for. That needs a separate issue, I'll create one right away!

troglobit commented 1 year ago

@hongkongkiwi The final hook names changed slightly, see doc/plugins.md for details and an example.