Re: Question about the killing spree during the transition from the initrd to the root file system.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Do, 04.07.24 11:24, chenruyi (A) (chenruyi2@xxxxxxxxxx) wrote:

> Hi,
>
> I have some processes in my initrd needed to be excluded from the killing spree
> during switch-root and needed to continue to run in the root file system. I read
> the ROOT_STORAGE_DAEMONS.md and the source code of killall.c, and I've learned
> that there are methods to exclude the processes from the killing spree, such as
> setting `@` to `argv[0][0]`.
>
> However, I'm not sure if this is without potential consequences. For example, could
> it be that even though my processes survive, some resources that the processes
> depends on are discarded after switch-root, such as file
> descriptors?

No, these belong to your process, systemd couldn't really reach into
your processes to close them, even if it wanted to.

But do note that any files you keep open or mapped at the moment of transition
will remain pinned in memory, and cannot be released by the
kernel. this means that even though during the tmpfs→host transition
we generally destory the initrd's tmpfs' contents, the stuff you keep
pinned will stick around.

Generally, only special purpose software should be left around that
way, if it is carefully written to handle this. For example it is not
allowed to dlopen() anything (and hence no NSS either! No
gethostbyname() or getpwnam() or so), because you'd otherwise end up
with a weird mix of match of shared libs from the initrd and the host.

Hence, you really should know what you are doing. Otherwise it's
almost always a better idea to allow the daemon to terminate in the
initrd, and thatn start a new instance from the host fs after the
transition.

> I have the following two questions:
>
> Question 1:
> Why is it necessary to kill processes during the transition from the
> initrd to the main system?

It's not strictly necessary. It's simply about hygiene, because
everything that sticks around will pin initrd resources, and we'd
really like to get rid of those.

Generally it's the absolute exception that stuff should stick around,
hence it's a good idea to just kill everything but allow a focussed
exception logic to that.

> Question 2:
> If my processes are excluded from the killing spree during switch-root and continue to run in
> the root file system, what are the potential consequences?

You are running a processes from a different context, pinning files
from an emptied files.

Generally, don't do this, unless you know exactly what you are
doing. There are usually uch better approaches.

Lennart

--
Lennart Poettering, Berlin



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux