mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-15 03:53:43 +00:00
fixed #162: optional sigabbrev_np()
This commit is contained in:
@@ -195,7 +195,9 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
|
|
||||||
static void _signal_handler(int signum) {
|
static void _signal_handler(int signum) {
|
||||||
US_LOG_INFO_NOLOCK("===== Stopping by SIG%s =====", us_signum_to_string(signum));
|
char *const name = us_signum_to_string(signum);
|
||||||
|
US_LOG_INFO_NOLOCK("===== Stopping by %s =====", name);
|
||||||
|
free(name);
|
||||||
_g_stop = true;
|
_g_stop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,12 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
|
||||||
|
#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 32
|
||||||
|
# define HAS_SIGABBREV_NP
|
||||||
|
#else
|
||||||
|
# include <signal.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
# error WTF dude? Asserts are good things!
|
# error WTF dude? Asserts are good things!
|
||||||
@@ -194,7 +200,22 @@ INLINE char *us_errno_to_string(int error, char *buf, size_t size) {
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE const char *us_signum_to_string(int signum) {
|
INLINE char *us_signum_to_string(int signum) {
|
||||||
const char *const str = sigabbrev_np(signum);
|
# ifdef HAS_SIGABBREV_NP
|
||||||
return (str == NULL ? "???" : str);
|
const char *const name = sigabbrev_np(signum);
|
||||||
|
# else
|
||||||
|
const char *const name = (
|
||||||
|
signum == SIGTERM ? "TERM" :
|
||||||
|
signum == SIGINT ? "INT" :
|
||||||
|
signum == SIGPIPE ? "PIPE" :
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
# endif
|
||||||
|
char *buf;
|
||||||
|
if (name != NULL) {
|
||||||
|
US_ASPRINTF(buf, "SIG%s", name);
|
||||||
|
} else {
|
||||||
|
US_ASPRINTF(buf, "SIG[%d]", signum);
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,9 @@ static void *_server_loop_thread(UNUSED void *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void _signal_handler(int signum) {
|
static void _signal_handler(int signum) {
|
||||||
US_LOG_INFO_NOLOCK("===== Stopping by SIG%s =====", us_signum_to_string(signum));
|
char *const name = us_signum_to_string(signum);
|
||||||
|
US_LOG_INFO_NOLOCK("===== Stopping by %s =====", name);
|
||||||
|
free(name);
|
||||||
us_stream_loop_break(_g_stream);
|
us_stream_loop_break(_g_stream);
|
||||||
us_server_loop_break(_g_server);
|
us_server_loop_break(_g_server);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user