X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=common%2Fcommon.h;h=40eb0a2d55b4d255ca1d6708ce678cb5cac19c50;hb=f78d6baee60179e6ce41cc7058a8df5857116010;hp=22299b7150e1bd22ae48ea800238ad86e8112862;hpb=7961b29b3aae8dee45748bf66e30a45c76a47272;p=apps%2Fpfixtools.git diff --git a/common/common.h b/common/common.h index 22299b7..40eb0a2 100644 --- a/common/common.h +++ b/common/common.h @@ -63,11 +63,23 @@ typedef int (*initcall_t)(void); typedef void (*exitcall_t)(void); -#define __init __attribute__((__used__,__section__(".mad.init"))) -#define __exit __attribute__((__used__,__section__(".mad.exit"))) - -#define module_init(fn) static __init initcall_t __init_##fn = fn; -#define module_exit(fn) static __exit exitcall_t __exit_##fn = fn; +void common_register_exit(exitcall_t _exit); +void common_init(void); + +#define module_init(fn) \ + __attribute__((constructor,used)) \ + static void __init_wrapper__ ## fn (void) { \ + common_init(); \ + if (fn() != 0) { \ + exit(-1); \ + } \ + } +#define module_exit(fn) \ + __attribute__((constructor,used)) \ + static void __exit_wrapper ## fn(void) { \ + common_init(); \ + common_register_exit(fn); \ + } #define likely(expr) __builtin_expect((expr) != 0, 1) #define unlikely(expr) __builtin_expect((expr) != 0, 0) @@ -104,8 +116,6 @@ typedef void (*exitcall_t)(void); #define UNIXERR(fun) err("%s:%d:%s %s: %m", \ __FILE__, __LINE__, __func__, fun) -extern sig_atomic_t sigint; -extern sig_atomic_t sighup; extern int log_level; extern bool log_syslog; @@ -130,9 +140,6 @@ int common_setup(const char* pidfile, bool unsafe, const char* runas_user, static inline void common_startup(void) { signal(SIGPIPE, SIG_IGN); - signal(SIGINT, &common_sighandler); - signal(SIGTERM, &common_sighandler); - signal(SIGHUP, &common_sighandler); signal(SIGSEGV, &common_sighandler); }