From: Andi Kleen <ak@suse.de>
To: linux-kernel@vger.kernel.org, akpm@osdl.org
Subject: [PATCH] [2/3] Create call_usermodehelper_pipe()
Date: Mon, 14 Aug 2006 13:27:31 +0200 (CEST) [thread overview]
Message-ID: <20060814112731.5A16213BD9@wotan.suse.de> (raw)
In-Reply-To: <20060814 127.183332000@suse.de>
A new member in the ever growing family of call_usermode* functions is born.
The new call_usermodehelper_pipe() function allows to pipe data to the stdin of the called
user mode progam and behaves otherwise like the normal call_usermodehelp()
(except that it always waits for the child to finish)
To be used in a follow up patch.
Signed-off-by: Andi Kleen <ak@suse.de>
Index: linux/kernel/kmod.c
===================================================================
--- linux.orig/kernel/kmod.c
+++ linux/kernel/kmod.c
@@ -122,6 +122,7 @@ struct subprocess_info {
struct key *ring;
int wait;
int retval;
+ struct file *stdin;
};
/*
@@ -145,12 +146,26 @@ static int ____call_usermodehelper(void
key_put(old_session);
+ /* Install input pipe when needed */
+ if (sub_info->stdin) {
+ struct files_struct *f = current->files;
+ struct fdtable *fdt;
+ /* no races because files should be private here */
+ sys_close(0);
+ fd_install(0, sub_info->stdin);
+ spin_lock(&f->file_lock);
+ fdt = files_fdtable(f);
+ FD_SET(0, fdt->open_fds);
+ FD_CLR(0, fdt->close_on_exec);
+ spin_unlock(&f->file_lock);
+ }
+
/* We can run anywhere, unlike our parent keventd(). */
set_cpus_allowed(current, CPU_MASK_ALL);
retval = -EPERM;
if (current->fs->root)
- retval = execve(sub_info->path, sub_info->argv,sub_info->envp);
+ retval = execve(sub_info->path, sub_info->argv, sub_info->envp);
/* Exec failed? */
sub_info->retval = retval;
@@ -257,6 +272,44 @@ int call_usermodehelper_keys(char *path,
}
EXPORT_SYMBOL(call_usermodehelper_keys);
+int call_usermodehelper_pipe(char *path, char **argv, char **envp,
+ struct file **filp)
+{
+ DECLARE_COMPLETION(done);
+ struct subprocess_info sub_info = {
+ .complete = &done,
+ .path = path,
+ .argv = argv,
+ .envp = envp,
+ .retval = 0,
+ };
+ struct file *f;
+ DECLARE_WORK(work, __call_usermodehelper, &sub_info);
+
+ if (!khelper_wq)
+ return -EBUSY;
+
+ if (path[0] == '\0')
+ return 0;
+
+ f = create_write_pipe();
+ if (!f)
+ return -ENOMEM;
+ *filp = f;
+
+ f = create_read_pipe(f);
+ if (!f) {
+ free_write_pipe(*filp);
+ return -ENOMEM;
+ }
+ sub_info.stdin = f;
+
+ queue_work(khelper_wq, &work);
+ wait_for_completion(&done);
+ return sub_info.retval;
+}
+EXPORT_SYMBOL(call_usermodehelper_pipe);
+
void __init usermodehelper_init(void)
{
khelper_wq = create_singlethread_workqueue("khelper");
Index: linux/include/linux/kmod.h
===================================================================
--- linux.orig/include/linux/kmod.h
+++ linux/include/linux/kmod.h
@@ -47,4 +47,8 @@ call_usermodehelper(char *path, char **a
extern void usermodehelper_init(void);
+struct file;
+extern int call_usermodehelper_pipe(char *path, char *argv[], char *envp[],
+ struct file **filp);
+
#endif /* __LINUX_KMOD_H__ */
next prev parent reply other threads:[~2006-08-14 11:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20060814 127.183332000@suse.de>
2006-08-14 11:27 ` [PATCH] [1/3] Some cleanup in the pipe code Andi Kleen
2006-08-14 11:27 ` Andi Kleen [this message]
2006-08-15 21:22 ` [PATCH] [2/3] Create call_usermodehelper_pipe() Andrew Morton
2006-08-16 2:13 ` Andrew Morton
2006-08-16 7:22 ` Andi Kleen
2006-08-14 11:27 ` [PATCH] [3/3] Support piping into commands in /proc/sys/kernel/core_pattern Andi Kleen
2006-08-15 0:43 ` Andrew Morton
2006-08-15 6:04 ` Andi Kleen
2006-08-16 8:43 ` Greg KH
2006-08-16 9:18 ` Andi Kleen
2006-08-16 18:10 ` Andrew Morton
2006-08-17 9:46 ` Andi Kleen
2006-08-17 11:27 ` Alan Cox
2006-08-18 5:30 ` Andrew Morton
2006-08-18 8:29 ` Andi Kleen
2006-08-18 12:01 ` Arjan van de Ven
2006-08-18 12:10 ` Arjan van de Ven
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=20060814112731.5A16213BD9@wotan.suse.de \
--to=ak@suse.de \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®