#include "rcyn-protocol.h"
#include "expire.h"
+
#define _HELP_ 'h'
#define _SOCKET_ 's'
#define _VERSION_ 'v'
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"
"\n"
;
+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[] =
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"))
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"))
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;
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");
int count,
const char *args[]
) {
+ bool nextlog;
int rc;
data_key_t key;
data_value_t value;
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)) {