From 3238ac1e732a9f34762aad61ac6fc20081bc4bb3 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 8 Sep 2014 14:38:45 +0200 Subject: set danger in mds-base's receive_danger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-base.c | 41 ++++++++++++++++++++++++++--------------- src/mds-base.h | 26 +++++++++++++++----------- src/mds-clipboard.c | 19 ------------------- src/mds-kkbd.c | 19 ------------------- 4 files changed, 41 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/mds-base.c b/src/mds-base.c index 3553c69..03ebc27 100644 --- a/src/mds-base.c +++ b/src/mds-base.c @@ -96,6 +96,11 @@ volatile sig_atomic_t terminating = 0; */ volatile sig_atomic_t reexecing = 0; +/** + * Whether the server has been signaled to free unneeded memory + */ +volatile sig_atomic_t danger = 0; + /** * The file descriptor of the socket @@ -289,21 +294,6 @@ void __attribute__((weak)) signal_all(int signo) { (void) signo; } - - -/** - * This function is called when a signal that - * signals that the system is running out of memory - * has been received - * - * By default this function does not do anything - * - * @param signo The signal that has been received - */ -void __attribute__((weak)) received_danger(int signo) -{ - (void) signo; -} # pragma GCC diagnostic pop @@ -363,6 +353,27 @@ void __attribute__((weak)) received_terminate(int signo) } +/** + * This function is called when a signal that + * signals that the system is running out of memory + * has been received + * + * When this function is invoked, it should set `danger` to a non-zero value + * + * @param signo The signal that has been received + */ +void __attribute__((weak)) received_danger(int signo) +{ + (void) signo; + if (danger == 0) + { + danger = 1; + eprint("danger signal received."); + signal_all(signo); + } +} + + /** * Unmarshal the server's saved state * diff --git a/src/mds-base.h b/src/mds-base.h index 0b5f85a..8f62c29 100644 --- a/src/mds-base.h +++ b/src/mds-base.h @@ -149,6 +149,11 @@ extern volatile sig_atomic_t terminating; */ extern volatile sig_atomic_t reexecing; +/** + * Whether the server has been signaled to free unneeded memory + */ +extern volatile sig_atomic_t danger; + /** * The file descriptor of the socket @@ -201,17 +206,6 @@ int server_initialised(void); /* __attribute__((weak)) */ */ void signal_all(int signo); /* __attribute__((weak)) */ -/** - * This function is called when a signal that - * signals that the system is running out of memory - * has been received - * - * By default this function does not do anything - * - * @param signo The signal that has been received - */ -void received_danger(int signo); - /** * This function is called when a signal that * signals the server to re-exec has been received @@ -233,6 +227,16 @@ void received_reexec(int signo); /* __attribute__((weak)) */ */ void received_terminate(int signo); /* __attribute__((weak)) */ +/** + * This function is called when a signal that signals that + * the system is running out of memory has been received + * + * When this function is invoked, it should set `danger` to a non-zero value + * + * @param signo The signal that has been received + */ +void received_danger(int signo); /* __attribute__((weak)) */ + /** * This function should be implemented by the actual server implementation * diff --git a/src/mds-clipboard.c b/src/mds-clipboard.c index 8cd9bea..d7a943f 100644 --- a/src/mds-clipboard.c +++ b/src/mds-clipboard.c @@ -82,11 +82,6 @@ static size_t clipboard_used[CLIPBOARD_LEVELS] = { 0, 0, 0 }; */ static clipitem_t* clipboard[CLIPBOARD_LEVELS]; -/** - * Whether the server should free memory as soon as possible - */ -static volatile sig_atomic_t danger = 0; - /** @@ -337,20 +332,6 @@ int __attribute__((const)) reexec_failure_recover(void) } -/** - * This function is called when a signal that - * signals that the system is running out of memory - * has been received - * - * @param signo The signal that has been received - */ -void received_danger(int signo) -{ - (void) signo; - danger = 1; -} - - /** * Perform the server's mission * diff --git a/src/mds-kkbd.c b/src/mds-kkbd.c index 4deb6f8..f5c44b8 100644 --- a/src/mds-kkbd.c +++ b/src/mds-kkbd.c @@ -187,11 +187,6 @@ static pthread_mutex_t send_mutex; */ static pthread_mutex_t mapping_mutex; -/** - * Whether the server should free memory as soon as possible - */ -static volatile sig_atomic_t danger = 0; - /** @@ -415,20 +410,6 @@ int __attribute__((const)) reexec_failure_recover(void) } -/** - * This function is called when a signal that - * signals that the system is running out of memory - * has been received - * - * @param signo The signal that has been received - */ -void received_danger(int signo) -{ - (void) signo; - danger = 1; -} - - /** * Perform the server's mission * -- cgit v1.2.3-70-g09d2