Changeset 18725


Ignore:
Timestamp:
2009-12-09T19:50:49+01:00 (7 years ago)
Author:
nbd
Message:

Fix a memory leak in hotplug2 environment handling.
Bump hotplug2 to the latest svn revision, remove obsolete patches.

Memory leak is caused by the way hotplug2 handles environment variables,
using setenv() and unsetenv(). setenv() creates copies of the supplied
strings, but, due to a POSIX blunder, these copies are never destroyed
by unsetenv(), neither in glibc nor uclibc - not until the program
terminates.

Since some events are handled directly in the main process, even when
configured with the "fork" worker, hotplug2 memory usage will keep
growing over time. This can be observed by running "udevtrigger" and
noting the increase in hotplug2 VmRSS after each run.

This patch uses putenv() instead, which leaves storage management to
the caller, so that we can explicitly delete stuff when it's no longer
needed.

Signed-off-by: Aleksandar Radovanovic <biblbroks@…>

Location:
trunk/package/hotplug2
Files:
1 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/package/hotplug2/Makefile

    r18104 r18725  
    99 
    1010PKG_NAME:=hotplug2 
    11 PKG_REV:=199 
     11PKG_REV:=201 
    1212PKG_VERSION:=$(PKG_REV) 
    1313PKG_RELEASE:=1 
  • trunk/package/hotplug2/patches/110-static_worker.patch

    r18106 r18725  
    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 @@ 
     1diff -Naur a/common.mak b/common.mak 
     2--- a/common.mak        2009-11-18 13:15:21.000000000 +0000 
     3+++ b/common.mak        2009-11-18 13:25:18.000000000 +0000 
     4@@ -1,7 +1,7 @@ 
    555 # vim:set sw=8 nosta: 
    566  
    57 -CFLAGS=-Os -Wall -g -fPIC 
     7 COPTS=-Os -Wall -g 
    588-LDFLAGS=-g -ldl 
    59 +COPTS=-Os -Wall -g 
    609+LDFLAGS=-g 
    61 + 
    62 +CFLAGS=$(COPTS) 
    63 +FPIC=-fPIC 
    6410  
    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" 
     11 CFLAGS=$(COPTS) 
     12 FPIC=-fPIC 
     13diff -Naur a/Makefile b/Makefile 
     14--- a/Makefile  2009-11-18 13:15:21.000000000 +0000 
     15+++ b/Makefile  2009-11-18 13:25:18.000000000 +0000 
     16@@ -40,5 +40,6 @@ 
     17   CFLAGS += -DSTATIC_WORKER=1 
     18 else 
     19   CFLAGS += $(FPIC) 
     20+  LDFLAGS += -ldl 
     21 endif 
    7122  
    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, 
Note: See TracChangeset for help on using the changeset viewer.