[package] hotplug2: Fix forking (#7033)
[openwrt.git] / package / hotplug2 / patches / 140-worker_fork_fix.patch
1 diff -x '*~' -Naur hotplug2-201/action.c hotplug2-201.patched/action.c
2 --- hotplug2-201/action.c 2010-04-01 04:48:10.000000000 +0300
3 +++ hotplug2-201.patched/action.c 2010-04-01 04:53:49.000000000 +0300
4 @@ -39,7 +39,7 @@
5 * Returns: Newly allocated string in "key=value" form
6 *
7 */
8 -static char* alloc_env(const char *key, const char *value) {
9 +char* alloc_env(const char *key, const char *value) {
10 size_t keylen, vallen;
11 char *combined;
12
13 diff -x '*~' -Naur hotplug2-201/action.h hotplug2-201.patched/action.h
14 --- hotplug2-201/action.h 2009-12-09 20:44:14.000000000 +0200
15 +++ hotplug2-201.patched/action.h 2010-04-01 04:54:14.000000000 +0300
16 @@ -12,5 +12,6 @@
17 #include "settings.h"
18
19 void action_perform(struct settings_t *, struct uevent_t *);
20 +char* alloc_env(const char *, const char *);
21 #endif /* ifndef ACTION_H */
22
23 diff -x '*~' -Naur hotplug2-201/workers/worker_fork.c hotplug2-201.patched/workers/worker_fork.c
24 --- hotplug2-201/workers/worker_fork.c 2010-04-01 04:52:26.000000000 +0300
25 +++ hotplug2-201.patched/workers/worker_fork.c 2010-04-01 04:51:49.000000000 +0300
26 @@ -380,6 +380,7 @@
27
28
29 static int worker_fork_process(void *in_ctx, struct uevent_t *uevent) {
30 + char **env;
31 int i;
32 struct worker_fork_child_t *child;
33 struct worker_fork_ctx_t *ctx = in_ctx;
34 @@ -406,6 +407,12 @@
35 * No child process is currently available.
36 */
37 if (child == NULL) {
38 + env = xmalloc(sizeof(char *) * uevent->env_vars_c);
39 + for (i = 0; i < uevent->env_vars_c; i++) {
40 + env[i] = alloc_env(uevent->env_vars[i].key, uevent->env_vars[i].value);
41 + putenv(env[i]);
42 + }
43 +
44 /*
45 * Are the matching rules trivial enough that we
46 * can execute them in the main process?
47 @@ -421,6 +428,12 @@
48 */
49 if (ctx->children_count < ctx->max_children)
50 child = worker_fork_spawn(ctx);
51 +
52 + for (i = 0; i < uevent->env_vars_c; i++) {
53 + unsetenv(uevent->env_vars[i].key);
54 + free(env[i]);
55 + }
56 + free(env);
57 }
58
59 /*
This page took 0.069865 seconds and 5 git commands to generate.