+
+extern initcall_t __madinit[];
+extern exitcall_t __madexit[];
+
+static void common_shutdown(void)
+{
+ syslog(LOG_INFO, "Stopping...");
+ pidfile_close();
+
+ for (int i = -1; __madexit[i]; i--) {
+ (*__madexit[i])();
+ }
+}
+
+static void __attribute__((__constructor__,__used__))
+common_initialize(void)
+{
+ 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);
+ }
+ }
+}
+