return 0;
}
+extern initcall_t __madinit[], __madexit[];
+
void common_initialize(void)
{
- extern initcall_t __madinit_start, __madinit_end;
+ if (atexit(common_shutdown)) {
+ fputs("Cannot hook my atexit function, quitting !\n", stderr);
+ abort();
+ }
- initcall_t *call_p = &__madinit_start;
- while (call_p < &__madinit_end) {
- (*call_p++)();
+ for (int i = 0; __madinit[i]; i++) {
+ if ((*__madinit[i])()) {
+ exit(EXIT_FAILURE);
+ }
}
}
void common_shutdown(void)
{
- extern exitcall_t __madexit_start, __madexit_end;
-
- exitcall_t *call_p = &__madexit_end;
- while (call_p > &__madexit_start) {
- (*--call_p)();
+ for (int i = -1; __madexit[i]; i--) {
+ (*__madexit[i])();
}
}
#define PFIXTOOLS_H
#include <errno.h>
+#include <fcntl.h>
#include <limits.h>
+#include <netinet/in.h>
#include <pthread.h>
#include <signal.h>
#include <stdbool.h>
#include <stdbool.h>
-#include <stdio.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/types.h>
+#include <time.h>
#include <unistd.h>
#define UNIXERR(fun) \
#define __init __attribute__((__used__,__section__(".mad.init")))
#define __exit __attribute__((__used__,__section__(".mad.exit")))
-#define module_init(fn) static initcall_t __init_##fn __init = fn;
-#define module_exit(fn) static exitcall_t __exit_##fn __exit = fn;
+#define module_init(fn) static __init initcall_t __init_##fn = fn;
+#define module_exit(fn) static __exit exitcall_t __exit_##fn = fn;
/* common.c */
extern sig_atomic_t sigint;