linux-embedded.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] init: make init failures more explicit
@ 2013-10-18  8:47 Michael Opdenacker
  2013-10-18  9:01 ` Kieran Bingham
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Michael Opdenacker @ 2013-10-18  8:47 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, linux-embedded, Michael Opdenacker

This patch proposes to make init failures more explicit.

Before this, the "No init found" message didn't help much.
It could sometimes be misleading and actually mean
"No *working* init found".

This message could hide many different issues:
- no init program candidates found at all
- some init program candidates exist but can't be executed
  (missing execute permissions, failed to load shared libraries,
  executable compiled for an unknown architecture...)

This patch notifies the kernel user when a candidate
init program is found but can't be executed. It also replaces
"No init found" by "No working init found", which is more correct.

This will help embedded Linux developers (especially the new comers),
regularly making and debugging new root filesystems.

Signed-off-by: Michael Opdenacker <michael.opdenacker@free-electrons.com>
---
 init/main.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/init/main.c b/init/main.c
index 63d3e8f..a9a2833 100644
--- a/init/main.c
+++ b/init/main.c
@@ -811,6 +811,20 @@ static int run_init_process(const char *init_filename)
 		(const char __user *const __user *)envp_init);
 }
 
+static int try_to_run_init_process(const char *init_filename)
+{
+	int ret;
+
+	ret = run_init_process(init_filename);
+
+	if (ret && ret != -ENOENT) {
+		pr_err("Starting init: %s exists but couldn't execute it\n",
+		       init_filename);
+	}
+
+	return ret;
+}
+
 static noinline void __init kernel_init_freeable(void);
 
 static int __ref kernel_init(void *unused)
@@ -843,13 +857,13 @@ static int __ref kernel_init(void *unused)
 		pr_err("Failed to execute %s.  Attempting defaults...\n",
 			execute_command);
 	}
-	if (!run_init_process("/sbin/init") ||
-	    !run_init_process("/etc/init") ||
-	    !run_init_process("/bin/init") ||
-	    !run_init_process("/bin/sh"))
+	if (!try_to_run_init_process("/sbin/init") ||
+	    !try_to_run_init_process("/etc/init") ||
+	    !try_to_run_init_process("/bin/init") ||
+	    !try_to_run_init_process("/bin/sh"))
 		return 0;
 
-	panic("No init found.  Try passing init= option to kernel. "
+	panic("No working init found.  Try passing init= option to kernel. "
 	      "See Linux Documentation/init.txt for guidance.");
 }
 
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] init: make init failures more explicit
  2013-10-18  8:47 [PATCH] init: make init failures more explicit Michael Opdenacker
@ 2013-10-18  9:01 ` Kieran Bingham
  2013-10-18  9:23 ` Geert Uytterhoeven
  2013-10-18  9:31 ` Janne Karhunen
  2 siblings, 0 replies; 5+ messages in thread
From: Kieran Bingham @ 2013-10-18  9:01 UTC (permalink / raw)
  To: Michael Opdenacker; +Cc: akpm, linux-kernel, linux-embedded

Fantastic

I've been hurt by this in the past
 - and this patch would certainly would have helped save some time!

--
Kieran

On 18 October 2013 09:47, Michael Opdenacker
<michael.opdenacker@free-electrons.com> wrote:
> This patch proposes to make init failures more explicit.
>
> Before this, the "No init found" message didn't help much.
> It could sometimes be misleading and actually mean
> "No *working* init found".
>
> This message could hide many different issues:
> - no init program candidates found at all
> - some init program candidates exist but can't be executed
>   (missing execute permissions, failed to load shared libraries,
>   executable compiled for an unknown architecture...)
>
> This patch notifies the kernel user when a candidate
> init program is found but can't be executed. It also replaces
> "No init found" by "No working init found", which is more correct.
>
> This will help embedded Linux developers (especially the new comers),
> regularly making and debugging new root filesystems.
>
> Signed-off-by: Michael Opdenacker <michael.opdenacker@free-electrons.com>
> ---
>  init/main.c | 24 +++++++++++++++++++-----
>  1 file changed, 19 insertions(+), 5 deletions(-)
>
> diff --git a/init/main.c b/init/main.c
> index 63d3e8f..a9a2833 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -811,6 +811,20 @@ static int run_init_process(const char *init_filename)
>                 (const char __user *const __user *)envp_init);
>  }
>
> +static int try_to_run_init_process(const char *init_filename)
> +{
> +       int ret;
> +
> +       ret = run_init_process(init_filename);
> +
> +       if (ret && ret != -ENOENT) {
> +               pr_err("Starting init: %s exists but couldn't execute it\n",
> +                      init_filename);
> +       }
> +
> +       return ret;
> +}
> +
>  static noinline void __init kernel_init_freeable(void);
>
>  static int __ref kernel_init(void *unused)
> @@ -843,13 +857,13 @@ static int __ref kernel_init(void *unused)
>                 pr_err("Failed to execute %s.  Attempting defaults...\n",
>                         execute_command);
>         }
> -       if (!run_init_process("/sbin/init") ||
> -           !run_init_process("/etc/init") ||
> -           !run_init_process("/bin/init") ||
> -           !run_init_process("/bin/sh"))
> +       if (!try_to_run_init_process("/sbin/init") ||
> +           !try_to_run_init_process("/etc/init") ||
> +           !try_to_run_init_process("/bin/init") ||
> +           !try_to_run_init_process("/bin/sh"))
>                 return 0;
>
> -       panic("No init found.  Try passing init= option to kernel. "
> +       panic("No working init found.  Try passing init= option to kernel. "
>               "See Linux Documentation/init.txt for guidance.");
>  }
>
> --
> 1.8.1.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] init: make init failures more explicit
  2013-10-18  8:47 [PATCH] init: make init failures more explicit Michael Opdenacker
  2013-10-18  9:01 ` Kieran Bingham
@ 2013-10-18  9:23 ` Geert Uytterhoeven
  2013-10-18  9:32   ` Michael Opdenacker
  2013-10-18  9:31 ` Janne Karhunen
  2 siblings, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2013-10-18  9:23 UTC (permalink / raw)
  To: Michael Opdenacker
  Cc: Andrew Morton, linux-kernel@vger.kernel.org, Linux Embedded

On Fri, Oct 18, 2013 at 10:47 AM, Michael Opdenacker
<michael.opdenacker@free-electrons.com> wrote:
> +       if (ret && ret != -ENOENT) {
> +               pr_err("Starting init: %s exists but couldn't execute it\n",

I think it makes sense to also print the value of ret here.
Apart from your -ENOEXEC case, peeking a bit around, it can be also be
-EINVAL, -ENOMEM (debug binary too big for small embedded system?),
-EACCES, -E2BIG, ...

> +                      init_filename);
> +       }

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] init: make init failures more explicit
  2013-10-18  8:47 [PATCH] init: make init failures more explicit Michael Opdenacker
  2013-10-18  9:01 ` Kieran Bingham
  2013-10-18  9:23 ` Geert Uytterhoeven
@ 2013-10-18  9:31 ` Janne Karhunen
  2 siblings, 0 replies; 5+ messages in thread
From: Janne Karhunen @ 2013-10-18  9:31 UTC (permalink / raw)
  To: Michael Opdenacker; +Cc: akpm, Linux Kernel Mailing List, linux-embedded

On Fri, Oct 18, 2013 at 11:47 AM, Michael Opdenacker
<michael.opdenacker@free-electrons.com> wrote:

> This patch proposes to make init failures more explicit.
>
> Before this, the "No init found" message didn't help much.
> It could sometimes be misleading and actually mean
> "No *working* init found".

Heh, I was just looking at similar thing, except in my case dumping
out the execve error code would be the key (now I'm getting -ENOEXEC
back from init exec for no obvious reason). In case something like
this is getting merged I'd appreciate -errno dump as well.

diff --git a/init/main.c b/init/main.c
index 63d3e8f..56fb84a 100644
--- a/init/main.c
+++ b/init/main.c
@@ -815,6 +815,8 @@ static noinline void __init kernel_init_freeable(void);

 static int __ref kernel_init(void *unused)
 {
+       int err;
+
        kernel_init_freeable();
        /* need to finish all async __init code before freeing the memory */
        async_synchronize_full();
@@ -826,9 +828,11 @@ static int __ref kernel_init(void *unused)
        flush_delayed_fput();

        if (ramdisk_execute_command) {
-               if (!run_init_process(ramdisk_execute_command))
+               err = run_init_process(ramdisk_execute_command);
+               if (!err)
                        return 0;
-               pr_err("Failed to execute %s\n", ramdisk_execute_command);
+               pr_err("Failed to execute %s, error: %d\n",
+                       ramdisk_execute_command, err);
        }

        /*
@@ -838,10 +842,12 @@ static int __ref kernel_init(void *unused)
         * trying to recover a really broken machine.
         */
        if (execute_command) {
-               if (!run_init_process(execute_command))
+               err = run_init_process(execute_command);
+               if (!err)
                        return 0;
-               pr_err("Failed to execute %s.  Attempting defaults...\n",
-                       execute_command);
+               pr_err("Failed to execute %s, error: %d\n",
+                       execute_command, err);
+               pr_err("Attempting defaults...\n");
        }
        if (!run_init_process("/sbin/init") ||
            !run_init_process("/etc/init") ||




-- 
Janne

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] init: make init failures more explicit
  2013-10-18  9:23 ` Geert Uytterhoeven
@ 2013-10-18  9:32   ` Michael Opdenacker
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Opdenacker @ 2013-10-18  9:32 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Andrew Morton, linux-kernel@vger.kernel.org, Linux Embedded

Hi Geert,

On 10/18/2013 11:23 AM, Geert Uytterhoeven wrote:
> On Fri, Oct 18, 2013 at 10:47 AM, Michael Opdenacker
> <michael.opdenacker@free-electrons.com> wrote:
>> +       if (ret && ret != -ENOENT) {
>> +               pr_err("Starting init: %s exists but couldn't execute it\n",
> I think it makes sense to also print the value of ret here.
> Apart from your -ENOEXEC case, peeking a bit around, it can be also be
> -EINVAL, -ENOMEM (debug binary too big for small embedded system?),
> -EACCES, -E2BIG, ...
I agree. It would definitely make sense. I'll propose a new version.

Many thanks!

Cheers,

Michael.

-- 
Michael Opdenacker, CEO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
+33 484 258 098

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-10-18  9:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-18  8:47 [PATCH] init: make init failures more explicit Michael Opdenacker
2013-10-18  9:01 ` Kieran Bingham
2013-10-18  9:23 ` Geert Uytterhoeven
2013-10-18  9:32   ` Michael Opdenacker
2013-10-18  9:31 ` Janne Karhunen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).