[systemd-devel] [PATCH] use the switch_root function in shutdown

Lennart Poettering lennart at poettering.net
Thu Aug 28 06:17:51 PDT 2014


On Thu, 28.08.14 14:01, harald at redhat.com (harald at redhat.com) wrote:

>  
>          if (!in_container && !in_initrd() &&
>              access("/run/initramfs/shutdown", X_OK) == 0) {
> -
> -                if (prepare_new_root() >= 0 &&
> -                    pivot_to_new_root() >= 0) {
> +                if (switch_root_initramfs() >= 0) {
>                          arguments[0] = (char*) "/shutdown";
>  
> -                        log_info("Returning to initrd...");
> +                        setsid();
> +                        make_console_stdio();
> +
> +                        log_info("Successfully changed into root pivot.\n"
> +                                 "Returning to initrd...");
>  
>                          execv("/shutdown", arguments);
>                          log_error("Failed to execute shutdown binary: %m");
> -                }
> +                } else
> +                        log_error("Failed to switch root to \"/run/initramfs\": %m");
>          }

The error of switch_root_initramfs() is returned in the return value,
not in errno. Hence you need to store the result in some variable "r"
first, and then print the error with %s and strerror(-r) instead of %m...


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list