lkml.org 
[lkml]   [2003]   [Jan]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH-2.4] Add wait flag to call_usermodehelper()
From
Date
Hi Marcelo,

this patch adds a wait flag to call_usermodehelper(), so it can also
block, if some drivers wants it. Currently the following two drivers
get advantages from it and will save some lines of code:

drivers/net/hamradio/baycom_epp.c
drivers/bluetooth/bt3c_cs.c

Regards

Marcel

You can import this changeset into BK by piping this whole message to:
'| bk receive [path to repository]' or apply the patch as usual.

===================================================================


ChangeSet@1.926.2.1, 2003-01-06 07:50:59+01:00, marcel@holtmann.org
[PATCH] Add wait flag to call_usermodehelper()

This change is based on a patch from Rusty Russell and adds a wait
flag to call_usermodehelper() for blocking operation.


drivers/ieee1394/nodemgr.c | 2 -
drivers/pci/pci.c | 2 -
drivers/usb/usb.c | 2 -
include/linux/kmod.h | 2 -
kernel/kmod.c | 66 +++++++++++++++++++++++++++++++++------------
net/bluetooth/hci_core.c | 2 -
net/core/dev.c | 2 -
7 files changed, 55 insertions(+), 23 deletions(-)


diff -Nru a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
--- a/drivers/ieee1394/nodemgr.c Tue Jan 7 04:20:51 2003
+++ b/drivers/ieee1394/nodemgr.c Tue Jan 7 04:20:51 2003
@@ -741,7 +741,7 @@
#ifdef CONFIG_IEEE1394_VERBOSEDEBUG
HPSB_DEBUG("NodeMgr: %s %s %016Lx", argv[0], verb, (long long unsigned)ud->ne->guid);
#endif
- value = call_usermodehelper(argv[0], argv, envp);
+ value = call_usermodehelper(argv[0], argv, envp, 0);
kfree(buf);
kfree(envp);
if (value != 0)
diff -Nru a/drivers/pci/pci.c b/drivers/pci/pci.c
--- a/drivers/pci/pci.c Tue Jan 7 04:20:51 2003
+++ b/drivers/pci/pci.c Tue Jan 7 04:20:51 2003
@@ -741,7 +741,7 @@
envp[i++] = "ACTION=remove";
envp[i] = 0;

- call_usermodehelper (argv [0], argv, envp);
+ call_usermodehelper (argv [0], argv, envp, 0);
}

/**
diff -Nru a/drivers/usb/usb.c b/drivers/usb/usb.c
--- a/drivers/usb/usb.c Tue Jan 7 04:20:51 2003
+++ b/drivers/usb/usb.c Tue Jan 7 04:20:51 2003
@@ -882,7 +882,7 @@
/* NOTE: user mode daemons can call the agents too */

dbg ("kusbd: %s %s %d", argv [0], verb, dev->devnum);
- value = call_usermodehelper (argv [0], argv, envp);
+ value = call_usermodehelper (argv [0], argv, envp, 0);
kfree (buf);
kfree (envp);
if (value != 0)
diff -Nru a/include/linux/kmod.h b/include/linux/kmod.h
--- a/include/linux/kmod.h Tue Jan 7 04:20:51 2003
+++ b/include/linux/kmod.h Tue Jan 7 04:20:51 2003
@@ -29,7 +29,7 @@
#endif

extern int exec_usermodehelper(char *program_path, char *argv[], char *envp[]);
-extern int call_usermodehelper(char *path, char *argv[], char *envp[]);
+extern int call_usermodehelper(char *path, char *argv[], char *envp[], int wait);

#ifdef CONFIG_HOTPLUG
extern char hotplug_path [];
diff -Nru a/kernel/kmod.c b/kernel/kmod.c
--- a/kernel/kmod.c Tue Jan 7 04:20:51 2003
+++ b/kernel/kmod.c Tue Jan 7 04:20:51 2003
@@ -14,6 +14,9 @@

Unblock all signals when we exec a usermode process.
Shuu Yamaguchi <shuu@wondernetworkresources.com> December 2000
+
+ Add wait flag to call_usermodehelper. Based on a patch from Rusty Russell.
+ Marcel Holtmann <marcel@holtmann.org> Jan 2003
*/

#define __KERNEL_SYSCALLS__
@@ -178,7 +181,7 @@
* If module auto-loading support is disabled then this function
* becomes a no-operation.
*/
-int request_module(const char * module_name)
+int request_module(const char *module_name)
{
pid_t pid;
int waitpid_result;
@@ -276,7 +279,8 @@
char *path;
char **argv;
char **envp;
- pid_t retval;
+ int wait;
+ int retval;
};

/*
@@ -292,10 +296,29 @@
retval = exec_usermodehelper(sub_info->path, sub_info->argv, sub_info->envp);

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

+/*
+ * Keventd can't block, but this (a child) can.
+ */
+static int wait_for_helper(void *data)
+{
+ struct subprocess_info *sub_info = data;
+ pid_t pid;
+
+ pid = kernel_thread(____call_usermodehelper, sub_info,
+ CLONE_VFORK | SIGCHLD);
+ if (pid < 0)
+ sub_info->retval = pid;
+ else
+ sys_wait4(pid, (unsigned int *)&sub_info->retval, 0, NULL);
+
+ complete(sub_info->complete);
+ return 0;
+}
+
/*
* This is run by keventd.
*/
@@ -304,14 +327,21 @@
struct subprocess_info *sub_info = data;
pid_t pid;

- /*
- * CLONE_VFORK: wait until the usermode helper has execve'd successfully
- * We need the data structures to stay around until that is done.
- */
- pid = kernel_thread(____call_usermodehelper, sub_info, CLONE_VFORK | SIGCHLD);
- if (pid < 0)
+ /* CLONE_VFORK: wait until the usermode helper has execve'd
+ * successfully We need the data structures to stay around
+ * until that is done. */
+ if (sub_info->wait)
+ pid = kernel_thread(wait_for_helper, sub_info,
+ CLONE_FS | CLONE_FILES | CLONE_SIGHAND | SIGCHLD);
+ else
+ pid = kernel_thread(____call_usermodehelper, sub_info,
+ CLONE_VFORK | SIGCHLD);
+
+ if (pid < 0) {
sub_info->retval = pid;
- complete(sub_info->complete);
+ complete(sub_info->complete);
+ } else if (!sub_info->wait)
+ complete(sub_info->complete);
}

/**
@@ -319,15 +349,17 @@
* @path: pathname for the application
* @argv: null-terminated argument list
* @envp: null-terminated environment list
+ * @wait: wait for the application to finish and return status.
*
- * Runs a user-space application. The application is started asynchronously. It
- * runs as a child of keventd. It runs with full root capabilities. keventd silently
- * reaps the child when it exits.
+ * Runs a user-space application. The application is started
+ * asynchronously if wait is not set, and runs as a child of keventd.
+ * (ie. it runs with full root capabilities).
*
- * Must be called from process context. Returns zero on success, else a negative
- * error code.
+ * Must be called from process context. Returns a negative error code
+ * if program was not execed successfully, or (exitcode << 8 + signal)
+ * of the application (0 if wait is not set).
*/
-int call_usermodehelper(char *path, char **argv, char **envp)
+int call_usermodehelper(char *path, char **argv, char **envp, int wait)
{
DECLARE_COMPLETION(work);
struct subprocess_info sub_info = {
@@ -335,6 +367,7 @@
path: path,
argv: argv,
envp: envp,
+ wait: wait,
retval: 0,
};
struct tq_struct tqs = {
@@ -378,4 +411,3 @@
#ifdef CONFIG_KMOD
EXPORT_SYMBOL(request_module);
#endif
-
diff -Nru a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
--- a/net/bluetooth/hci_core.c Tue Jan 7 04:20:51 2003
+++ b/net/bluetooth/hci_core.c Tue Jan 7 04:20:51 2003
@@ -115,7 +115,7 @@
envp[3] = astr;
envp[4] = NULL;

- return call_usermodehelper(argv[0], argv, envp);
+ return call_usermodehelper(argv[0], argv, envp, 0);
}
#else
#define hci_run_hotplug(A...)
diff -Nru a/net/core/dev.c b/net/core/dev.c
--- a/net/core/dev.c Tue Jan 7 04:20:51 2003
+++ b/net/core/dev.c Tue Jan 7 04:20:51 2003
@@ -2834,6 +2834,6 @@
envp [i++] = action_str;
envp [i] = 0;

- return call_usermodehelper(argv [0], argv, envp);
+ return call_usermodehelper(argv [0], argv, envp, 0);
}
#endif
===================================================================

This BitKeeper patch contains the following changesets:
1.926.2.1
## Wrapped with gzip_uu ##


begin 664 bkpatch15567
M'XL(`)-'&CX``]59;7/:2!+^C'Y%7VW5+3@8YD6O.$XY:R=K7[Q)RDGN/F13
MU"`-H+*06&E$[%KM?[^>$=B&@"'DMJZ,#2.)F9ZGNY_I[AE^@D^%S'N-B<A#
MF5@_P7E6J%YCG"5J(M*TD^4C?'B59?BP.\XFLKOXJCN(U;644YEWZ\'9(>O8
M%O9^+U0XAIG,BUZ#=OC=$W4[E;W&U:M?/UV^O+*LXV,X'8MT)#](!<?'ELKR
MF4BBXD2H<9*E'96+M)A()3IA-JGNNE:,$(9_#O4X<=R*NL3VJI!&E`J;RH@P
MVW=M2R0B/4EN$']YW2FORU*K@A?+@CBAA#%.N!U4S+$]WSH#V@F8VV$="H1W
M">T2%XC7<TC/"9X1VB,$:GU/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S]*L
M+)!(J)F!A9W2#->U5.T:A)E$SV-B!61#](Z)*CIB0#-&!N$PT^UKK#"@(B\A
MSS*=DJ=B$">QBF71,O@]#'*(WZ_Q_X91%P;2!&JDL(G$\V`"&#$59G?4XLI8
M00-(Y0@5F4F0>8[&"Y$)6@PBQU&C7$Q0@QJ]7B\H\>%*:0,.:<J;6.EQ\/PY
M^/`,]*H724N+0<56W=$D:\QB-.'$<,<TNU<?!W6I.K^I*]:[VD.+\W1X;QB2
MU$T;YS))97&<=G_LMKTPV>/@;_.O.^O/_!AC=H#UL,NPMC$%"E_9[;I/:'^#
M(O7^IC[`7'-R=J__/G4K\XU_+^;MMA.S#9N;Q6]^X5B&UT4Y.>9<,L&CP/HO
(4$:+B7(<````
`
end
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 13:32    [W:0.040 / U:13.608 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site