public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Standardize shutdown of the system from enviroment control modules
@ 2005-08-09 21:10 Christoph Hellwig
  2005-08-09 21:25 ` Greg Howard
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Christoph Hellwig @ 2005-08-09 21:10 UTC (permalink / raw)
  To: Greg Howard, davem; +Cc: linux-kernel

Currently snsc_event for Altix systems sends SIGPWR to init (and abuses
tasklist_lock..) while the sbus drivers call execve for /sbin/shutdown
(which is also ugly, it should at least use call_usermodehelper)
With normal sysvinit both will end up the same, but I suspect the
shutdown variant, maybe with a sysctl to chose the exact path to call
would be cleaner.  What do you guys think about adding a common function
to do this.  Could you test such a patch for me?

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

* Re: Standardize shutdown of the system from enviroment control modules
  2005-08-09 21:10 Standardize shutdown of the system from enviroment control modules Christoph Hellwig
@ 2005-08-09 21:25 ` Greg Howard
  2005-08-09 21:36   ` Standardize shutdown of the system from enviroment control Aaron Young
  2005-08-11 12:10 ` Standardize shutdown of the system from enviroment control modules Pavel Machek
  2005-08-11 17:37 ` [PATCH, RFC] " Christoph Hellwig
  2 siblings, 1 reply; 8+ messages in thread
From: Greg Howard @ 2005-08-09 21:25 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: davem, LKML, Aaron Young


On Tue, 9 Aug 2005, Christoph Hellwig wrote:

> Currently snsc_event for Altix systems sends SIGPWR to init (and abuses
> tasklist_lock..) while the sbus drivers call execve for /sbin/shutdown
> (which is also ugly, it should at least use call_usermodehelper)
> With normal sysvinit both will end up the same, but I suspect the
> shutdown variant, maybe with a sysctl to chose the exact path to call
> would be cleaner.  What do you guys think about adding a common function
> to do this.

Sounds reasonable to me.  I'll copy Aaron Young, who I think
actually wrote the code to send the SIGPWR, in case he had a Good
Reason for doing it this way.  (Aaron, if I'm remembering wrong
and you're not the guy who wrote this, let me know...)

> Could you test such a patch for me?

Sure.  I'll need to get hold of some hardware/firmware that will
reproduce a critical environmental situation...  Might take a
litte while...

Thanks

--
Greg Howard, MTS - Core Platform SW     MS 10-1-061
SGI - Silicon Graphics Inc.             2750 Blue Water Road
ghoward@sgi.com                         Eagan, MN  55121

+--------------------------------------------------------------------+
  "This assignment has two parts: a hard part, and an easy part.  Do
   the easy part first; you might learn something that will help you
   on the hard part.  Or, maybe you'll go outside for a walk before
   you start the hard part, and get hit by a truck!"
                                        - Dr. Jeffrey W. Smith
+--------------------------------------------------------------------+

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

* Re: Standardize shutdown of the system from enviroment control
  2005-08-09 21:25 ` Greg Howard
@ 2005-08-09 21:36   ` Aaron Young
  0 siblings, 0 replies; 8+ messages in thread
From: Aaron Young @ 2005-08-09 21:36 UTC (permalink / raw)
  To: Greg Howard; +Cc: Christoph Hellwig, davem, LKML, Aaron Young

> 
> 
> On Tue, 9 Aug 2005, Christoph Hellwig wrote:
> 
> > Currently snsc_event for Altix systems sends SIGPWR to init (and abuses
> > tasklist_lock..) while the sbus drivers call execve for /sbin/shutdown
> > (which is also ugly, it should at least use call_usermodehelper)
> > With normal sysvinit both will end up the same, but I suspect the
> > shutdown variant, maybe with a sysctl to chose the exact path to call
> > would be cleaner.  What do you guys think about adding a common function
> > to do this.
> 
> Sounds reasonable to me.  I'll copy Aaron Young, who I think
> actually wrote the code to send the SIGPWR, in case he had a Good
> Reason for doing it this way.  (Aaron, if I'm remembering wrong
> and you're not the guy who wrote this, let me know...)

  Yep, that was me. I couldn't really find a better way to do it at
  the time. An 'execve shutdown' probably would have been better in retrospect
  because I think sending SIGPWR to init doesn't always shutdown the machine.
  It depends on how some config files are setup (inittab, powerfail).
  I'd rather not depend on any config files and just force a shutdown/poweroff.

> 
> > Could you test such a patch for me?
> 
> Sure.  I'll need to get hold of some hardware/firmware that will
> reproduce a critical environmental situation...  Might take a
> litte while...

 Testing should be easy - on a Deskside Prism system, just hit the
 power button while up at Linux.

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

* Re: Standardize shutdown of the system from enviroment control modules
  2005-08-09 21:10 Standardize shutdown of the system from enviroment control modules Christoph Hellwig
  2005-08-09 21:25 ` Greg Howard
@ 2005-08-11 12:10 ` Pavel Machek
  2005-08-11 17:37 ` [PATCH, RFC] " Christoph Hellwig
  2 siblings, 0 replies; 8+ messages in thread
From: Pavel Machek @ 2005-08-11 12:10 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Greg Howard, davem, linux-kernel

Hi!

> Currently snsc_event for Altix systems sends SIGPWR to init (and abuses
> tasklist_lock..) while the sbus drivers call execve for /sbin/shutdown
> (which is also ugly, it should at least use call_usermodehelper)
> With normal sysvinit both will end up the same, but I suspect the
> shutdown variant, maybe with a sysctl to chose the exact path to call
> would be cleaner.  What do you guys think about adding a common function
> to do this.  Could you test such a patch for me?

ACPI does some exec (in thermal), too. Yes, I think it is worth
standartizing. Easy to test, btw, just echo too low trippoints.

								Pavel
-- 
if you have sharp zaurus hardware you don't need... you know my address

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

* [PATCH, RFC] Standardize shutdown of the system from enviroment control modules
  2005-08-09 21:10 Standardize shutdown of the system from enviroment control modules Christoph Hellwig
  2005-08-09 21:25 ` Greg Howard
  2005-08-11 12:10 ` Standardize shutdown of the system from enviroment control modules Pavel Machek
@ 2005-08-11 17:37 ` Christoph Hellwig
  2005-08-26 11:44   ` Christoph Hellwig
  2 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2005-08-11 17:37 UTC (permalink / raw)
  To: Greg Howard, davem; +Cc: linux-kernel

On Tue, Aug 09, 2005 at 11:10:03PM +0200, Christoph Hellwig wrote:
> Currently snsc_event for Altix systems sends SIGPWR to init (and abuses
> tasklist_lock..) while the sbus drivers call execve for /sbin/shutdown
> (which is also ugly, it should at least use call_usermodehelper)
> With normal sysvinit both will end up the same, but I suspect the
> shutdown variant, maybe with a sysctl to chose the exact path to call
> would be cleaner.  What do you guys think about adding a common function
> to do this.  Could you test such a patch for me?

Okay, here's such a patch, I've also switched the SN and the two sbus
drivers over.


Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: linux-2.6/drivers/char/snsc_event.c
===================================================================
--- linux-2.6.orig/drivers/char/snsc_event.c	2005-08-11 16:45:55.000000000 +0200
+++ linux-2.6/drivers/char/snsc_event.c	2005-08-11 19:03:59.000000000 +0200
@@ -195,24 +195,7 @@
 	severity = scdrv_event_severity(code);
 
 	if ((code & EV_CLASS_MASK) == EV_CLASS_PWRD_NOTIFY) {
-		struct task_struct *p;
-
-		/* give a SIGPWR signal to init proc */
-
-		/* first find init's task */
-		read_lock(&tasklist_lock);
-		for_each_process(p) {
-			if (p->pid == 1)
-				break;
-		}
-		if (p) { /* we found init's task */
-			printk(KERN_EMERG "Power off indication received. Initiating power fail sequence...\n");
-			force_sig(SIGPWR, p);
-		} else { /* failed to find init's task - just give message(s) */
-			printk(KERN_WARNING "Failed to find init proc to handle power off!\n");
-			printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
-		}
-		read_unlock(&tasklist_lock);
+		envctrl_do_shutdown();
 	} else {
 		/* print to system log */
 		printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
Index: linux-2.6/drivers/sbus/char/bbc_envctrl.c
===================================================================
--- linux-2.6.orig/drivers/sbus/char/bbc_envctrl.c	2005-08-11 16:45:59.000000000 +0200
+++ linux-2.6/drivers/sbus/char/bbc_envctrl.c	2005-08-11 19:01:44.000000000 +0200
@@ -4,13 +4,12 @@
  * Copyright (C) 2001 David S. Miller (davem@redhat.com)
  */
 
-#define __KERNEL_SYSCALLS__
-
 #include <linux/kernel.h>
 #include <linux/kthread.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
+#include <linux/envctrl.h>
 #include <asm/oplib.h>
 #include <asm/ebus.h>
 static int errno;
@@ -176,8 +175,6 @@
 static void do_envctrl_shutdown(struct bbc_cpu_temperature *tp)
 {
 	static int shutting_down = 0;
-	static char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
-	char *argv[] = { "/sbin/shutdown", "-h", "now", NULL };
 	char *type = "???";
 	s8 val = -1;
 
@@ -201,8 +198,8 @@
 	printk(KERN_CRIT "kenvctrld: Shutting down the system now.\n");
 
 	shutting_down = 1;
-	if (execve("/sbin/shutdown", argv, envp) < 0)
-		printk(KERN_CRIT "envctrl: shutdown execution failed\n");
+
+	envctrl_do_shutdown();
 }
 
 #define WARN_INTERVAL	(30 * HZ)
Index: linux-2.6/drivers/sbus/char/envctrl.c
===================================================================
--- linux-2.6.orig/drivers/sbus/char/envctrl.c	2005-08-11 16:45:59.000000000 +0200
+++ linux-2.6/drivers/sbus/char/envctrl.c	2005-08-11 19:01:57.000000000 +0200
@@ -19,8 +19,6 @@
  *              Daniele Bellucci <bellucda@tiscali.it>
  */
 
-#define __KERNEL_SYSCALLS__
-
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/sched.h>
@@ -33,6 +31,7 @@
 #include <linux/mm.h>
 #include <linux/slab.h>
 #include <linux/kernel.h>
+#include <linux/envctrl.h>
 
 #include <asm/ebus.h>
 #include <asm/uaccess.h>
@@ -975,25 +974,6 @@
 	return NULL;
 }
 
-static void envctrl_do_shutdown(void)
-{
-	static int inprog = 0;
-	static char *envp[] = {	
-		"HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
-	char *argv[] = { 
-		"/sbin/shutdown", "-h", "now", NULL };	
-
-	if (inprog != 0)
-		return;
-
-	inprog = 1;
-	printk(KERN_CRIT "kenvctrld: WARNING: Shutting down the system now.\n");
-	if (0 > execve("/sbin/shutdown", argv, envp)) {
-		printk(KERN_CRIT "kenvctrld: WARNING: system shutdown failed!\n"); 
-		inprog = 0;  /* unlikely to succeed, but we could try again */
-	}
-}
-
 static struct task_struct *kenvctrld_task;
 
 static int kenvctrld(void *__unused)
Index: linux-2.6/include/linux/envctrl.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/include/linux/envctrl.h	2005-08-11 18:58:41.000000000 +0200
@@ -0,0 +1,6 @@
+#ifndef _LINUX_ENVCTRL_H
+#define _LINUX_ENVCTRL_H
+
+extern int envctrl_do_shutdown(void);
+
+#endif /* _LINUX_ENVCTRL_H */
Index: linux-2.6/kernel/Makefile
===================================================================
--- linux-2.6.orig/kernel/Makefile	2005-08-11 16:46:07.000000000 +0200
+++ linux-2.6/kernel/Makefile	2005-08-11 18:57:57.000000000 +0200
@@ -7,7 +7,7 @@
 	    sysctl.o capability.o ptrace.o timer.o user.o \
 	    signal.o sys.o kmod.o workqueue.o pid.o \
 	    rcupdate.o intermodule.o extable.o params.o posix-timers.o \
-	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o
+	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o envctrl.o
 
 obj-$(CONFIG_FUTEX) += futex.o
 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
Index: linux-2.6/kernel/envctrl.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/kernel/envctrl.c	2005-08-11 19:04:19.000000000 +0200
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2001 David S. Miller.
+ * Copyright (C) 2005 Christoph Hellwig.
+ *	Released under GPL v2.
+ *
+ * Common code to shutdown the system when overheating.
+ */
+
+#include <linux/envctrl.h>
+#include <linux/kernel.h>
+#include <linux/kmod.h>
+
+static char *envp[] = {
+	"HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL
+};
+
+static char *argv[] = {
+	"/sbin/shutdown", "-h", "now", NULL
+};
+
+/*
+ * envctrl_do_shutdown  -  shut the system down when overheating
+ *
+ * Common routine to be called from all enviromental monitoring
+ * drivers when a fatal overheating is detected.
+ *
+ * Returns 0 if /sbin/shutdown has been called sucessfully, 1 if
+ * this routine has been called already but the kernel is still
+ * running or a negative error value if executing the shutdown
+ * command failed.
+ */
+int envctrl_do_shutdown(void)
+{
+	static int shutting_down = 0;
+	int error;
+
+	if (shutting_down)
+		return 1;
+	shutting_down = 1;
+
+	printk(KERN_CRIT "envctrl: WARNING: Shutting down the system now.\n");
+	error = call_usermodehelper("/sbin/shutdown", argv, envp, 0);
+	if (error)
+		printk(KERN_CRIT "envctrl: WARNING: system shutdown failed!\n");
+	return error;
+}

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

* Re: [PATCH, RFC] Standardize shutdown of the system from enviroment control modules
  2005-08-11 17:37 ` [PATCH, RFC] " Christoph Hellwig
@ 2005-08-26 11:44   ` Christoph Hellwig
  2005-08-26 12:22     ` Greg Howard
  0 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2005-08-26 11:44 UTC (permalink / raw)
  To: Greg Howard, davem; +Cc: linux-kernel

On Thu, Aug 11, 2005 at 07:37:17PM +0200, Christoph Hellwig wrote:
> On Tue, Aug 09, 2005 at 11:10:03PM +0200, Christoph Hellwig wrote:
> > Currently snsc_event for Altix systems sends SIGPWR to init (and abuses
> > tasklist_lock..) while the sbus drivers call execve for /sbin/shutdown
> > (which is also ugly, it should at least use call_usermodehelper)
> > With normal sysvinit both will end up the same, but I suspect the
> > shutdown variant, maybe with a sysctl to chose the exact path to call
> > would be cleaner.  What do you guys think about adding a common function
> > to do this.  Could you test such a patch for me?
> 
> Okay, here's such a patch, I've also switched the SN and the two sbus
> drivers over.

ping?

>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> 
> Index: linux-2.6/drivers/char/snsc_event.c
> ===================================================================
> --- linux-2.6.orig/drivers/char/snsc_event.c	2005-08-11 16:45:55.000000000 +0200
> +++ linux-2.6/drivers/char/snsc_event.c	2005-08-11 19:03:59.000000000 +0200
> @@ -195,24 +195,7 @@
>  	severity = scdrv_event_severity(code);
>  
>  	if ((code & EV_CLASS_MASK) == EV_CLASS_PWRD_NOTIFY) {
> -		struct task_struct *p;
> -
> -		/* give a SIGPWR signal to init proc */
> -
> -		/* first find init's task */
> -		read_lock(&tasklist_lock);
> -		for_each_process(p) {
> -			if (p->pid == 1)
> -				break;
> -		}
> -		if (p) { /* we found init's task */
> -			printk(KERN_EMERG "Power off indication received. Initiating power fail sequence...\n");
> -			force_sig(SIGPWR, p);
> -		} else { /* failed to find init's task - just give message(s) */
> -			printk(KERN_WARNING "Failed to find init proc to handle power off!\n");
> -			printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
> -		}
> -		read_unlock(&tasklist_lock);
> +		envctrl_do_shutdown();
>  	} else {
>  		/* print to system log */
>  		printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
> Index: linux-2.6/drivers/sbus/char/bbc_envctrl.c
> ===================================================================
> --- linux-2.6.orig/drivers/sbus/char/bbc_envctrl.c	2005-08-11 16:45:59.000000000 +0200
> +++ linux-2.6/drivers/sbus/char/bbc_envctrl.c	2005-08-11 19:01:44.000000000 +0200
> @@ -4,13 +4,12 @@
>   * Copyright (C) 2001 David S. Miller (davem@redhat.com)
>   */
>  
> -#define __KERNEL_SYSCALLS__
> -
>  #include <linux/kernel.h>
>  #include <linux/kthread.h>
>  #include <linux/sched.h>
>  #include <linux/slab.h>
>  #include <linux/delay.h>
> +#include <linux/envctrl.h>
>  #include <asm/oplib.h>
>  #include <asm/ebus.h>
>  static int errno;
> @@ -176,8 +175,6 @@
>  static void do_envctrl_shutdown(struct bbc_cpu_temperature *tp)
>  {
>  	static int shutting_down = 0;
> -	static char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
> -	char *argv[] = { "/sbin/shutdown", "-h", "now", NULL };
>  	char *type = "???";
>  	s8 val = -1;
>  
> @@ -201,8 +198,8 @@
>  	printk(KERN_CRIT "kenvctrld: Shutting down the system now.\n");
>  
>  	shutting_down = 1;
> -	if (execve("/sbin/shutdown", argv, envp) < 0)
> -		printk(KERN_CRIT "envctrl: shutdown execution failed\n");
> +
> +	envctrl_do_shutdown();
>  }
>  
>  #define WARN_INTERVAL	(30 * HZ)
> Index: linux-2.6/drivers/sbus/char/envctrl.c
> ===================================================================
> --- linux-2.6.orig/drivers/sbus/char/envctrl.c	2005-08-11 16:45:59.000000000 +0200
> +++ linux-2.6/drivers/sbus/char/envctrl.c	2005-08-11 19:01:57.000000000 +0200
> @@ -19,8 +19,6 @@
>   *              Daniele Bellucci <bellucda@tiscali.it>
>   */
>  
> -#define __KERNEL_SYSCALLS__
> -
>  #include <linux/config.h>
>  #include <linux/module.h>
>  #include <linux/sched.h>
> @@ -33,6 +31,7 @@
>  #include <linux/mm.h>
>  #include <linux/slab.h>
>  #include <linux/kernel.h>
> +#include <linux/envctrl.h>
>  
>  #include <asm/ebus.h>
>  #include <asm/uaccess.h>
> @@ -975,25 +974,6 @@
>  	return NULL;
>  }
>  
> -static void envctrl_do_shutdown(void)
> -{
> -	static int inprog = 0;
> -	static char *envp[] = {	
> -		"HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
> -	char *argv[] = { 
> -		"/sbin/shutdown", "-h", "now", NULL };	
> -
> -	if (inprog != 0)
> -		return;
> -
> -	inprog = 1;
> -	printk(KERN_CRIT "kenvctrld: WARNING: Shutting down the system now.\n");
> -	if (0 > execve("/sbin/shutdown", argv, envp)) {
> -		printk(KERN_CRIT "kenvctrld: WARNING: system shutdown failed!\n"); 
> -		inprog = 0;  /* unlikely to succeed, but we could try again */
> -	}
> -}
> -
>  static struct task_struct *kenvctrld_task;
>  
>  static int kenvctrld(void *__unused)
> Index: linux-2.6/include/linux/envctrl.h
> ===================================================================
> --- /dev/null	1970-01-01 00:00:00.000000000 +0000
> +++ linux-2.6/include/linux/envctrl.h	2005-08-11 18:58:41.000000000 +0200
> @@ -0,0 +1,6 @@
> +#ifndef _LINUX_ENVCTRL_H
> +#define _LINUX_ENVCTRL_H
> +
> +extern int envctrl_do_shutdown(void);
> +
> +#endif /* _LINUX_ENVCTRL_H */
> Index: linux-2.6/kernel/Makefile
> ===================================================================
> --- linux-2.6.orig/kernel/Makefile	2005-08-11 16:46:07.000000000 +0200
> +++ linux-2.6/kernel/Makefile	2005-08-11 18:57:57.000000000 +0200
> @@ -7,7 +7,7 @@
>  	    sysctl.o capability.o ptrace.o timer.o user.o \
>  	    signal.o sys.o kmod.o workqueue.o pid.o \
>  	    rcupdate.o intermodule.o extable.o params.o posix-timers.o \
> -	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o
> +	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o envctrl.o
>  
>  obj-$(CONFIG_FUTEX) += futex.o
>  obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
> Index: linux-2.6/kernel/envctrl.c
> ===================================================================
> --- /dev/null	1970-01-01 00:00:00.000000000 +0000
> +++ linux-2.6/kernel/envctrl.c	2005-08-11 19:04:19.000000000 +0200
> @@ -0,0 +1,46 @@
> +/*
> + * Copyright (C) 2001 David S. Miller.
> + * Copyright (C) 2005 Christoph Hellwig.
> + *	Released under GPL v2.
> + *
> + * Common code to shutdown the system when overheating.
> + */
> +
> +#include <linux/envctrl.h>
> +#include <linux/kernel.h>
> +#include <linux/kmod.h>
> +
> +static char *envp[] = {
> +	"HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL
> +};
> +
> +static char *argv[] = {
> +	"/sbin/shutdown", "-h", "now", NULL
> +};
> +
> +/*
> + * envctrl_do_shutdown  -  shut the system down when overheating
> + *
> + * Common routine to be called from all enviromental monitoring
> + * drivers when a fatal overheating is detected.
> + *
> + * Returns 0 if /sbin/shutdown has been called sucessfully, 1 if
> + * this routine has been called already but the kernel is still
> + * running or a negative error value if executing the shutdown
> + * command failed.
> + */
> +int envctrl_do_shutdown(void)
> +{
> +	static int shutting_down = 0;
> +	int error;
> +
> +	if (shutting_down)
> +		return 1;
> +	shutting_down = 1;
> +
> +	printk(KERN_CRIT "envctrl: WARNING: Shutting down the system now.\n");
> +	error = call_usermodehelper("/sbin/shutdown", argv, envp, 0);
> +	if (error)
> +		printk(KERN_CRIT "envctrl: WARNING: system shutdown failed!\n");
> +	return error;
> +}
---end quoted text---

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

* Re: [PATCH, RFC] Standardize shutdown of the system from enviroment control modules
  2005-08-26 11:44   ` Christoph Hellwig
@ 2005-08-26 12:22     ` Greg Howard
  2005-08-27 13:16       ` Denis Vlasenko
  0 siblings, 1 reply; 8+ messages in thread
From: Greg Howard @ 2005-08-26 12:22 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: davem, LKML, Aaron Young


On Fri, 26 Aug 2005, Christoph Hellwig wrote:

> On Thu, Aug 11, 2005 at 07:37:17PM +0200, Christoph Hellwig wrote:
> > On Tue, Aug 09, 2005 at 11:10:03PM +0200, Christoph Hellwig wrote:
> > > Currently snsc_event for Altix systems sends SIGPWR to init (and abuses
> > > tasklist_lock..) while the sbus drivers call execve for /sbin/shutdown
> > > (which is also ugly, it should at least use call_usermodehelper)
> > > With normal sysvinit both will end up the same, but I suspect the
> > > shutdown variant, maybe with a sysctl to chose the exact path to call
> > > would be cleaner.  What do you guys think about adding a common function
> > > to do this.  Could you test such a patch for me?
> >
> > Okay, here's such a patch, I've also switched the SN and the two sbus
> > drivers over.
>
> ping?

Hi Christoph,

Got your patch and built it into a kernel...  Ran into other
(unrelated) difficulties booting said kernel...  I'll see if I
can get that sorted out today and test drive it.

>From inspection I don't see any problem with the patch.

Thanks - Greg

>
> >
> > Signed-off-by: Christoph Hellwig <hch@lst.de>
> >
> > Index: linux-2.6/drivers/char/snsc_event.c
> > ===================================================================
> > --- linux-2.6.orig/drivers/char/snsc_event.c	2005-08-11 16:45:55.000000000 +0200
> > +++ linux-2.6/drivers/char/snsc_event.c	2005-08-11 19:03:59.000000000 +0200
> > @@ -195,24 +195,7 @@
> >  	severity = scdrv_event_severity(code);
> >
> >  	if ((code & EV_CLASS_MASK) == EV_CLASS_PWRD_NOTIFY) {
> > -		struct task_struct *p;
> > -
> > -		/* give a SIGPWR signal to init proc */
> > -
> > -		/* first find init's task */
> > -		read_lock(&tasklist_lock);
> > -		for_each_process(p) {
> > -			if (p->pid == 1)
> > -				break;
> > -		}
> > -		if (p) { /* we found init's task */
> > -			printk(KERN_EMERG "Power off indication received. Initiating power fail sequence...\n");
> > -			force_sig(SIGPWR, p);
> > -		} else { /* failed to find init's task - just give message(s) */
> > -			printk(KERN_WARNING "Failed to find init proc to handle power off!\n");
> > -			printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
> > -		}
> > -		read_unlock(&tasklist_lock);
> > +		envctrl_do_shutdown();
> >  	} else {
> >  		/* print to system log */
> >  		printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
> > Index: linux-2.6/drivers/sbus/char/bbc_envctrl.c
> > ===================================================================
> > --- linux-2.6.orig/drivers/sbus/char/bbc_envctrl.c	2005-08-11 16:45:59.000000000 +0200
> > +++ linux-2.6/drivers/sbus/char/bbc_envctrl.c	2005-08-11 19:01:44.000000000 +0200
> > @@ -4,13 +4,12 @@
> >   * Copyright (C) 2001 David S. Miller (davem@redhat.com)
> >   */
> >
> > -#define __KERNEL_SYSCALLS__
> > -
> >  #include <linux/kernel.h>
> >  #include <linux/kthread.h>
> >  #include <linux/sched.h>
> >  #include <linux/slab.h>
> >  #include <linux/delay.h>
> > +#include <linux/envctrl.h>
> >  #include <asm/oplib.h>
> >  #include <asm/ebus.h>
> >  static int errno;
> > @@ -176,8 +175,6 @@
> >  static void do_envctrl_shutdown(struct bbc_cpu_temperature *tp)
> >  {
> >  	static int shutting_down = 0;
> > -	static char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
> > -	char *argv[] = { "/sbin/shutdown", "-h", "now", NULL };
> >  	char *type = "???";
> >  	s8 val = -1;
> >
> > @@ -201,8 +198,8 @@
> >  	printk(KERN_CRIT "kenvctrld: Shutting down the system now.\n");
> >
> >  	shutting_down = 1;
> > -	if (execve("/sbin/shutdown", argv, envp) < 0)
> > -		printk(KERN_CRIT "envctrl: shutdown execution failed\n");
> > +
> > +	envctrl_do_shutdown();
> >  }
> >
> >  #define WARN_INTERVAL	(30 * HZ)
> > Index: linux-2.6/drivers/sbus/char/envctrl.c
> > ===================================================================
> > --- linux-2.6.orig/drivers/sbus/char/envctrl.c	2005-08-11 16:45:59.000000000 +0200
> > +++ linux-2.6/drivers/sbus/char/envctrl.c	2005-08-11 19:01:57.000000000 +0200
> > @@ -19,8 +19,6 @@
> >   *              Daniele Bellucci <bellucda@tiscali.it>
> >   */
> >
> > -#define __KERNEL_SYSCALLS__
> > -
> >  #include <linux/config.h>
> >  #include <linux/module.h>
> >  #include <linux/sched.h>
> > @@ -33,6 +31,7 @@
> >  #include <linux/mm.h>
> >  #include <linux/slab.h>
> >  #include <linux/kernel.h>
> > +#include <linux/envctrl.h>
> >
> >  #include <asm/ebus.h>
> >  #include <asm/uaccess.h>
> > @@ -975,25 +974,6 @@
> >  	return NULL;
> >  }
> >
> > -static void envctrl_do_shutdown(void)
> > -{
> > -	static int inprog = 0;
> > -	static char *envp[] = {
> > -		"HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
> > -	char *argv[] = {
> > -		"/sbin/shutdown", "-h", "now", NULL };
> > -
> > -	if (inprog != 0)
> > -		return;
> > -
> > -	inprog = 1;
> > -	printk(KERN_CRIT "kenvctrld: WARNING: Shutting down the system now.\n");
> > -	if (0 > execve("/sbin/shutdown", argv, envp)) {
> > -		printk(KERN_CRIT "kenvctrld: WARNING: system shutdown failed!\n");
> > -		inprog = 0;  /* unlikely to succeed, but we could try again */
> > -	}
> > -}
> > -
> >  static struct task_struct *kenvctrld_task;
> >
> >  static int kenvctrld(void *__unused)
> > Index: linux-2.6/include/linux/envctrl.h
> > ===================================================================
> > --- /dev/null	1970-01-01 00:00:00.000000000 +0000
> > +++ linux-2.6/include/linux/envctrl.h	2005-08-11 18:58:41.000000000 +0200
> > @@ -0,0 +1,6 @@
> > +#ifndef _LINUX_ENVCTRL_H
> > +#define _LINUX_ENVCTRL_H
> > +
> > +extern int envctrl_do_shutdown(void);
> > +
> > +#endif /* _LINUX_ENVCTRL_H */
> > Index: linux-2.6/kernel/Makefile
> > ===================================================================
> > --- linux-2.6.orig/kernel/Makefile	2005-08-11 16:46:07.000000000 +0200
> > +++ linux-2.6/kernel/Makefile	2005-08-11 18:57:57.000000000 +0200
> > @@ -7,7 +7,7 @@
> >  	    sysctl.o capability.o ptrace.o timer.o user.o \
> >  	    signal.o sys.o kmod.o workqueue.o pid.o \
> >  	    rcupdate.o intermodule.o extable.o params.o posix-timers.o \
> > -	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o
> > +	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o envctrl.o
> >
> >  obj-$(CONFIG_FUTEX) += futex.o
> >  obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
> > Index: linux-2.6/kernel/envctrl.c
> > ===================================================================
> > --- /dev/null	1970-01-01 00:00:00.000000000 +0000
> > +++ linux-2.6/kernel/envctrl.c	2005-08-11 19:04:19.000000000 +0200
> > @@ -0,0 +1,46 @@
> > +/*
> > + * Copyright (C) 2001 David S. Miller.
> > + * Copyright (C) 2005 Christoph Hellwig.
> > + *	Released under GPL v2.
> > + *
> > + * Common code to shutdown the system when overheating.
> > + */
> > +
> > +#include <linux/envctrl.h>
> > +#include <linux/kernel.h>
> > +#include <linux/kmod.h>
> > +
> > +static char *envp[] = {
> > +	"HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL
> > +};
> > +
> > +static char *argv[] = {
> > +	"/sbin/shutdown", "-h", "now", NULL
> > +};
> > +
> > +/*
> > + * envctrl_do_shutdown  -  shut the system down when overheating
> > + *
> > + * Common routine to be called from all enviromental monitoring
> > + * drivers when a fatal overheating is detected.
> > + *
> > + * Returns 0 if /sbin/shutdown has been called sucessfully, 1 if
> > + * this routine has been called already but the kernel is still
> > + * running or a negative error value if executing the shutdown
> > + * command failed.
> > + */
> > +int envctrl_do_shutdown(void)
> > +{
> > +	static int shutting_down = 0;
> > +	int error;
> > +
> > +	if (shutting_down)
> > +		return 1;
> > +	shutting_down = 1;
> > +
> > +	printk(KERN_CRIT "envctrl: WARNING: Shutting down the system now.\n");
> > +	error = call_usermodehelper("/sbin/shutdown", argv, envp, 0);
> > +	if (error)
> > +		printk(KERN_CRIT "envctrl: WARNING: system shutdown failed!\n");
> > +	return error;
> > +}
> ---end quoted text---
>


--
Greg Howard, MTS - Core Platform SW     MS 10-1-061
SGI - Silicon Graphics Inc.             2750 Blue Water Road
ghoward@sgi.com                         Eagan, MN  55121

+----------------------------------------------------------+
  "Who am I to smudge the palette of conventional wisdom?"
					- John Brocato
+----------------------------------------------------------+

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

* Re: [PATCH, RFC] Standardize shutdown of the system from enviroment control modules
  2005-08-26 12:22     ` Greg Howard
@ 2005-08-27 13:16       ` Denis Vlasenko
  0 siblings, 0 replies; 8+ messages in thread
From: Denis Vlasenko @ 2005-08-27 13:16 UTC (permalink / raw)
  To: Greg Howard; +Cc: Christoph Hellwig, davem, LKML, Aaron Young

> > > > Currently snsc_event for Altix systems sends SIGPWR to init (and
> > > > abuses tasklist_lock..) while the sbus drivers call execve for
> > > > /sbin/shutdown (which is also ugly, it should at least use
> > > > call_usermodehelper) With normal sysvinit both will end up the same,
> > > > but I suspect the shutdown variant, maybe with a sysctl to chose the
> > > > exact path to call would be cleaner.  What do you guys think about

sysctl is indeed would be nice. Paranoid users may insist on having
freedom not to have /sbin at all.

> > > > adding a common function to do this.  Could you test such a patch for
> > > > me?
> > >
> > > Okay, here's such a patch, I've also switched the SN and the two sbus
> > > drivers over.
> >
> > ping?
>
> Hi Christoph,
>
> Got your patch and built it into a kernel...  Ran into other
> (unrelated) difficulties booting said kernel...  I'll see if I
> can get that sorted out today and test drive it.
>
> From inspection I don't see any problem with the patch.
>
> Thanks - Greg

[snip]

> > > +/*
> > > + * envctrl_do_shutdown  -  shut the system down when overheating
> > > + *
> > > + * Common routine to be called from all enviromental monitoring
> > > + * drivers when a fatal overheating is detected.
> > > + *
> > > + * Returns 0 if /sbin/shutdown has been called sucessfully, 1 if
> > > + * this routine has been called already but the kernel is still
> > > + * running or a negative error value if executing the shutdown
> > > + * command failed.
> > > + */
> > > +int envctrl_do_shutdown(void)
> > > +{
> > > +	static int shutting_down = 0;
> > > +	int error;
> > > +
> > > +	if (shutting_down)
> > > +		return 1;
> > > +	shutting_down = 1;
> > > +
> > > +	printk(KERN_CRIT "envctrl: WARNING: Shutting down the system now.\n");
> > > +	error = call_usermodehelper("/sbin/shutdown", argv, envp, 0);
> > > +	if (error) 
> > > +		printk(KERN_CRIT "envctrl: WARNING: system shutdown failed!\n");
> > > +	return error;
> > > +}
--
vda

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

end of thread, other threads:[~2005-08-27 13:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-09 21:10 Standardize shutdown of the system from enviroment control modules Christoph Hellwig
2005-08-09 21:25 ` Greg Howard
2005-08-09 21:36   ` Standardize shutdown of the system from enviroment control Aaron Young
2005-08-11 12:10 ` Standardize shutdown of the system from enviroment control modules Pavel Machek
2005-08-11 17:37 ` [PATCH, RFC] " Christoph Hellwig
2005-08-26 11:44   ` Christoph Hellwig
2005-08-26 12:22     ` Greg Howard
2005-08-27 13:16       ` Denis Vlasenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox