[RFC][PATCH -mm 2/2] PM: Disable usermode helper before hibernation and suspend

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: pm list <linux-pm@...>
Cc: LKML <linux-kernel@...>, Matthew Garrett <mjg59@...>, Nigel Cunningham <nigel@...>, Pavel Machek <pavel@...>, Alan Stern <stern@...>, Oliver Neukum <oliver@...>
Date: Friday, June 1, 2007 - 8:44 pm

From: Rafael J. Wysocki <rjw@sisk.pl>

Use a hibernation and suspend notifier to disable the user mode helper before
a hibernation/suspend and enable it after the operation.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 kernel/kmod.c |   33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

Index: linux-2.6.22-rc3/kernel/kmod.c
===================================================================
--- linux-2.6.22-rc3.orig/kernel/kmod.c	2007-05-31 00:00:37.000000000 +0200
+++ linux-2.6.22-rc3/kernel/kmod.c	2007-06-02 00:01:47.000000000 +0200
@@ -33,6 +33,8 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/resource.h>
+#include <linux/notifier.h>
+#include <linux/suspend.h>
 #include <asm/uaccess.h>
 
 extern int max_threads;
@@ -46,6 +48,14 @@ static struct workqueue_struct *khelper_
 */
 char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
 
+/*
+ * If set, both call_usermodehelper_keys() and call_usermodehelper_pipe() exit
+ * immediately returning -EBUSY.  Used for preventing user land processes from
+ * being created after the user land has been frozen during a system-wide
+ * hibernation or suspend operation.
+ */
+static int usermodehelper_disabled;
+
 /**
  * request_module - try to load a kernel module
  * @fmt:     printf style format string for the name of the module
@@ -251,6 +261,24 @@ static void __call_usermodehelper(struct
 		complete(sub_info->complete);
 }
 
+static int usermodehelper_pm_callback(struct notifier_block *nfb,
+					unsigned long action,
+					void *ignored)
+{
+	switch (action) {
+	case PM_HIBERNATION_PREPARE:
+	case PM_SUSPEND_PREPARE:
+		usermodehelper_disabled = 1;
+		return NOTIFY_OK;
+	case PM_POST_HIBERNATION:
+	case PM_POST_SUSPEND:
+		usermodehelper_disabled = 0;
+		return NOTIFY_OK;
+	}
+
+	return NOTIFY_DONE;
+}
+
 /**
  * call_usermodehelper_keys - start a usermode application
  * @path: pathname for the application
@@ -276,7 +304,7 @@ int call_usermodehelper_keys(char *path,
 	struct subprocess_info *sub_info;
 	int retval;
 
-	if (!khelper_wq)
+	if (!khelper_wq || usermodehelper_disabled)
 		return -EBUSY;
 
 	if (path[0] == '\0')
@@ -319,7 +347,7 @@ int call_usermodehelper_pipe(char *path,
 	};
 	struct file *f;
 
-	if (!khelper_wq)
+	if (!khelper_wq || usermodehelper_disabled)
 		return -EBUSY;
 
 	if (path[0] == '\0')
@@ -347,4 +375,5 @@ void __init usermodehelper_init(void)
 {
 	khelper_wq = create_singlethread_workqueue("khelper");
 	BUG_ON(!khelper_wq);
+	pm_notifier(usermodehelper_pm_callback, 0);
 }
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC][PATCH -mm 0/3] PM: Hibernation and suspend notifiers, Rafael J. Wysocki, (Sun May 27, 4:29 pm)
[RFC][PATCH -mm 2/2] PM: Disable usermode helper before hibe..., Rafael J. Wysocki, (Fri Jun 1, 8:44 pm)
[RFC][PATCH -mm 3/3] PM: Disable _request_firmware before hi..., Rafael J. Wysocki, (Sun May 27, 4:31 pm)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Rafael J. Wysocki, (Mon May 28, 1:43 pm)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Rafael J. Wysocki, (Mon May 28, 3:43 am)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Michael-Luke Jones, (Mon May 28, 7:38 am)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Michael-Luke Jones, (Mon May 28, 8:26 am)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Michael-Luke Jones, (Mon May 28, 9:10 am)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Rafael J. Wysocki, (Mon May 28, 7:28 am)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Michael-Luke Jones, (Mon May 28, 4:48 am)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Michael-Luke Jones, (Mon May 28, 6:41 am)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Michael-Luke Jones, (Mon May 28, 6:26 am)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Michael-Luke Jones, (Mon May 28, 8:07 am)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Rafael J. Wysocki, (Sun May 27, 6:01 pm)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Rafael J. Wysocki, (Sun May 27, 5:45 pm)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Rafael J. Wysocki, (Mon May 28, 7:22 am)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Rafael J. Wysocki, (Mon May 28, 3:44 am)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Michael-Luke Jones, (Sun May 27, 4:45 pm)
Re: [RFC][PATCH -mm 3/3] PM: Disable _request_firmware befor..., Rafael J. Wysocki, (Sun May 27, 5:55 pm)
[RFC][PATCH -mm 1/3] PM: Hibernation and suspend notifiers, Rafael J. Wysocki, (Sun May 27, 4:30 pm)
Re: [RFC][PATCH -mm 1/3] PM: Hibernation and suspend notifiers, Rafael J. Wysocki, (Tue May 29, 6:24 pm)
Re: [RFC][PATCH -mm 1/3] PM: Hibernation and suspend notifiers, Rafael J. Wysocki, (Wed May 30, 4:44 pm)
Re: [RFC][PATCH -mm 1/3] PM: Hibernation and suspend notifiers, Rafael J. Wysocki, (Wed May 30, 5:11 pm)
Re: [RFC][PATCH -mm 1/3] PM: Hibernation and suspend notifiers, Rafael J. Wysocki, (Thu May 31, 1:42 am)
Re: [RFC][PATCH -mm 1/3] PM: Hibernation and suspend notifiers, Rafael J. Wysocki, (Thu May 31, 1:44 am)
Re: [RFC][PATCH -mm 1/3] PM: Hibernation and suspend notifiers, Rafael J. Wysocki, (Thu May 31, 4:02 pm)
Re: [RFC][PATCH -mm 1/3] PM: Hibernation and suspend notifiers, Rafael J. Wysocki, (Mon May 28, 1:29 pm)
Re: [RFC][PATCH -mm 1/3] PM: Hibernation and suspend notifiers, Rafael J. Wysocki, (Mon May 28, 1:26 pm)
[RFC][PATCH -mm 2/3] PM: Disable usermode helper before hibe..., Rafael J. Wysocki, (Sun May 27, 4:30 pm)