aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/info/mds.texinfo11
-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
5 files changed, 48 insertions, 68 deletions
diff --git a/doc/info/mds.texinfo b/doc/info/mds.texinfo
index 0d721b8..18c1b9d 100644
--- a/doc/info/mds.texinfo
+++ b/doc/info/mds.texinfo
@@ -4162,10 +4162,10 @@ This function is called when a signal that signals the
system is running out of memory has been received. The exact
received signal is specified by the parameter @code{signo}.
When this function is invoked, the server should free up
-all memory it can spare. If the server never has any memory
-that could be freed this function does not been to be
-overridden. If @code{server_characteristics.danger_is_deadly}
-is set, this function will never be called.
+all memory it can spare. When this function is invoked, it
+should set the variable @code{danger} to a non-zero value.
+If @code{server_characteristics.danger_is_deadly} is set,
+this function will never be called.
@item @code{received_reexec} [(@code{int signo}) @arrow{} @code{void}]
This function is called when a signal that signals the
@@ -4280,6 +4280,9 @@ Whether the server has been signaled to terminate.
@item @code{reexecing} [@code{volatile sig_atomic_t}]
Whether the server has been signaled to re-execute.
+@item @code{danger} [@code{volatile sig_atomic_t}]
+Whether the server has been signaled to free unneeded memory.
+
@item @code{socket_fd} [@code{int}]
The file descriptor of the socket that is connected
to the server.
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