projects
/
apps
/
pfixtools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use a single version number for the project.
[apps/pfixtools.git]
/
common
/
common.c
diff --git
a/common/common.c
b/common/common.c
index
dc0e194
..
63f0d9a
100644
(file)
--- a/
common/common.c
+++ b/
common/common.c
@@
-280,8
+280,16
@@
int common_setup(const char* pidfilename, bool unsafe, const char* runas_user,
return EXIT_SUCCESS;
}
return EXIT_SUCCESS;
}
-extern initcall_t __madinit[];
-extern exitcall_t __madexit[];
+#include "array.h"
+
+ARRAY(exitcall_t)
+
+static A(exitcall_t) __exit = ARRAY_INIT;
+
+void common_register_exit(exitcall_t exitcall)
+{
+ array_add(__exit, exitcall);
+}
static void common_shutdown(void)
{
static void common_shutdown(void)
{
@@
-289,23
+297,22
@@
static void common_shutdown(void)
info("stopping...");
}
pidfile_close();
info("stopping...");
}
pidfile_close();
- for (int i =
-1; __madexit[i]; i--
) {
-
(*__madexit[i]
)();
+ for (int i =
array_len(__exit) - 1 ; i >= 0 ; --i
) {
+
array_elt(__exit, i
)();
}
}
+ array_wipe(__exit);
}
}
-static void __attribute__((__constructor__,__used__))
-common_initialize(void)
+void common_init(void)
{
{
+ static bool __ran = false;
+ if (__ran) {
+ return;
+ }
if (atexit(common_shutdown)) {
fputs("Cannot hook my atexit function, quitting !\n", stderr);
abort();
}
if (atexit(common_shutdown)) {
fputs("Cannot hook my atexit function, quitting !\n", stderr);
abort();
}
-
- for (int i = 0; __madinit[i]; i++) {
- if ((*__madinit[i])()) {
- exit(EXIT_FAILURE);
- }
- }
+ __ran = true;
}
}