140-worker_fork_fix.patch 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --- a/action.c
  2. +++ b/action.c
  3. @@ -39,7 +39,7 @@ static void action_dumb(const struct set
  4. * Returns: Newly allocated string in "key=value" form
  5. *
  6. */
  7. -static char* alloc_env(const char *key, const char *value) {
  8. +char* alloc_env(const char *key, const char *value) {
  9. size_t keylen, vallen;
  10. char *combined;
  11. --- a/action.h
  12. +++ b/action.h
  13. @@ -12,5 +12,6 @@
  14. #include "settings.h"
  15. void action_perform(struct settings_t *, struct uevent_t *);
  16. +char* alloc_env(const char *, const char *);
  17. #endif /* ifndef ACTION_H */
  18. --- a/workers/worker_fork.c
  19. +++ b/workers/worker_fork.c
  20. @@ -380,6 +380,7 @@ static void worker_fork_deinit(void *in_
  21. static int worker_fork_process(void *in_ctx, struct uevent_t *uevent) {
  22. + char **env;
  23. int i;
  24. struct worker_fork_child_t *child;
  25. struct worker_fork_ctx_t *ctx = in_ctx;
  26. @@ -406,6 +407,12 @@ static int worker_fork_process(void *in_
  27. * No child process is currently available.
  28. */
  29. if (child == NULL) {
  30. + env = xmalloc(sizeof(char *) * uevent->env_vars_c);
  31. + for (i = 0; i < uevent->env_vars_c; i++) {
  32. + env[i] = alloc_env(uevent->env_vars[i].key, uevent->env_vars[i].value);
  33. + putenv(env[i]);
  34. + }
  35. +
  36. /*
  37. * Are the matching rules trivial enough that we
  38. * can execute them in the main process?
  39. @@ -421,6 +428,12 @@ static int worker_fork_process(void *in_
  40. */
  41. if (ctx->children_count < ctx->max_children)
  42. child = worker_fork_spawn(ctx);
  43. +
  44. + for (i = 0; i < uevent->env_vars_c; i++) {
  45. + unsetenv(uevent->env_vars[i].key);
  46. + free(env[i]);
  47. + }
  48. + free(env);
  49. }
  50. /*