diff options
author | Jeremy Fitzhardinge <jeremy@xensource.com> | 2007-07-17 21:37:02 -0400 |
---|---|---|
committer | Jeremy Fitzhardinge <jeremy@goop.org> | 2007-07-18 11:47:40 -0400 |
commit | 10a0a8d4e3f6bf2d077f94344441909abe670f5a (patch) | |
tree | b834c912629498e9fefb5958ee9965c414d32d69 /kernel | |
parent | 0ab4dc92278a0f3816e486d6350c6652a72e06c8 (diff) |
Add common orderly_poweroff()
Various pieces of code around the kernel want to be able to trigger an
orderly poweroff. This pulls them together into a single
implementation.
By default the poweroff command is /sbin/poweroff, but it can be set
via sysctl: kernel/poweroff_cmd. This is split at whitespace, so it
can include command-line arguments.
This patch replaces four other instances of invoking either "poweroff"
or "shutdown -h now": two sbus drivers, and acpi thermal
management.
sparc64 has its own "powerd"; still need to determine whether it should
be replaced by orderly_poweroff().
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Acked-by: Len Brown <lenb@kernel.org>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/sys.c | 58 | ||||
-rw-r--r-- | kernel/sysctl.c | 10 |
2 files changed, 68 insertions, 0 deletions
diff --git a/kernel/sys.c b/kernel/sys.c index 4d141ae3e802..aeded9ad66ce 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -2286,3 +2286,61 @@ asmlinkage long sys_getcpu(unsigned __user *cpup, unsigned __user *nodep, | |||
2286 | } | 2286 | } |
2287 | return err ? -EFAULT : 0; | 2287 | return err ? -EFAULT : 0; |
2288 | } | 2288 | } |
2289 | |||
2290 | char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff"; | ||
2291 | |||
2292 | static void argv_cleanup(char **argv, char **envp) | ||
2293 | { | ||
2294 | argv_free(argv); | ||
2295 | } | ||
2296 | |||
2297 | /** | ||
2298 | * orderly_poweroff - Trigger an orderly system poweroff | ||
2299 | * @force: force poweroff if command execution fails | ||
2300 | * | ||
2301 | * This may be called from any context to trigger a system shutdown. | ||
2302 | * If the orderly shutdown fails, it will force an immediate shutdown. | ||
2303 | */ | ||
2304 | int orderly_poweroff(bool force) | ||
2305 | { | ||
2306 | int argc; | ||
2307 | char **argv = argv_split(GFP_ATOMIC, poweroff_cmd, &argc); | ||
2308 | static char *envp[] = { | ||
2309 | "HOME=/", | ||
2310 | "PATH=/sbin:/bin:/usr/sbin:/usr/bin", | ||
2311 | NULL | ||
2312 | }; | ||
2313 | int ret = -ENOMEM; | ||
2314 | struct subprocess_info *info; | ||
2315 | |||
2316 | if (argv == NULL) { | ||
2317 | printk(KERN_WARNING "%s failed to allocate memory for \"%s\"\n", | ||
2318 | __func__, poweroff_cmd); | ||
2319 | goto out; | ||
2320 | } | ||
2321 | |||
2322 | info = call_usermodehelper_setup(argv[0], argv, envp); | ||
2323 | if (info == NULL) { | ||
2324 | argv_free(argv); | ||
2325 | goto out; | ||
2326 | } | ||
2327 | |||
2328 | call_usermodehelper_setcleanup(info, argv_cleanup); | ||
2329 | |||
2330 | ret = call_usermodehelper_exec(info, -1); | ||
2331 | |||
2332 | out: | ||
2333 | if (ret && force) { | ||
2334 | printk(KERN_WARNING "Failed to start orderly shutdown: " | ||
2335 | "forcing the issue\n"); | ||
2336 | |||
2337 | /* I guess this should try to kick off some daemon to | ||
2338 | sync and poweroff asap. Or not even bother syncing | ||
2339 | if we're doing an emergency shutdown? */ | ||
2340 | emergency_sync(); | ||
2341 | kernel_power_off(); | ||
2342 | } | ||
2343 | |||
2344 | return ret; | ||
2345 | } | ||
2346 | EXPORT_SYMBOL_GPL(orderly_poweroff); | ||
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 7063ebc6db05..44a1d699aad7 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -46,6 +46,7 @@ | |||
46 | #include <linux/syscalls.h> | 46 | #include <linux/syscalls.h> |
47 | #include <linux/nfs_fs.h> | 47 | #include <linux/nfs_fs.h> |
48 | #include <linux/acpi.h> | 48 | #include <linux/acpi.h> |
49 | #include <linux/reboot.h> | ||
49 | 50 | ||
50 | #include <asm/uaccess.h> | 51 | #include <asm/uaccess.h> |
51 | #include <asm/processor.h> | 52 | #include <asm/processor.h> |
@@ -705,6 +706,15 @@ static ctl_table kern_table[] = { | |||
705 | .proc_handler = &proc_dointvec, | 706 | .proc_handler = &proc_dointvec, |
706 | }, | 707 | }, |
707 | #endif | 708 | #endif |
709 | { | ||
710 | .ctl_name = CTL_UNNUMBERED, | ||
711 | .procname = "poweroff_cmd", | ||
712 | .data = &poweroff_cmd, | ||
713 | .maxlen = POWEROFF_CMD_PATH_LEN, | ||
714 | .mode = 0644, | ||
715 | .proc_handler = &proc_dostring, | ||
716 | .strategy = &sysctl_string, | ||
717 | }, | ||
708 | 718 | ||
709 | { .ctl_name = 0 } | 719 | { .ctl_name = 0 } |
710 | }; | 720 | }; |