Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 198736
b: refs/heads/master
c: a06a4dc
h: refs/heads/master
v: v3
  • Loading branch information
Neil Horman authored and Linus Torvalds committed May 27, 2010
1 parent 120599c commit 9b8da11
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 36 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 065add3941bdca54fe04ed3471a96bce9af88793
refs/heads/master: a06a4dc3a08201ff6a8a958f935b3cbf7744115f
51 changes: 41 additions & 10 deletions trunk/include/linux/kmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/stddef.h>
#include <linux/errno.h>
#include <linux/compiler.h>
#include <linux/workqueue.h>

#define KMOD_PATH_LEN 256

Expand All @@ -45,7 +46,27 @@ static inline int request_module_nowait(const char *name, ...) { return -ENOSYS;

struct key;
struct file;
struct subprocess_info;

enum umh_wait {
UMH_NO_WAIT = -1, /* don't wait at all */
UMH_WAIT_EXEC = 0, /* wait for the exec, but not the process */
UMH_WAIT_PROC = 1, /* wait for the process to complete */
};

struct subprocess_info {
struct work_struct work;
struct completion *complete;
struct cred *cred;
char *path;
char **argv;
char **envp;
enum umh_wait wait;
int retval;
struct file *stdin;
int (*init)(struct subprocess_info *info);
void (*cleanup)(struct subprocess_info *info);
void *data;
};

/* Allocate a subprocess_info structure */
struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
Expand All @@ -56,14 +77,10 @@ void call_usermodehelper_setkeys(struct subprocess_info *info,
struct key *session_keyring);
int call_usermodehelper_stdinpipe(struct subprocess_info *sub_info,
struct file **filp);
void call_usermodehelper_setcleanup(struct subprocess_info *info,
void (*cleanup)(char **argv, char **envp));

enum umh_wait {
UMH_NO_WAIT = -1, /* don't wait at all */
UMH_WAIT_EXEC = 0, /* wait for the exec, but not the process */
UMH_WAIT_PROC = 1, /* wait for the process to complete */
};
void call_usermodehelper_setfns(struct subprocess_info *info,
int (*init)(struct subprocess_info *info),
void (*cleanup)(struct subprocess_info *info),
void *data);

/* Actually execute the sub-process */
int call_usermodehelper_exec(struct subprocess_info *info, enum umh_wait wait);
Expand All @@ -73,17 +90,31 @@ int call_usermodehelper_exec(struct subprocess_info *info, enum umh_wait wait);
void call_usermodehelper_freeinfo(struct subprocess_info *info);

static inline int
call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait)
call_usermodehelper_fns(char *path, char **argv, char **envp,
enum umh_wait wait,
int (*init)(struct subprocess_info *info),
void (*cleanup)(struct subprocess_info *), void *data)
{
struct subprocess_info *info;
gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;

info = call_usermodehelper_setup(path, argv, envp, gfp_mask);

if (info == NULL)
return -ENOMEM;

call_usermodehelper_setfns(info, init, cleanup, data);

return call_usermodehelper_exec(info, wait);
}

static inline int
call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait)
{
return call_usermodehelper_fns(path, argv, envp, wait,
NULL, NULL, NULL);
}

static inline int
call_usermodehelper_keys(char *path, char **argv, char **envp,
struct key *session_keyring, enum umh_wait wait)
Expand Down
51 changes: 29 additions & 22 deletions trunk/kernel/kmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,16 @@ int __request_module(bool wait, const char *fmt, ...)

trace_module_request(module_name, wait, _RET_IP_);

ret = call_usermodehelper(modprobe_path, argv, envp,
wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
ret = call_usermodehelper_fns(modprobe_path, argv, envp,
wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
NULL, NULL, NULL);

atomic_dec(&kmod_concurrent);
return ret;
}
EXPORT_SYMBOL(__request_module);
#endif /* CONFIG_MODULES */

struct subprocess_info {
struct work_struct work;
struct completion *complete;
struct cred *cred;
char *path;
char **argv;
char **envp;
enum umh_wait wait;
int retval;
struct file *stdin;
void (*cleanup)(char **argv, char **envp);
};

/*
* This is the task which runs the usermode application
*/
Expand Down Expand Up @@ -184,17 +173,24 @@ static int ____call_usermodehelper(void *data)
*/
set_user_nice(current, 0);

if (sub_info->init) {
retval = sub_info->init(sub_info);
if (retval)
goto fail;
}

retval = kernel_execve(sub_info->path, sub_info->argv, sub_info->envp);

/* Exec failed? */
fail:
sub_info->retval = retval;
do_exit(0);
}

void call_usermodehelper_freeinfo(struct subprocess_info *info)
{
if (info->cleanup)
(*info->cleanup)(info->argv, info->envp);
(*info->cleanup)(info);
if (info->cred)
put_cred(info->cred);
kfree(info);
Expand Down Expand Up @@ -406,21 +402,31 @@ void call_usermodehelper_setkeys(struct subprocess_info *info,
EXPORT_SYMBOL(call_usermodehelper_setkeys);

/**
* call_usermodehelper_setcleanup - set a cleanup function
* call_usermodehelper_setfns - set a cleanup/init function
* @info: a subprocess_info returned by call_usermodehelper_setup
* @cleanup: a cleanup function
* @init: an init function
* @data: arbitrary context sensitive data
*
* The init function is used to customize the helper process prior to
* exec. A non-zero return code causes the process to error out, exit,
* and return the failure to the calling process
*
* The cleanup function is just befor ethe subprocess_info is about to
* The cleanup function is just before ethe subprocess_info is about to
* be freed. This can be used for freeing the argv and envp. The
* Function must be runnable in either a process context or the
* context in which call_usermodehelper_exec is called.
*/
void call_usermodehelper_setcleanup(struct subprocess_info *info,
void (*cleanup)(char **argv, char **envp))
void call_usermodehelper_setfns(struct subprocess_info *info,
int (*init)(struct subprocess_info *info),
void (*cleanup)(struct subprocess_info *info),
void *data)
{
info->cleanup = cleanup;
info->init = init;
info->data = data;
}
EXPORT_SYMBOL(call_usermodehelper_setcleanup);
EXPORT_SYMBOL(call_usermodehelper_setfns);

/**
* call_usermodehelper_stdinpipe - set up a pipe to be used for stdin
Expand Down Expand Up @@ -515,7 +521,8 @@ int call_usermodehelper_pipe(char *path, char **argv, char **envp,
struct subprocess_info *sub_info;
int ret;

sub_info = call_usermodehelper_setup(path, argv, envp, GFP_KERNEL);
sub_info = call_usermodehelper_setup(path, argv, envp,
GFP_KERNEL);
if (sub_info == NULL)
return -ENOMEM;

Expand Down
6 changes: 3 additions & 3 deletions trunk/kernel/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1632,9 +1632,9 @@ SYSCALL_DEFINE3(getcpu, unsigned __user *, cpup, unsigned __user *, nodep,

char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";

static void argv_cleanup(char **argv, char **envp)
static void argv_cleanup(struct subprocess_info *info)
{
argv_free(argv);
argv_free(info->argv);
}

/**
Expand Down Expand Up @@ -1668,7 +1668,7 @@ int orderly_poweroff(bool force)
goto out;
}

call_usermodehelper_setcleanup(info, argv_cleanup);
call_usermodehelper_setfns(info, NULL, argv_cleanup, NULL);

ret = call_usermodehelper_exec(info, UMH_NO_WAIT);

Expand Down

0 comments on commit 9b8da11

Please sign in to comment.