[PATCH 1/1] switch_root: When console doesn't exist don't bail out

Denys Vlasenko vda.linux at googlemail.com
Fri Mar 24 15:40:58 UTC 2017


Applied, thanks

On Fri, Mar 24, 2017 at 12:44 AM, Andrei Gherzan <andrei at gherzan.com> wrote:
> Busybox is very often used in initramfs at the end of which usually
> there is a switch_root to the actual rootfs. There are many cases where
> the console kernel argument is either just a placeholder (for example
> RaspberryPi uses serial0 and serial1) or configured as null to avoid any
> console messages - usually you would see such of a setup in production
> environments.
>
> Currently busybox bails out if can't open the console argument. If this
> happenes in initramfs and if the console=null for example, you get in a
> blind kernel panic. Avoid this by checking if the console exists and if
> not warn and continue.
>
> Signed-off-by: Andrei Gherzan <andrei at gherzan.com>
> ---
>  util-linux/switch_root.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c
> index 6034485d7..a39ec0ba7 100644
> --- a/util-linux/switch_root.c
> +++ b/util-linux/switch_root.c
> @@ -39,6 +39,7 @@
>
>  #include <sys/vfs.h>
>  #include <sys/mount.h>
> +#include <unistd.h>
>  #include "libbb.h"
>  // Make up for header deficiencies
>  #ifndef RAMFS_MAGIC
> @@ -140,12 +141,14 @@ int switch_root_main(int argc UNUSED_PARAM, char **argv)
>         /*xchdir("/"); - done in xchroot */
>
>         // If a new console specified, redirect stdin/stdout/stderr to it
> -       if (console) {
> -               close(0);
> -               xopen(console, O_RDWR);
> -               xdup2(0, 1);
> -               xdup2(0, 2);
> -       }
> +       if (console)
> +               if (access(console, F_OK)) {
> +                       close(0);
> +                       xopen(console, O_RDWR);
> +                       xdup2(0, 1);
> +                       xdup2(0, 2);
> +               } else
> +                       bb_error_msg("specified console doesn't exist, ignoring");
>
>         // Exec real init
>         execv(argv[0], argv);
> --
> 2.12.0
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox


More information about the busybox mailing list