From 896ca9c44cb695904257065321846ce8cb30a95d Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sat, 11 Feb 2017 08:13:18 +0800 Subject: [PATCH] Add support for the --signal-list option --- README.md | 1 + src/server.c | 7 ++++++- src/utils.c | 10 ++++++++++ src/utils.h | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index efb7ad7..368f2b8 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ OPTIONS: --uid, -u User id to run with --gid, -g Group id to run with --signal, -s Signal to send to the command when exit it (default: SIGHUP) + --signal-list Print a list of supported signals --reconnect, -r Time to reconnect for the client in seconds (default: 10) --readonly, -R Do not allow clients to write to the TTY --client-option, -t Send option to client (format: key=value), repeat to add more options diff --git a/src/server.c b/src/server.c index 8979012..45ffa51 100644 --- a/src/server.c +++ b/src/server.c @@ -28,6 +28,7 @@ static const struct option options[] = { {"uid", required_argument, NULL, 'u'}, {"gid", required_argument, NULL, 'g'}, {"signal", required_argument, NULL, 's'}, + {"signal-list", no_argument, NULL, 1}, {"reconnect", required_argument, NULL, 'r'}, {"index", required_argument, NULL, 'I'}, {"ssl", no_argument, NULL, 'S'}, @@ -41,7 +42,7 @@ static const struct option options[] = { {"debug", required_argument, NULL, 'd'}, {"version", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, - {NULL, 0, 0, 0} + {NULL, 0, 0, 0} }; static const char *opt_string = "p:i:c:u:g:s:r:I:aSC:K:A:Rt:OoBd:vh"; @@ -58,6 +59,7 @@ void print_help() { " --uid, -u User id to run with\n" " --gid, -g Group id to run with\n" " --signal, -s Signal to send to the command when exit it (default: SIGHUP)\n" + " --signal-list Print a list of supported signals\n" " --reconnect, -r Time to reconnect for the client in seconds (default: 10)\n" " --readonly, -R Do not allow clients to write to the TTY\n" " --client-option, -t Send option to client (format: key=value), repeat to add more options\n" @@ -232,6 +234,9 @@ main(int argc, char **argv) { int c; while ((c = getopt_long(start, argv, opt_string, options, NULL)) != -1) { switch (c) { + case 1: + print_sig_list(); + exit(EXIT_SUCCESS); case 'h': print_help(); return 0; diff --git a/src/utils.c b/src/utils.c index b2fe8d6..af6ead5 100644 --- a/src/utils.c +++ b/src/utils.c @@ -88,6 +88,16 @@ get_sig(const char *sig_name) { return -1; } +void print_sig_list() { + char name[30]; + for (int sig = 1; sig < NSIG; sig++) { + if (sys_signame[sig] != NULL) { + strcpy(name, sys_signame[sig]); + printf("%2d) SIG%s (%s)\n", sig, uppercase(name), strsignal(sig)); + } + } +} + int open_uri(char *uri) { #ifdef __APPLE__ diff --git a/src/utils.h b/src/utils.h index 7ac0008..ceef702 100644 --- a/src/utils.h +++ b/src/utils.h @@ -25,6 +25,10 @@ get_sig_name(int sig, char *buf); int get_sig(const char *sig_name); +// print signal list +void +print_sig_list(); + // Open uri with the default application of system int open_uri(char *uri); -- 2.43.4