diff options
-rw-r--r-- | src/main-cynadm.c | 45 | ||||
-rw-r--r-- | src/rcyn-client.c | 67 | ||||
-rw-r--r-- | src/rcyn-client.h | 8 | ||||
-rw-r--r-- | src/rcyn-protocol.c | 3 | ||||
-rw-r--r-- | src/rcyn-protocol.h | 3 | ||||
-rw-r--r-- | src/rcyn-protocol.txt | 5 | ||||
-rw-r--r-- | src/rcyn-server.c | 19 |
7 files changed, 105 insertions, 45 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; diff --git a/src/rcyn-client.c b/src/rcyn-client.c index 575d72c..769c6c0 100644 --- a/src/rcyn-client.c +++ b/src/rcyn-client.c @@ -195,48 +195,6 @@ putxkv( } } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - static int wait_input( @@ -679,6 +637,31 @@ rcyn_get( } int +rcyn_log( + rcyn_t *rcyn, + int on, + int off +) { + int rc; + + if (rcyn->type != rcyn_Admin) + return -EPERM; + if (rcyn->async.requests != NULL) + return -EINPROGRESS; + + rc = ensure_opened(rcyn); + if (rc < 0) + return rc; + + rc = putxkv(rcyn, _log_, off ? _off_ : on ? _on_ : 0, 0, 0); + if (rc >= 0) + rc = wait_done(rcyn); + + return rc < 0 ? rc : rcyn->reply.count < 2 ? 0 : !strcmp(rcyn->reply.fields[1], _on_); +} + + +int rcyn_drop( rcyn_t *rcyn, const rcyn_key_t *key diff --git a/src/rcyn-client.h b/src/rcyn-client.h index ad93689..f0fffe9 100644 --- a/src/rcyn-client.h +++ b/src/rcyn-client.h @@ -112,6 +112,14 @@ rcyn_get( extern int +rcyn_log( + rcyn_t *rcyn, + int on, + int off +); + +extern +int rcyn_drop( rcyn_t *rcyn, const rcyn_key_t *key diff --git a/src/rcyn-protocol.c b/src/rcyn-protocol.c index e3071e9..d570b04 100644 --- a/src/rcyn-protocol.c +++ b/src/rcyn-protocol.c @@ -26,6 +26,7 @@ const char _enter_[] = "enter", _get_[] = "get", _leave_[] = "leave", + _log_[] = "log", _rcyn_[] = "rcyn", _set_[] = "set", _test_[] = "test"; @@ -40,6 +41,8 @@ const char _error_[] = "error", _item_[] = "item", _no_[] = "no", + _on_[] = "on", + _off_[] = "off", _yes_[] = "yes"; #if !defined(RCYN_DEFAULT_SOCKET_SCHEME) diff --git a/src/rcyn-protocol.h b/src/rcyn-protocol.h index c408dac..8640186 100644 --- a/src/rcyn-protocol.h +++ b/src/rcyn-protocol.h @@ -24,6 +24,7 @@ extern const char _enter_[], _get_[], _leave_[], + _log_[], _rcyn_[], _set_[], _test_[]; @@ -38,6 +39,8 @@ extern const char _error_[], _item_[], _no_[], + _off_[], + _on_[], _yes_[]; extern const char diff --git a/src/rcyn-protocol.txt b/src/rcyn-protocol.txt index 72789a2..582a912 100644 --- a/src/rcyn-protocol.txt +++ b/src/rcyn-protocol.txt @@ -47,6 +47,11 @@ leave critical (admin) c->s leave [commit|rollback] s->c done|error ... +set/get logging status (admin) + + c->s log [on|off] + s->c done (on|off) + register agent (agent): c->s agent NAME [ARGS...] diff --git a/src/rcyn-server.c b/src/rcyn-server.c index 6974265..b062c89 100644 --- a/src/rcyn-server.c +++ b/src/rcyn-server.c @@ -110,11 +110,11 @@ dolog( const char *fields[] ) { static const char types[3][6] = { "check", "agent", "admin" }; - static const char dir[2] = { '<', '>' }; + static const char dir[2] = { '>', '<' }; int i; - fprintf(stderr, "%p.%s %c%c", cli, types[cli->type], dir[!c2s], dir[!c2s]); + fprintf(stderr, "%p%c%c%s", cli, dir[!c2s], dir[!c2s], types[cli->type]); for (i = 0 ; i < count ; i++) fprintf(stderr, " %s", fields[i]); fprintf(stderr, "\n"); @@ -317,6 +317,7 @@ onrequest( int count, const char *args[] ) { + bool nextlog; int rc; data_key_t key; data_value_t value; @@ -412,6 +413,20 @@ onrequest( send_done_or_error(cli, rc); return; } + if (ckarg(args[0], _log_, 1) && count <= 2) { + nextlog = rcyn_server_log; + if (cli->type != rcyn_Admin) + break; + if (count == 2) { + if (!ckarg(args[1], _on_, 0) && !ckarg(args[1], _off_, 0)) + break; + nextlog = ckarg(args[1], _on_, 0); + } + putx(cli, _done_, nextlog ? _on_ : _off_, NULL); + flushw(cli); + rcyn_server_log = nextlog; + return; + } break; case 's': /* set */ if (ckarg(args[0], _set_, 1) && (count == 6 || count == 7)) { |