453a52d5428c0761cbf355a48f8c2d778cb3cc56
[openwrt.git] / package / hotplug2 / patches / 110-static_worker.patch
1 --- a/Makefile
2 +++ b/Makefile
3 @@ -4,7 +4,24 @@ SOFTWARE=hotplug2
4 VERSION=1.0-alpha
5
6 BINS=hotplug2 hotplug2-modwrap
7 -SUBDIRS=parser rules workers
8 +SUBDIRS=parser rules
9 +
10 +hotplug2-objs := \
11 + hotplug2.o netlink.o seqnum.o settings.o uevent.o xmemutils.o \
12 + workers/loader.o parser/parser.o parser/buffer.o parser/token.o \
13 + parser/token_queue.o parser/lexer.o rules/ruleset.o rules/rule.o \
14 + rules/condition.o rules/expression.o rules/execution.o \
15 + rules/command.o
16 +
17 +ifdef STATIC_WORKER
18 + ifeq ($(wildcard workers/worker_$(STATIC_WORKER).c),)
19 + $(error Worker source worker/worker_$(STATIC_WORKER).c not found)
20 + endif
21 + hotplug2-objs += action.o workers/worker_$(STATIC_WORKER).o
22 +else
23 + SUBDIRS += workers
24 +endif
25 +
26 DESTDIR=
27
28
29 @@ -13,13 +30,16 @@ all: $(BINS)
30 install:
31 $(INSTALL_BIN) $(BINS) $(DESTDIR)/sbin/
32
33 -
34 -hotplug2: hotplug2.o netlink.o seqnum.o settings.o uevent.o xmemutils.o \
35 - workers/loader.o parser/parser.o parser/buffer.o parser/token.o \
36 - parser/token_queue.o parser/lexer.o rules/ruleset.o rules/rule.o \
37 - rules/condition.o rules/expression.o rules/execution.o \
38 - rules/command.o
39 +hotplug2: $(hotplug2-objs)
40
41 coldplug2: coldplug2.o
42
43 include common.mak
44 +
45 +ifdef STATIC_WORKER
46 + CFLAGS += -DSTATIC_WORKER=1
47 +else
48 + CFLAGS += $(FPIC)
49 + LDFLAGS += -ldl
50 +endif
51 +
52 --- a/common.mak
53 +++ b/common.mak
54 @@ -1,7 +1,10 @@
55 # vim:set sw=8 nosta:
56
57 -CFLAGS=-Os -Wall -g -fPIC
58 -LDFLAGS=-g -ldl
59 +COPTS=-Os -Wall -g
60 +LDFLAGS=-g
61 +
62 +CFLAGS=$(COPTS)
63 +FPIC=-fPIC
64
65 INSTALL=install -c -m 644
66 INSTALL_BIN=install -c -m 755
67 --- a/workers/loader.c
68 +++ b/workers/loader.c
69 @@ -1,5 +1,23 @@
70 #include "loader.h"
71
72 +#ifdef STATIC_WORKER
73 +
74 +extern struct worker_module_t worker_module;
75 +static struct loader_ctx_t static_ctx = {
76 + .module = &worker_module
77 +};
78 +
79 +struct loader_ctx_t *worker_load(const char *name)
80 +{
81 + return &static_ctx;
82 +}
83 +
84 +void worker_free(struct loader_ctx_t *ctx)
85 +{
86 +}
87 +
88 +#else
89 +
90 struct loader_ctx_t *worker_load(const char *name) {
91 struct loader_ctx_t *ctx;
92
93 @@ -12,7 +30,7 @@ struct loader_ctx_t *worker_load(const c
94 return NULL;
95 }
96
97 - ctx->module = dlsym(ctx->dl_handle, "module");
98 + ctx->module = dlsym(ctx->dl_handle, "worker_module");
99 if (ctx->module == NULL) {
100 fprintf(stderr, "Loader error: %s\n", dlerror());
101 worker_free(ctx);
102 @@ -31,3 +49,5 @@ void worker_free(struct loader_ctx_t *ct
103
104 free(ctx);
105 }
106 +
107 +#endif
108 --- a/hotplug2.c
109 +++ b/hotplug2.c
110 @@ -261,17 +261,21 @@ int main(int argc, char *argv[]) {
111 }
112
113 /* Load the worker. */
114 +#ifndef STATIC_WORKER
115 if (settings->worker_name == NULL) {
116 fprintf(stderr, "Missing worker name.\n");
117 settings_clear(settings);
118 exit(1);
119 }
120 +#endif
121 settings->worker = worker_load(settings->worker_name);
122 +#ifndef STATIC_WORKER
123 if (settings->worker == NULL) {
124 fprintf(stderr, "Unable to load worker: %s\n", settings->worker_name);
125 settings_clear(settings);
126 exit(1);
127 }
128 +#endif
129
130 /* Prepare a netlink connection to the kernel. */
131 settings->netlink_socket = netlink_init();
132 --- a/workers/worker_example.c
133 +++ b/workers/worker_example.c
134 @@ -62,7 +62,7 @@ static int worker_example_process(void *
135 return 0;
136 }
137
138 -struct worker_module_t module = {
139 +struct worker_module_t worker_module = {
140 "Hotplug2 example module",
141 worker_example_init,
142 worker_example_deinit,
143 --- a/workers/worker_fork.c
144 +++ b/workers/worker_fork.c
145 @@ -443,7 +443,7 @@ static int worker_fork_process(void *in_
146 return 0;
147 }
148
149 -struct worker_module_t module = {
150 +struct worker_module_t worker_module = {
151 "Hotplug2 forking module",
152 worker_fork_init,
153 worker_fork_deinit,
154 --- a/workers/worker_single.c
155 +++ b/workers/worker_single.c
156 @@ -18,7 +18,7 @@ static int worker_single_process(void *s
157 return 0;
158 }
159
160 -struct worker_module_t module = {
161 +struct worker_module_t worker_module = {
162 "Hotplug2 single process module",
163 worker_single_init,
164 worker_single_deinit,
This page took 0.048943 seconds and 3 git commands to generate.