aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-base.c
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/mds-base.c
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/mds-base.c')
-rw-r--r--src/mds-base.c41
1 files changed, 26 insertions, 15 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