diff options
author | José Bollo <jose.bollo@iot.bzh> | 2019-06-13 21:17:46 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2019-06-13 21:17:46 +0200 |
commit | 677cf057551edcaf0ddbe13b646b318f4f5d67b1 (patch) | |
tree | bbadcf568c530bc79f2c2e3c03e5b17bddb9ddff /src/main-cynadm.c | |
parent | 0411d1fbb66d29945cdb27b679112aa37f44bd53 (diff) |
Allow admin to (un)set logging
Change-Id: I5479c9e35512ab77a005692903733f7d1af627a3
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/main-cynadm.c')
-rw-r--r-- | src/main-cynadm.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/main-cynadm.c b/src/main-cynadm.c index 8a5c492..59253f1 100644 --- a/src/main-cynadm.c +++ b/src/main-cynadm.c @@ -29,6 +29,7 @@ #include "rcyn-protocol.h" #include "expire.h" + #define _HELP_ 'h' #define _SOCKET_ 's' #define _VERSION_ 'v' @@ -74,7 +75,7 @@ static const char help__text[] = "\n" - "Commands are: list, set, drop, check, test, cache, clear, quit, help\n" + "Commands are: list, set, drop, check, test, cache, clear, quit, log, help\n" "Type 'help command' to get help on the command\n" "Type 'help expiration' to get help on expirations\n" "\n" @@ -181,6 +182,21 @@ help_test_text[] = static const char +help_log_text[] = + "\n" + "Command: log [on|off]\n" + "\n" + "With the 'on' or 'off' arguments, set the logging state to what required.\n" + "In all cases, prints the logging state.\n" + "\n" + "Examples:\n" + "\n" + " log on activates the logging\n" + "\n" +; + +static +const char help_cache_text[] = "\n" "Command: cache client session user permission\n" @@ -483,6 +499,28 @@ int do_check(int ac, char **av, int (*f)(rcyn_t*,const rcyn_key_t*)) return uc; } +int do_log(int ac, char **av) +{ + int uc, rc; + int on = 0, off = 0; + int n = plink(ac, av, &uc, 2); + + if (n > 1) { + on = !strcmp(av[1], "on"); + off = !strcmp(av[1], "off"); + if (!on && !off) { + fprintf(stderr, "bad argument '%s'\n", av[1]); + return uc; + } + } + rc = rcyn_log(rcyn, on, off); + if (rc < 0) + fprintf(stderr, "error %s\n", strerror(-rc)); + else + fprintf(stdout, "logging %s\n", rc ? "on" : "off"); + return uc; +} + int do_help(int ac, char **av) { if (ac > 1 && !strcmp(av[1], "list")) @@ -499,6 +537,8 @@ int do_help(int ac, char **av) fprintf(stdout, "%s", help_cache_text); else if (ac > 1 && !strcmp(av[1], "clear")) fprintf(stdout, "%s", help_clear_text); + else if (ac > 1 && !strcmp(av[1], "log")) + fprintf(stdout, "%s", help_log_text); else if (ac > 1 && !strcmp(av[1], "quit")) fprintf(stdout, "%s", help_quit_text); else if (ac > 1 && !strcmp(av[1], "help")) @@ -535,6 +575,9 @@ int do_any(int ac, char **av) if (!strcmp(av[0], "cache")) return do_check(ac, av, rcyn_cache_check); + if (!strcmp(av[0], "log")) + return do_log(ac, av); + if (!strcmp(av[0], "clear")) { rcyn_cache_clear(rcyn); return 1; |