From: Mike Waychison <michael.waychison@sun.com>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: raven@themaw.net
Subject: [PATCH 20/28] HOTPLUG: call_usermodehelper callback support
Date: Mon, 25 Oct 2004 10:48:40 -0400 [thread overview]
Message-ID: <10987157204162@sun.com> (raw)
In-Reply-To: <10987156903663@sun.com>
This patch extends the call_usermodehelper api by adding a callback variant.
The callback is made right when the system is about to call execve into the
new process. This allows for the caller to provide changes to the default
environment right before the exec takes place. Note: the context of the
callback will be _from within another process_.
Signed-off-by: Mike Waychison <michael.waychison@sun.com>
---
include/linux/kmod.h | 2 +
kernel/kmod.c | 80 ++++++++++++++++++++++++++++++++++++++-------------
2 files changed, 63 insertions(+), 19 deletions(-)
Index: linux-2.6.9-quilt/kernel/kmod.c
===================================================================
--- linux-2.6.9-quilt.orig/kernel/kmod.c 2004-08-14 01:36:44.000000000 -0400
+++ linux-2.6.9-quilt/kernel/kmod.c 2004-10-22 17:17:44.279732600 -0400
@@ -140,17 +140,22 @@ EXPORT_SYMBOL(hotplug_path);
struct subprocess_info {
struct completion *complete;
+ call_usermodehelper_cb_t cb;
+ void *cbdata;
+ int wait;
+ int retval;
+};
+
+struct simple_usermodehelper_info {
char *path;
char **argv;
char **envp;
- int wait;
- int retval;
};
/*
* This is the task which runs the usermode application
*/
-static int ____call_usermodehelper(void *data)
+static int ____call_usermodehelper_cb(void *data)
{
struct subprocess_info *sub_info = data;
int retval;
@@ -168,7 +173,7 @@ static int ____call_usermodehelper(void
retval = -EPERM;
if (current->fs->root)
- retval = execve(sub_info->path, sub_info->argv,sub_info->envp);
+ retval = (*sub_info->cb)(sub_info->cbdata);
/* Exec failed? */
sub_info->retval = retval;
@@ -190,7 +195,7 @@ static int wait_for_helper(void *data)
do_sigaction(SIGCHLD, &sa, (struct k_sigaction *)0);
allow_signal(SIGCHLD);
- pid = kernel_thread(____call_usermodehelper, sub_info, SIGCHLD);
+ pid = kernel_thread(____call_usermodehelper_cb, sub_info, SIGCHLD);
if (pid < 0) {
sub_info->retval = pid;
} else {
@@ -211,7 +216,7 @@ static int wait_for_helper(void *data)
}
/* This is run by khelper thread */
-static void __call_usermodehelper(void *data)
+static void __call_usermodehelper_cb(void *data)
{
struct subprocess_info *sub_info = data;
pid_t pid;
@@ -223,7 +228,7 @@ static void __call_usermodehelper(void *
pid = kernel_thread(wait_for_helper, sub_info,
CLONE_FS | CLONE_FILES | SIGCHLD);
else
- pid = kernel_thread(____call_usermodehelper, sub_info,
+ pid = kernel_thread(____call_usermodehelper_cb, sub_info,
CLONE_VFORK | SIGCHLD);
if (pid < 0) {
@@ -234,12 +239,16 @@ static void __call_usermodehelper(void *
}
/**
- * call_usermodehelper - start a usermode application
- * @path: pathname for the application
- * @argv: null-terminated argument list
- * @envp: null-terminated environment list
+ * call_usermodehelper_cb - start a usermode application with a callback
+ * @cb: A user provided callback that will eventually execve.
+ * @cbdata: User supplied information that will be passed back to the callback.
* @wait: wait for the application to finish and return status.
*
+ * This call will do all the work required for setting up a usermode helper
+ * except perform the actual exec. It is the caller's responsibility to
+ * provide a callback that will eventually exec. This allows last minute
+ * changes to current.
+ *
* Runs a user-space application. The application is started
* asynchronously if wait is not set, and runs as a child of keventd.
* (ie. it runs with full root capabilities).
@@ -247,29 +256,62 @@ static void __call_usermodehelper(void *
* Must be called from process context. Returns a negative error code
* if program was not execed successfully, or 0.
*/
-int call_usermodehelper(char *path, char **argv, char **envp, int wait)
+int call_usermodehelper_cb(call_usermodehelper_cb_t cb, void *cbdata, int wait)
{
DECLARE_COMPLETION(done);
struct subprocess_info sub_info = {
.complete = &done,
- .path = path,
- .argv = argv,
- .envp = envp,
+ .cb = cb,
+ .cbdata = cbdata,
.wait = wait,
.retval = 0,
};
- DECLARE_WORK(work, __call_usermodehelper, &sub_info);
+ DECLARE_WORK(work, __call_usermodehelper_cb, &sub_info);
+ BUG_ON(!cb || !cbdata);
if (!khelper_wq)
return -EBUSY;
- if (path[0] == '\0')
- return 0;
-
queue_work(khelper_wq, &work);
wait_for_completion(&done);
return sub_info.retval;
}
+EXPORT_SYMBOL(call_usermodehelper_cb);
+
+static int call_usermodehelper_simple(void *cbdata)
+{
+ struct simple_usermodehelper_info *info = cbdata;
+ return execve(info->path, info->argv, info->envp);
+}
+
+/**
+ * call_usermodehelper - start a usermode application
+ * @path: pathname for the application
+ * @argv: null-terminated argument list
+ * @envp: null-terminated environment list
+ * @wait: wait for the application to finish and return status.
+ *
+ * Runs a user-space application. The application is started
+ * asynchronously if wait is not set, and runs as a child of keventd.
+ * (ie. it runs with full root capabilities).
+ *
+ * Must be called from process context. Returns a negative error code
+ * if program was not execed successfully, or 0.
+ */
+
+int call_usermodehelper(char *path, char **argv, char **envp, int wait)
+{
+ struct simple_usermodehelper_info info = {
+ .path = path,
+ .argv = argv,
+ .envp = envp,
+ };
+
+ if (path[0] == '\0')
+ return 0;
+
+ return call_usermodehelper_cb(call_usermodehelper_simple, &info, wait);
+}
EXPORT_SYMBOL(call_usermodehelper);
static __init int usermodehelper_init(void)
Index: linux-2.6.9-quilt/include/linux/kmod.h
===================================================================
--- linux-2.6.9-quilt.orig/include/linux/kmod.h 2004-08-14 01:36:32.000000000 -0400
+++ linux-2.6.9-quilt/include/linux/kmod.h 2004-10-22 17:17:44.279732600 -0400
@@ -34,6 +34,8 @@ static inline int request_module(const c
#endif
#define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x)))
+typedef int (*call_usermodehelper_cb_t)(void *cbdata);
+extern int call_usermodehelper_cb(call_usermodehelper_cb_t cb, void *cbdata, int wait);
extern int call_usermodehelper(char *path, char *argv[], char *envp[], int wait);
#ifdef CONFIG_HOTPLUG
next prev parent reply other threads:[~2004-10-25 14:48 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <10987155332448@sun.com>
2004-10-25 14:46 ` [PATCH 15/28] VFS: Mountpoint file descriptor umount support Mike Waychison
2004-10-25 14:46 ` [PATCH 16/28] VFS: Mountpoint file descriptor attach support Mike Waychison
2004-10-25 14:47 ` [PATCH 17/28] VFS: Mountpoint file descriptor walking Mike Waychison
2004-10-25 14:47 ` [PATCH 18/28] VFS: Mountpoint file descriptor read properties Mike Waychison
2004-10-25 14:48 ` [PATCH 19/28] VFS: Mountpoint file descriptor expiry support Mike Waychison
2004-10-25 14:48 ` Mike Waychison [this message]
2004-10-25 14:49 ` [PATCH 21/28] HOTPLUG: Hack to allow for call to execve Mike Waychison
2004-10-25 14:49 ` [PATCH 22/28] VFS: Export put_namespace Mike Waychison
2004-10-25 14:50 ` [PATCH 23/28] VFS: Export get_sb_pseudo Mike Waychison
2004-10-25 14:50 ` [PATCH 24/28] VFS: Fixup for ->follow_link on root of filesystem Mike Waychison
2004-10-25 14:51 ` [PATCH 25/28] VFS: statfs(64) shouldn't follow last component symlink Mike Waychison
2004-10-25 14:51 ` [PATCH 26/28] VFS: Introduce MNT_NOFOLLOW Mike Waychison
2004-10-25 14:52 ` [PATCH 27/28] Testing syscall for expiry Mike Waychison
2004-10-25 15:01 ` Christoph Hellwig
2004-10-25 15:37 ` [PATCH 28/28] AUTOFSNG: New autofs filesystem (resend) Mike Waychison
2004-10-25 15:14 ` [PATCH 25/28] VFS: statfs(64) shouldn't follow last component symlink Christoph Hellwig
2004-10-25 15:21 ` Mike Waychison
2004-10-25 15:18 ` [PATCH 20/28] HOTPLUG: call_usermodehelper callback support Christoph Hellwig
2004-10-25 15:29 ` Mike Waychison
2004-10-26 10:28 ` [PATCH 15/28] VFS: Mountpoint file descriptor umount support Christoph Hellwig
2004-10-26 14:16 ` Mike Waychison
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=10987157204162@sun.com \
--to=michael.waychison@sun.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=raven@themaw.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).