aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-09-08 14:38:45 +0200
committerMattias Andrée <maandree@operamail.com>2014-09-08 14:38:45 +0200
commit3238ac1e732a9f34762aad61ac6fc20081bc4bb3 (patch)
tree0b38acecb688750c3a119208342c75c2a0aa6037 /src
parentderp, danger is volatile and atomic (diff)
downloadmds-3238ac1e732a9f34762aad61ac6fc20081bc4bb3.tar.gz
mds-3238ac1e732a9f34762aad61ac6fc20081bc4bb3.tar.bz2
mds-3238ac1e732a9f34762aad61ac6fc20081bc4bb3.tar.xz
set danger in mds-base's receive_danger
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r--src/mds-base.c41
-rw-r--r--src/mds-base.h26
-rw-r--r--src/mds-clipboard.c19
-rw-r--r--src/mds-kkbd.c19
4 files changed, 41 insertions, 64 deletions
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
@@ -364,6 +354,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
*
* @return Non-zero on error
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
@@ -203,17 +208,6 @@ 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
*
* When this function is invoked, it should set `reexecing` and
@@ -234,6 +228,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
*
* This function will be invoked before `initialise_server` (if not re-exec:ing)
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;
-
/**
@@ -338,20 +333,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
*
* @return Non-zero on error
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;
-
/**
@@ -416,20 +411,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
*
* @return Non-zero on error