Commit 938e4b22 authored by Lucas De Marchi's avatar Lucas De Marchi Committed by Linus Torvalds

usermodehelper: export call_usermodehelper_exec() and call_usermodehelper_setup()

call_usermodehelper_setup() + call_usermodehelper_exec() need to be
called instead of call_usermodehelper_fns() when the cleanup function
needs to be called even when an ENOMEM error occurs.  In this case using
call_usermodehelper_fns() the user can't distinguish if the cleanup
function was called or not.

[akpm@linux-foundation.org: export call_usermodehelper_setup() to modules]
Signed-off-by: default avatarLucas De Marchi <lucas.demarchi@profusion.mobi>
Reviewed-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: David Howells <dhowells@redhat.com>
Cc: James Morris <james.l.morris@oracle.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Tejun Heo <tj@kernel.org>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 17afab1d
...@@ -71,6 +71,14 @@ call_usermodehelper_fns(char *path, char **argv, char **envp, int wait, ...@@ -71,6 +71,14 @@ call_usermodehelper_fns(char *path, char **argv, char **envp, int wait,
int (*init)(struct subprocess_info *info, struct cred *new), int (*init)(struct subprocess_info *info, struct cred *new),
void (*cleanup)(struct subprocess_info *), void *data); void (*cleanup)(struct subprocess_info *), void *data);
extern struct subprocess_info *
call_usermodehelper_setup(char *path, char **argv, char **envp, gfp_t gfp_mask,
int (*init)(struct subprocess_info *info, struct cred *new),
void (*cleanup)(struct subprocess_info *), void *data);
extern int
call_usermodehelper_exec(struct subprocess_info *info, int wait);
static inline int static inline int
call_usermodehelper(char *path, char **argv, char **envp, int wait) call_usermodehelper(char *path, char **argv, char **envp, int wait)
{ {
......
...@@ -502,14 +502,28 @@ static void helper_unlock(void) ...@@ -502,14 +502,28 @@ static void helper_unlock(void)
* @argv: arg vector for process * @argv: arg vector for process
* @envp: environment for process * @envp: environment for process
* @gfp_mask: gfp mask for memory allocation * @gfp_mask: gfp mask for memory allocation
* @cleanup: a cleanup function
* @init: an init function
* @data: arbitrary context sensitive data
* *
* Returns either %NULL on allocation failure, or a subprocess_info * Returns either %NULL on allocation failure, or a subprocess_info
* structure. This should be passed to call_usermodehelper_exec to * structure. This should be passed to call_usermodehelper_exec to
* exec the process and free the structure. * exec the process and free the structure.
*
* 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 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.
*/ */
static
struct subprocess_info *call_usermodehelper_setup(char *path, char **argv, struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
char **envp, gfp_t gfp_mask) char **envp, gfp_t gfp_mask,
int (*init)(struct subprocess_info *info, struct cred *new),
void (*cleanup)(struct subprocess_info *info),
void *data)
{ {
struct subprocess_info *sub_info; struct subprocess_info *sub_info;
sub_info = kzalloc(sizeof(struct subprocess_info), gfp_mask); sub_info = kzalloc(sizeof(struct subprocess_info), gfp_mask);
...@@ -520,36 +534,14 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv, ...@@ -520,36 +534,14 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
sub_info->path = path; sub_info->path = path;
sub_info->argv = argv; sub_info->argv = argv;
sub_info->envp = envp; sub_info->envp = envp;
sub_info->cleanup = cleanup;
sub_info->init = init;
sub_info->data = data;
out: out:
return sub_info; return sub_info;
} }
EXPORT_SYMBOL(call_usermodehelper_setup);
/**
* 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 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.
*/
static
void call_usermodehelper_setfns(struct subprocess_info *info,
int (*init)(struct subprocess_info *info, struct cred *new),
void (*cleanup)(struct subprocess_info *info),
void *data)
{
info->cleanup = cleanup;
info->init = init;
info->data = data;
}
/** /**
* call_usermodehelper_exec - start a usermode application * call_usermodehelper_exec - start a usermode application
...@@ -563,7 +555,6 @@ void call_usermodehelper_setfns(struct subprocess_info *info, ...@@ -563,7 +555,6 @@ void call_usermodehelper_setfns(struct subprocess_info *info,
* asynchronously if wait is not set, and runs as a child of keventd. * asynchronously if wait is not set, and runs as a child of keventd.
* (ie. it runs with full root capabilities). * (ie. it runs with full root capabilities).
*/ */
static
int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait) int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
{ {
DECLARE_COMPLETION_ONSTACK(done); DECLARE_COMPLETION_ONSTACK(done);
...@@ -615,6 +606,7 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait) ...@@ -615,6 +606,7 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
helper_unlock(); helper_unlock();
return retval; return retval;
} }
EXPORT_SYMBOL(call_usermodehelper_exec);
/* /*
* call_usermodehelper_fns() will not run the caller-provided cleanup function * call_usermodehelper_fns() will not run the caller-provided cleanup function
...@@ -630,13 +622,12 @@ int call_usermodehelper_fns( ...@@ -630,13 +622,12 @@ int call_usermodehelper_fns(
struct subprocess_info *info; struct subprocess_info *info;
gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL; gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
info = call_usermodehelper_setup(path, argv, envp, gfp_mask); info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
init, cleanup, data);
if (info == NULL) if (info == NULL)
return -ENOMEM; return -ENOMEM;
call_usermodehelper_setfns(info, init, cleanup, data);
return call_usermodehelper_exec(info, wait); return call_usermodehelper_exec(info, wait);
} }
EXPORT_SYMBOL(call_usermodehelper_fns); EXPORT_SYMBOL(call_usermodehelper_fns);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment