Commit d47419cd967a4f032a194148a7b08afad32faded

Authored by Oleg Nesterov
Committed by Linus Torvalds
1 parent 7d64224217

call_usermodehelper: simplify/fix UMH_NO_WAIT case

__call_usermodehelper(UMH_NO_WAIT) has 2 problems:

	- if kernel_thread() fails, call_usermodehelper_freeinfo()
	  is not called.

	- for unknown reason UMH_NO_WAIT has UMH_WAIT_PROC logic,
	  we spawn yet another thread which waits until the user
	  mode application exits.

Change the UMH_NO_WAIT code to use ____call_usermodehelper() instead of
wait_for_helper(), and do call_usermodehelper_freeinfo() unconditionally.
We can rely on CLONE_VFORK, do_fork(CLONE_VFORK) until the child exits or
execs.

With or without this patch UMH_NO_WAIT does not report the error if
kernel_thread() fails, this is correct since the caller doesn't wait for
result.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 4 additions and 6 deletions Side-by-side Diff

... ... @@ -205,10 +205,7 @@
205 205 sub_info->retval = ret;
206 206 }
207 207  
208   - if (sub_info->wait == UMH_NO_WAIT)
209   - call_usermodehelper_freeinfo(sub_info);
210   - else
211   - complete(sub_info->complete);
  208 + complete(sub_info->complete);
212 209 return 0;
213 210 }
214 211  
215 212  
216 213  
... ... @@ -217,13 +214,13 @@
217 214 {
218 215 struct subprocess_info *sub_info =
219 216 container_of(work, struct subprocess_info, work);
220   - pid_t pid;
221 217 enum umh_wait wait = sub_info->wait;
  218 + pid_t pid;
222 219  
223 220 /* CLONE_VFORK: wait until the usermode helper has execve'd
224 221 * successfully We need the data structures to stay around
225 222 * until that is done. */
226   - if (wait == UMH_WAIT_PROC || wait == UMH_NO_WAIT)
  223 + if (wait == UMH_WAIT_PROC)
227 224 pid = kernel_thread(wait_for_helper, sub_info,
228 225 CLONE_FS | CLONE_FILES | SIGCHLD);
229 226 else
... ... @@ -232,6 +229,7 @@
232 229  
233 230 switch (wait) {
234 231 case UMH_NO_WAIT:
  232 + call_usermodehelper_freeinfo(sub_info);
235 233 break;
236 234  
237 235 case UMH_WAIT_PROC: