110-static_worker.patch 3.8 KB

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