From: Pierre Habouzit Date: Thu, 29 Nov 2007 10:17:45 +0000 (+0100) Subject: Use even more magic. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=59b31c88179af4a9a9c9074a7b428841ce8661f8;p=apps%2Fpfixtools.git Use even more magic. Signed-off-by: Pierre Habouzit --- diff --git a/common.c b/common.c index 80746ae..7553779 100644 --- a/common.c +++ b/common.c @@ -206,7 +206,15 @@ int drop_privileges(const char *user, const char *group) extern initcall_t __madinit[], __madexit[]; -void common_initialize(void) +static void common_shutdown(void) +{ + 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); @@ -220,9 +228,3 @@ void common_initialize(void) } } -void common_shutdown(void) -{ - for (int i = -1; __madexit[i]; i--) { - (*__madexit[i])(); - } -} diff --git a/common.h b/common.h index 449ead5..801457c 100644 --- a/common.h +++ b/common.h @@ -72,8 +72,6 @@ extern sig_atomic_t sigint; extern sig_atomic_t sighup; void common_sighandler(int sig); -void common_initialize(void); -void common_shutdown(void); /* daemon.c */ int tcp_listen_nonblock(const struct sockaddr *addr, socklen_t len); diff --git a/main-postlicyd.c b/main-postlicyd.c index 70d9d69..01eb9e6 100644 --- a/main-postlicyd.c +++ b/main-postlicyd.c @@ -98,7 +98,6 @@ int main(int argc, char *argv[]) FILE *f = NULL; int res; - common_initialize(); for (int c = 0; (c = getopt(argc, argv, "h" "p:")) >= 0; ) { switch (c) { case 'p': diff --git a/main-srsd.c b/main-srsd.c index 57835cd..8d703af 100644 --- a/main-srsd.c +++ b/main-srsd.c @@ -373,8 +373,6 @@ int main(int argc, char *argv[]) int res; srs_t *srs; - common_initialize(); - for (int c = 0; (c = getopt(argc, argv, "hu" "e:d:p:")) >= 0; ) { switch (c) { case 'e':