diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-04-18 10:20:49 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-04-18 10:20:49 +0200 |
commit | e34d491ee14d6fc76294296552a070004493af32 (patch) | |
tree | 3d3105ad2928c0324ba3428a387c31958299ff22 /src | |
parent | typo + update todo (diff) | |
download | mds-e34d491ee14d6fc76294296552a070004493af32.tar.gz mds-e34d491ee14d6fc76294296552a070004493af32.tar.bz2 mds-e34d491ee14d6fc76294296552a070004493af32.tar.xz |
m doc + iprint and iprintf macros + siginfo on mds, mds-vt and mds-respawn
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/libmdsserver/macros.h | 27 | ||||
-rw-r--r-- | src/mds-base.c | 3 | ||||
-rw-r--r-- | src/mds-respawn.c | 46 | ||||
-rw-r--r-- | src/mds-vt.c | 27 | ||||
-rw-r--r-- | src/mds.c | 4 |
5 files changed, 106 insertions, 1 deletions
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); +} + @@ -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); |