Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 295269
b: refs/heads/master
c: d0bd587
h: refs/heads/master
i:
  295267: 46ba57a
v: v3
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Mar 23, 2012
1 parent 1deeb36 commit b03e245
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 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: b3449922502f5a161ee2b5022a33aec8472fbf18
refs/heads/master: d0bd587a80960d7ba7e0c8396e154028c9045c54
2 changes: 2 additions & 0 deletions trunk/include/linux/kmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ enum umh_wait {
UMH_WAIT_PROC = 1, /* wait for the process to complete */
};

#define UMH_KILLABLE 4 /* wait for EXEC/PROC killable */

struct subprocess_info {
struct work_struct work;
struct completion *complete;
Expand Down
27 changes: 25 additions & 2 deletions trunk/kernel/kmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,15 @@ EXPORT_SYMBOL(call_usermodehelper_freeinfo);

static void umh_complete(struct subprocess_info *sub_info)
{
complete(sub_info->complete);
struct completion *comp = xchg(&sub_info->complete, NULL);
/*
* See call_usermodehelper_exec(). If xchg() returns NULL
* we own sub_info, the UMH_KILLABLE caller has gone away.
*/
if (comp)
complete(comp);
else
call_usermodehelper_freeinfo(sub_info);
}

/* Keventd can't block, but this (a child) can. */
Expand Down Expand Up @@ -252,6 +260,9 @@ static void __call_usermodehelper(struct work_struct *work)
enum umh_wait wait = sub_info->wait;
pid_t pid;

if (wait != UMH_NO_WAIT)
wait &= ~UMH_KILLABLE;

/* CLONE_VFORK: wait until the usermode helper has execve'd
* successfully We need the data structures to stay around
* until that is done. */
Expand Down Expand Up @@ -461,9 +472,21 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info,
queue_work(khelper_wq, &sub_info->work);
if (wait == UMH_NO_WAIT) /* task has freed sub_info */
goto unlock;

if (wait & UMH_KILLABLE) {
retval = wait_for_completion_killable(&done);
if (!retval)
goto wait_done;

/* umh_complete() will see NULL and free sub_info */
if (xchg(&sub_info->complete, NULL))
goto unlock;
/* fallthrough, umh_complete() was already called */
}

wait_for_completion(&done);
wait_done:
retval = sub_info->retval;

out:
call_usermodehelper_freeinfo(sub_info);
unlock:
Expand Down

0 comments on commit b03e245

Please sign in to comment.