summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-10-06 15:02:32 +0000
committerRoy Marples <roy@marples.name>2008-10-06 15:02:32 +0000
commitcb44b0a46c9b1c72a84cf65e6b4d6ae735c0e413 (patch)
treec203264849ad86d67ddfb86242ef2aa0680a9b8b
parent4e4c4a5bf4d5c463b79b5648e614b3b780efdbec (diff)
downloadopenrc-cb44b0a46c9b1c72a84cf65e6b4d6ae735c0e413.tar.gz
openrc-cb44b0a46c9b1c72a84cf65e6b4d6ae735c0e413.tar.bz2
openrc-cb44b0a46c9b1c72a84cf65e6b4d6ae735c0e413.tar.xz
#ifdef atexit cleanups calling free as the OS should do this for us, but valgrind debuggers need it.
-rw-r--r--.gitignore2
-rw-r--r--README2
-rw-r--r--src/rc/rc-misc.c4
-rw-r--r--src/rc/rc.c23
-rw-r--r--src/rc/runscript.c11
-rw-r--r--src/rc/start-stop-daemon.c5
6 files changed, 30 insertions, 17 deletions
diff --git a/.gitignore b/.gitignore
index c6b48d8..9ad51cb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
-openrc-0.1.tar.bz2
+openrc-*.tar.bz2
.gdb_history
.gdbinit
diff --git a/README b/README
index c9c0ebf..2c61b0c 100644
--- a/README
+++ b/README
@@ -19,6 +19,8 @@ PREFIX=/usr/local
We don't support building a static OpenRC with PAM.
You may need to use PROGLDFLAGS=-Wl,-Bstatic on glibc instead of just -static.
+If you debug memory under valgrind, add -DDEBUG_MEMORY to your CPPFLAGS
+so that all malloc memory should be freed at exit.
You can also brand OpenRC if you so wish like so
BRANDING=\"Gentoo/$(uname -s)\"
diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c
index d4b3ca0..2784638 100644
--- a/src/rc/rc-misc.c
+++ b/src/rc/rc-misc.c
@@ -61,10 +61,12 @@ static RC_STRINGLIST *rc_conf = NULL;
extern char** environ;
+#ifdef DEBUG_MEMORY
static void _free_rc_conf(void)
{
rc_stringlist_free(rc_conf);
}
+#endif
char *rc_conf_value(const char *setting)
{
@@ -74,7 +76,9 @@ char *rc_conf_value(const char *setting)
if (! rc_conf) {
rc_conf = rc_config_load(RC_CONF);
+#ifdef DEBUG_MEMORY
atexit(_free_rc_conf);
+#endif
/* Support old configs */
if (exists(RC_CONF_OLD)) {
diff --git a/src/rc/rc.c b/src/rc/rc.c
index e6472bd..4fee700 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -137,8 +137,10 @@ static void clean_failed(void)
static void cleanup(void)
{
if (applet && strcmp(applet, "rc") == 0) {
+#ifdef DEBUG_MEMORY
RC_PID *p1 = LIST_FIRST(&service_pids);
RC_PID *p2;
+#endif
if (hook_out)
rc_plugin_run(hook_out, runlevel);
@@ -150,6 +152,16 @@ static void cleanup(void)
free(termios_orig);
}
+ /* Clean runlevel start, stop markers */
+ if (! rc_in_plugin && ! rc_in_logger) {
+ rmdir(RC_STARTING);
+ rmdir(RC_STOPPING);
+ clean_failed();
+
+ rc_logger_close();
+ }
+
+#ifdef DEBUG_MEMORY
while (p1) {
p2 = LIST_NEXT(p1, entries);
free(p1);
@@ -162,17 +174,8 @@ static void cleanup(void)
rc_stringlist_free(types_n);
rc_stringlist_free(types_nua);
rc_deptree_free(deptree);
-
- /* Clean runlevel start, stop markers */
- if (! rc_in_plugin && ! rc_in_logger) {
- rmdir(RC_STARTING);
- rmdir(RC_STOPPING);
- clean_failed();
-
- rc_logger_close();
- }
-
free(runlevel);
+#endif
}
}
diff --git a/src/rc/runscript.c b/src/rc/runscript.c
index c04f967..6dea2b2 100644
--- a/src/rc/runscript.c
+++ b/src/rc/runscript.c
@@ -327,28 +327,29 @@ static void cleanup(void)
start_services(restart_services);
}
+ rc_plugin_unload();
+
+#ifdef DEBUG_MEMORY
rc_stringlist_free(types_b);
rc_stringlist_free(types_n);
rc_stringlist_free(types_nu);
rc_stringlist_free(types_nua);
rc_stringlist_free(types_m);
rc_stringlist_free(types_mua);
-
- rc_plugin_unload();
rc_deptree_free(deptree);
-
rc_stringlist_free(restart_services);
rc_stringlist_free(need_services);
rc_stringlist_free(use_services);
rc_stringlist_free(services);
rc_stringlist_free(applet_list);
rc_stringlist_free(tmplist);
- free (ibsave);
+ free(ibsave);
free(service);
free(prefix);
free(runlevel);
+#endif
- if (*mtime_test && ! rc_in_plugin)
+ if (*mtime_test && !rc_in_plugin)
unlink(mtime_test);
}
diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index e367345..463983e 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -116,13 +116,14 @@ static void free_schedulelist(void)
TAILQ_INIT(&schedule);
}
+#ifdef DEBUG_MEMORY
static void cleanup(void)
{
free(changeuser);
free(nav);
-
free_schedulelist();
}
+#endif
static int parse_signal(const char *sig)
{
@@ -609,7 +610,9 @@ int start_stop_daemon(int argc, char **argv)
unsigned int start_wait = 0;
TAILQ_INIT(&schedule);
+#ifdef DEBUG_MEMORY
atexit(cleanup);
+#endif
signal_setup(SIGINT, handle_signal);
signal_setup(SIGQUIT, handle_signal);