aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--TODO1
-rw-r--r--doc/info/mds.texinfo16
-rw-r--r--src/libmdsserver/macros.h27
-rw-r--r--src/mds-base.c3
-rw-r--r--src/mds-respawn.c46
-rw-r--r--src/mds-vt.c27
-rw-r--r--src/mds.c4
7 files changed, 122 insertions, 2 deletions
diff --git a/TODO b/TODO
index 3ed4d23..879c84f 100644
--- a/TODO
+++ b/TODO
@@ -60,4 +60,5 @@ to autorelease.
IPA keyboard layout
Add support for SIGINFO
+ mds-clipboard mds-echo mds-kkbd mds-registry mds-server
diff --git a/doc/info/mds.texinfo b/doc/info/mds.texinfo
index 79449ae..05cd511 100644
--- a/doc/info/mds.texinfo
+++ b/doc/info/mds.texinfo
@@ -3885,7 +3885,8 @@ this to find out how large the buffer is so it can call
@item @code{eprint} [(@code{const char* format}) @arrow{} @code{int}]
A wrapper for @code{fprintf} that prints a string prefixed
-with the value value of @code{*argv} to @code{stderr}.
+with the value of @code{*argv} to @code{stderr}.
+This wrapper also as a line feed to the end of the text.
Because @code{eprintf} naïvely wraps @code{fprintf}, all
`%':s in the string must be duplicated.
@@ -3894,6 +3895,19 @@ Because @code{eprintf} naïvely wraps @code{fprintf}, all
that can be used to insert values into the format string
just like you can do in @code{fprintf}.
+@item @code{iprint} [(@code{const char* format}) @arrow{} @code{int}]
+A wrapper for @code{fprintf} that prints a string prefixed
+with the value of @code{*argv}, as well a label telling the
+user that the output is part of a state and statistics dump,
+to @code{stderr}. This wrapper also as a line feed to the
+end of the text. Because @code{eprintf} naïvely wraps
+@code{fprintf}, all `%':s in the string must be duplicated.
+
+@item @code{iprintf} [(@code{const char* format, ...}) @arrow{} @code{int}]
+@code{eprint} extends @code{iprint} with variadic arguments
+that can be used to insert values into the format string
+just like you can do in @code{fprintf}.
+
@item @code{with_mutex} [(@code{pthread_mutex_t mutex, instructions})]
Wraps @code{instructions} with @code{errno = pthread_mutex_lock(mutex);}
and @code{errno = pthread_mutex_unlock(mutex);}, so a set of
diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h
index 7ab5f04..41e5567 100644
--- a/src/libmdsserver/macros.h
+++ b/src/libmdsserver/macros.h
@@ -98,6 +98,33 @@
/**
+ * Wrapper for `fprintf` that prints to `stderr` with
+ * the prefixed with information telling the user that
+ * the output is part of an state and statistics dump
+ * and a new line suffixed
+ *
+ * @param format:const char* The format
+ * @return :int The number of bytes written, including the NUL-termination, negative on error
+ */
+#define iprint(format) \
+ fprintf(stderr, "%s: info: " format "\n", *argv)
+
+
+/**
+ * Wrapper for `fprintf` that prints to `stderr` with
+ * the prefixed with information telling the user that
+ * the output is part of an state and statistics dump
+ * and a new line suffixed
+ *
+ * @param format:const char* The format
+ * @param ... The arguments
+ * @return :int The number of bytes written, including the NUL-termination, negative on error
+ */
+#define iprintf(format, ...) \
+ fprintf(stderr, "%s: info: " format "\n", *argv, __VA_ARGS__)
+
+
+/**
* Wrapper for `pthread_mutex_lock` and `pthread_mutex_unlock`
*
* @param mutex:pthread_mutex_t The mutex
diff --git a/src/mds-base.c b/src/mds-base.c
index b944d08..2e6a3b1 100644
--- a/src/mds-base.c
+++ b/src/mds-base.c
@@ -373,10 +373,13 @@ void __attribute__((weak)) received_danger(int signo)
*
* @param signo The signal that has been received
*/
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wsuggest-attribute=const"
void __attribute__((weak)) received_info(int signo)
{
(void) signo;
}
+# pragma GCC diagnostic pop
/**
diff --git a/src/mds-respawn.c b/src/mds-respawn.c
index 014fce3..785eb67 100644
--- a/src/mds-respawn.c
+++ b/src/mds-respawn.c
@@ -64,7 +64,7 @@ static int interval = RESPAWN_TIME_LIMIT_SECONDS;
static size_t servers = 0;
/**
- * Command line arguments, for each server — concatenated, with NULL termination
+ * Command line arguments, for each server — concatenated, with NULL-termination
*/
static char** commands_args = NULL;
@@ -535,3 +535,47 @@ int master_loop(void)
return rc;
}
+
+/**
+ * This function is called when a signal that
+ * signals that the system to dump state information
+ * and statistics has been received
+ *
+ * @param signo The signal that has been received
+ */
+void received_info(int signo)
+{
+ server_state_t state;
+ size_t i, n = servers;
+ char** cmdline;
+ struct timespec now;
+ (void) signo;
+ if (monotone(&now) < 0)
+ iprint("(unable to get current time)");
+ else
+ iprintf("current time: %ji.%09li", (intmax_t)(now.tv_sec), (long)(now.tv_nsec));
+ iprintf("do-not-resuscitate period: %i seconds", interval);
+ iprintf("managed servers: %zu", n);
+ iprintf("alive servers: %zu", live_count);
+ iprintf("reviving: %s", reviving ? "yes" : "no");
+ for (i = 0; i < n; i++)
+ {
+ state = states[i];
+ cmdline = commands[i];
+ iprintf("managed server %zu: pid: %li", i, (long)(state.pid));
+ iprintf("managed server %zu: state: %s", i,
+ state.state == UNBORN ? "not started yet" :
+ state.state == ALIVE ? "up and running" :
+ state.state == DEAD ? "about to be respawn" :
+ state.state == DEAD_AND_BURIED ? "requires SIGUSR2 to respawn" :
+ state.state == CREMATED ? "will never respawn" :
+ "unrecognised state, something is wrong here!");
+ iprintf("managed server %zu: started: %ji.%09li", i,
+ (intmax_t)(state.started.tv_sec),
+ (long)(state.started.tv_nsec));
+ iprintf("managed server %zu: cmdline:", i);
+ while (*cmdline)
+ iprintf(" %z", *cmdline++);
+ }
+}
+
diff --git a/src/mds-vt.c b/src/mds-vt.c
index 70e8c2e..5072d85 100644
--- a/src/mds-vt.c
+++ b/src/mds-vt.c
@@ -903,3 +903,30 @@ void vt_construct_mode(int vt_switch_control, int vt_leave_signal,
mode->acqsig = (short int)vt_enter_signal;
}
+
+/**
+ * This function is called when a signal that
+ * signals that the system to dump state information
+ * and statistics has been received
+ *
+ * @param signo The signal that has been received
+ */
+void received_info(int signo)
+{
+ (void) signo;
+ iprintf("next message ID: %" PRIu32, message_id);
+ iprintf("connected: %s", connected ? "yes" : "no");
+ iprintf("VT of the display: %i", display_vt);
+ iprintf("TTY FD of the display: %i", display_tty_fd);
+ iprintf("TTY in foreground: %s", vt_is_active ? "yes" : "no");
+ iprintf("old VT stat: mode: %lo", (long)(old_vt_stat.st_mode));
+ iprintf("old VT stat: uid: %li", (long)(old_vt_stat.st_uid));
+ iprintf("old VT stat: gid: %li", (long)(old_vt_stat.st_gid));
+ iprintf("switching VT: %s", switching_vt ? "yes" : "no");
+ iprintf("VT-file pathname: %s", vtfile_path);
+ iprintf("secondary socket FD: %i", secondary_socket_fd);
+ iprintf("secondary thread started: %s", secondary_thread_started ? "yes" : "no");
+ iprintf("secondary thread failed: %s", secondary_thread_failed ? "yes" : "no");
+ iprintf("non-exclusive counter: %zi", nonexclusive_counter);
+}
+
diff --git a/src/mds.c b/src/mds.c
index 76bc4ee..b6f6abb 100644
--- a/src/mds.c
+++ b/src/mds.c
@@ -112,6 +112,10 @@ int main(int argc_, char** argv_)
if (xsigaction(SIGDANGER, SIG_IGN) < 0)
xperror(*argv);
+ /* Set up to ignore SIGINFO. */
+ if (xsigaction(SIGINFO, SIG_IGN) < 0)
+ xperror(*argv);
+
/* Remove umask. */
saved_umask = umask(0);