[systemd-devel] [PATCH 2/2] [V3] systemctl: switch-root check, if we switch to a systemd init

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Thu Mar 6 05:25:04 PST 2014


On Thu, Mar 06, 2014 at 09:12:58AM +0100, harald at redhat.com wrote:
> From: Harald Hoyer <harald at redhat.com>
> 
> If "systemctl switch-root" is called with a specific "INIT" or
> /proc/cmdline contains "init=", then systemd would not serialize
> itsself.
> 
> Let systemctl check, if the new init is in the standard systemd
> installation path and if so, clear the INIT parameter,
> to let systemd serialize itsself.
> ---
>  src/systemctl/systemctl.c | 27 +++++++++++++++++++++------
>  1 file changed, 21 insertions(+), 6 deletions(-)
> 
> diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
> index f395265..852616d 100644
> --- a/src/systemctl/systemctl.c
> +++ b/src/systemctl/systemctl.c
> @@ -4295,19 +4295,34 @@ static int switch_root(sd_bus *bus, char **args) {
>  
>          root = args[1];
>  
> -        if (l >= 3)
> +        if (l >= 3) {
>                  init = strdup(args[2]);
> +                if (!init)
> +                        return log_oom();
> +        }
>          else {
} else {

>                  parse_env_file("/proc/cmdline", WHITESPACE,
>                                 "init", &init,
>                                 NULL);
> -
> -                if (!init)
> -                        init = strdup("");
>          }
>  
> -        if (!init)
> -                return log_oom();
> +        if (init && init[0]) {
!isempty(init)

> +                _cleanup_free_ char *root_init_path = NULL;
> +                _cleanup_free_ char *root_systemd_path = NULL;
> +
> +                root_systemd_path = strappenda(root, "/" SYSTEMD_BINARY_PATH);
> +                if (!root_systemd_path)
> +                        return log_oom();
This check is now unnecessary.

> +
> +                root_init_path = strjoin(root, "/", init, NULL);
> +                if (!root_init_path)
> +                        return log_oom();
> +
> +                if (files_same(root_init_path, root_systemd_path) > 0) {
> +                        free(init);
> +                        init = NULL;
> +                }
> +        }
>  
>          log_debug("switching root - root: %s; init: %s", root, init);

Zbyszek


More information about the systemd-devel mailing list