This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Tarantool -- an efficient key/value data store".
The branch core-yaml-repair has been created
at 195c233035d723bd38f9da462f14661414be8039 (commit)
commit 195c233035d723bd38f9da462f14661414be8039
Author: Yuriy Vostrikov <[email protected]>
Date: Mon Dec 27 13:16:40 2010 +0300
[core] Ensure that all output from administrative console is in YAML.
Fix output to be YAML parsable.
Fix test to actually check for YAML syntax.
Use CRLF consistently.
diff --git a/core/admin.c b/core/admin.c
index d4923b1..2312257 100644
--- a/core/admin.c
+++ b/core/admin.c
@@ -41,26 +41,25 @@
#include <tbuf.h>
#include <util.h>
-static const char help[] =
- "available commands:\r\n"
- "help\r\n"
- "exit\r\n"
- "show info\r\n"
- "show fiber\r\n"
- "show configuration\r\n"
- "show slab\r\n"
- "show palloc\r\n"
- "show stat\r\n"
- "save coredump\r\n"
- "save snapshot\r\n"
- "exec module command\r\n"
- ;
+static const char *help =
+ "available commands:" CRLF
+ " - help" CRLF
+ " - exit" CRLF
+ " - show info" CRLF
+ " - show fiber" CRLF
+ " - show configuration" CRLF
+ " - show slab" CRLF
+ " - show palloc" CRLF
+ " - show stat" CRLF
+ " - save coredump" CRLF
+ " - save snapshot" CRLF
+ " - exec module command" CRLF;
-static const char unknown_command[] = "unknown command. try typing help.\r\n";
+static const char unknown_command[] = "unknown command. try typing help." CRLF;
-#line 64 "core/admin.c"
+#line 63 "core/admin.c"
static const int admin_start = 1;
static const int admin_first_final = 88;
static const int admin_error = 0;
@@ -68,19 +67,28 @@ static const int admin_error = 0;
static const int admin_en_main = 1;
-#line 63 "core/admin.rl"
+#line 62 "core/admin.rl"
+
static void
-ok(struct tbuf *out)
+end(struct tbuf *out)
{
- tbuf_printf(out, "ok\r\n");
+ tbuf_printf(out, "..." CRLF);
}
static void
-end(struct tbuf *out)
+start(struct tbuf *out)
{
- tbuf_printf(out, "---\r\n");
+ tbuf_printf(out, "---" CRLF);
+}
+
+static void
+ok(struct tbuf *out)
+{
+ start(out);
+ tbuf_printf(out, "ok" CRLF);
+ end(out);
}
static int
@@ -100,12 +108,12 @@ admin_dispatch(void)
p = fiber->rbuf->data;
-#line 104 "core/admin.c"
+#line 112 "core/admin.c"
{
cs = admin_start;
}
-#line 109 "core/admin.c"
+#line 117 "core/admin.c"
{
if ( p == pe )
goto _test_eof;
@@ -166,146 +174,164 @@ case 6:
}
goto st0;
tr11:
-#line 140 "core/admin.rl"
+#line 161 "core/admin.rl"
{slab_validate(); ok(out);}
goto st88;
tr18:
-#line 130 "core/admin.rl"
+#line 151 "core/admin.rl"
{return 0;}
goto st88;
tr27:
-#line 127 "core/admin.rl"
+#line 148 "core/admin.rl"
{strend = p;}
-#line 139 "core/admin.rl"
- {mod_exec(strstart, strend - strstart, out); end(out);}
+#line 126 "core/admin.rl"
+ {
+ start(out);
+ mod_exec(strstart, strend - strstart, out);
+ end(out);
+ }
goto st88;
tr31:
-#line 129 "core/admin.rl"
- {tbuf_append(out, help, sizeof(help));}
+#line 120 "core/admin.rl"
+ {
+ start(out);
+ tbuf_append(out, help, strlen(help));
+ end(out);
+ }
goto st88;
tr44:
-#line 137 "core/admin.rl"
+#line 158 "core/admin.rl"
{coredump(60); ok(out);}
goto st88;
tr53:
-#line 138 "core/admin.rl"
+#line 159 "core/admin.rl"
{snapshot(NULL, 0); ok(out);}
goto st88;
tr70:
-#line 94 "core/admin.rl"
+#line 102 "core/admin.rl"
{
tarantool_cfg_iterator_t *i;
char *key, *value;
- tbuf_printf(out, "configuration:\n");
+ start(out);
+ tbuf_printf(out, "configuration:" CRLF);
i = tarantool_cfg_iterator_init();
while ((key = tarantool_cfg_iterator_next(i, &cfg,
&value)) != NULL) {
if (value) {
- tbuf_printf(out, " %s: \"%s\"\n", key,
value);
+ tbuf_printf(out, " %s: \"%s\"" CRLF,
key, value);
free(value);
} else {
- tbuf_printf(out, " %s: (null)\n", key);
+ tbuf_printf(out, " %s: (null)" CRLF,
key);
}
}
end(out);
}
goto st88;
tr84:
-#line 132 "core/admin.rl"
- {fiber_info(out);end(out);}
+#line 153 "core/admin.rl"
+ {start(out); fiber_info(out); end(out);}
goto st88;
tr90:
-#line 131 "core/admin.rl"
- {mod_info(out); end(out);}
+#line 152 "core/admin.rl"
+ {start(out); mod_info(out); end(out);}
goto st88;
tr95:
-#line 135 "core/admin.rl"
- {palloc_stat(out);end(out);}
+#line 156 "core/admin.rl"
+ {start(out); palloc_stat(out); end(out);}
goto st88;
tr103:
-#line 134 "core/admin.rl"
- {slab_stat(out);end(out);}
+#line 155 "core/admin.rl"
+ {start(out); slab_stat(out); end(out);}
goto st88;
tr107:
-#line 136 "core/admin.rl"
- {stat_print(out);end(out);}
+#line 157 "core/admin.rl"
+ {start(out); stat_print(out);end(out);}
goto st88;
st88:
if ( ++p == pe )
goto _test_eof88;
case 88:
-#line 238 "core/admin.c"
+#line 255 "core/admin.c"
goto st0;
tr12:
-#line 140 "core/admin.rl"
+#line 161 "core/admin.rl"
{slab_validate(); ok(out);}
goto st7;
tr19:
-#line 130 "core/admin.rl"
+#line 151 "core/admin.rl"
{return 0;}
goto st7;
tr28:
-#line 127 "core/admin.rl"
+#line 148 "core/admin.rl"
{strend = p;}
-#line 139 "core/admin.rl"
- {mod_exec(strstart, strend - strstart, out); end(out);}
+#line 126 "core/admin.rl"
+ {
+ start(out);
+ mod_exec(strstart, strend - strstart, out);
+ end(out);
+ }
goto st7;
tr32:
-#line 129 "core/admin.rl"
- {tbuf_append(out, help, sizeof(help));}
+#line 120 "core/admin.rl"
+ {
+ start(out);
+ tbuf_append(out, help, strlen(help));
+ end(out);
+ }
goto st7;
tr45:
-#line 137 "core/admin.rl"
+#line 158 "core/admin.rl"
{coredump(60); ok(out);}
goto st7;
tr54:
-#line 138 "core/admin.rl"
+#line 159 "core/admin.rl"
{snapshot(NULL, 0); ok(out);}
goto st7;
tr71:
-#line 94 "core/admin.rl"
+#line 102 "core/admin.rl"
{
tarantool_cfg_iterator_t *i;
char *key, *value;
- tbuf_printf(out, "configuration:\n");
+ start(out);
+ tbuf_printf(out, "configuration:" CRLF);
i = tarantool_cfg_iterator_init();
while ((key = tarantool_cfg_iterator_next(i, &cfg,
&value)) != NULL) {
if (value) {
- tbuf_printf(out, " %s: \"%s\"\n", key,
value);
+ tbuf_printf(out, " %s: \"%s\"" CRLF,
key, value);
free(value);
} else {
- tbuf_printf(out, " %s: (null)\n", key);
+ tbuf_printf(out, " %s: (null)" CRLF,
key);
}
}
end(out);
}
goto st7;
tr85:
-#line 132 "core/admin.rl"
- {fiber_info(out);end(out);}
+#line 153 "core/admin.rl"
+ {start(out); fiber_info(out); end(out);}
goto st7;
tr91:
-#line 131 "core/admin.rl"
- {mod_info(out); end(out);}
+#line 152 "core/admin.rl"
+ {start(out); mod_info(out); end(out);}
goto st7;
tr96:
-#line 135 "core/admin.rl"
- {palloc_stat(out);end(out);}
+#line 156 "core/admin.rl"
+ {start(out); palloc_stat(out); end(out);}
goto st7;
tr104:
-#line 134 "core/admin.rl"
- {slab_stat(out);end(out);}
+#line 155 "core/admin.rl"
+ {start(out); slab_stat(out); end(out);}
goto st7;
tr108:
-#line 136 "core/admin.rl"
- {stat_print(out);end(out);}
+#line 157 "core/admin.rl"
+ {start(out); stat_print(out);end(out);}
goto st7;
st7:
if ( ++p == pe )
goto _test_eof7;
case 7:
-#line 309 "core/admin.c"
+#line 335 "core/admin.c"
if ( (*p) == 10 )
goto st88;
goto st0;
@@ -386,28 +412,28 @@ case 15:
}
goto tr24;
tr24:
-#line 127 "core/admin.rl"
+#line 148 "core/admin.rl"
{strstart = p;}
goto st16;
st16:
if ( ++p == pe )
goto _test_eof16;
case 16:
-#line 397 "core/admin.c"
+#line 423 "core/admin.c"
switch( (*p) ) {
case 10: goto tr27;
case 13: goto tr28;
}
goto st16;
tr25:
-#line 127 "core/admin.rl"
+#line 148 "core/admin.rl"
{strstart = p;}
goto st17;
st17:
if ( ++p == pe )
goto _test_eof17;
case 17:
-#line 411 "core/admin.c"
+#line 437 "core/admin.c"
switch( (*p) ) {
case 10: goto tr27;
case 13: goto tr28;
@@ -1166,14 +1192,17 @@ case 87:
_out: {}
}
-#line 145 "core/admin.rl"
+#line 166 "core/admin.rl"
fiber->rbuf->len -= (void *)pe - (void *)fiber->rbuf->data;
fiber->rbuf->data = pe;
- if (p != pe)
+ if (p != pe) {
+ start(out);
tbuf_append(out, unknown_command, sizeof(unknown_command));
+ end(out);
+ }
return fiber_write(out->data, out->len);
}
diff --git a/core/admin.rl b/core/admin.rl
index a73061c..065a144 100644
--- a/core/admin.rl
+++ b/core/admin.rl
@@ -39,39 +39,47 @@
#include <tbuf.h>
#include <util.h>
-static const char help[] =
- "available commands:\r\n"
- "help\r\n"
- "exit\r\n"
- "show info\r\n"
- "show fiber\r\n"
- "show configuration\r\n"
- "show slab\r\n"
- "show palloc\r\n"
- "show stat\r\n"
- "save coredump\r\n"
- "save snapshot\r\n"
- "exec module command\r\n"
- ;
-
-
-static const char unknown_command[] = "unknown command. try typing help.\r\n";
+static const char *help =
+ "available commands:" CRLF
+ " - help" CRLF
+ " - exit" CRLF
+ " - show info" CRLF
+ " - show fiber" CRLF
+ " - show configuration" CRLF
+ " - show slab" CRLF
+ " - show palloc" CRLF
+ " - show stat" CRLF
+ " - save coredump" CRLF
+ " - save snapshot" CRLF
+ " - exec module command" CRLF;
+
+
+static const char unknown_command[] = "unknown command. try typing help." CRLF;
%%{
machine admin;
write data;
}%%
+
static void
-ok(struct tbuf *out)
+end(struct tbuf *out)
{
- tbuf_printf(out, "ok\r\n");
+ tbuf_printf(out, "..." CRLF);
}
static void
-end(struct tbuf *out)
+start(struct tbuf *out)
+{
+ tbuf_printf(out, "---" CRLF);
+}
+
+static void
+ok(struct tbuf *out)
{
- tbuf_printf(out, "---\r\n");
+ start(out);
+ tbuf_printf(out, "ok" CRLF);
+ end(out);
}
static int
@@ -95,19 +103,32 @@ admin_dispatch(void)
tarantool_cfg_iterator_t *i;
char *key, *value;
- tbuf_printf(out, "configuration:\n");
+ start(out);
+ tbuf_printf(out, "configuration:" CRLF);
i = tarantool_cfg_iterator_init();
while ((key = tarantool_cfg_iterator_next(i, &cfg,
&value)) != NULL) {
if (value) {
- tbuf_printf(out, " %s: \"%s\"\n", key,
value);
+ tbuf_printf(out, " %s: \"%s\"" CRLF,
key, value);
free(value);
} else {
- tbuf_printf(out, " %s: (null)\n", key);
+ tbuf_printf(out, " %s: (null)" CRLF,
key);
}
}
end(out);
}
+ action help {
+ start(out);
+ tbuf_append(out, help, strlen(help));
+ end(out);
+ }
+
+ action mod_exec {
+ start(out);
+ mod_exec(strstart, strend - strstart, out);
+ end(out);
+ }
+
eol = "\n" | "\r\n";
show = "sh"("o"("w")?)?;
info = "in"("f"("o")?)?;
@@ -126,17 +147,17 @@ admin_dispatch(void)
exec = "ex"("e"("c")?)?;
string = [^\r\n]+ >{strstart = p;} %{strend = p;};
- commands = (help %{tbuf_append(out,
help, sizeof(help));} |
- exit %{return 0;}
|
- show " "+ info %{mod_info(out);
end(out);} |
- show " "+ fiber
%{fiber_info(out);end(out);} |
- show " "+ configuration %show_configuration
|
- show " "+ slab
%{slab_stat(out);end(out);} |
- show " "+ palloc
%{palloc_stat(out);end(out);} |
- show " "+ stat
%{stat_print(out);end(out);} |
- save " "+ coredump %{coredump(60);
ok(out);} |
- save " "+ snapshot %{snapshot(NULL, 0);
ok(out);} |
- exec " "+ string %{mod_exec(strstart,
strend - strstart, out); end(out);}|
+ commands = (help %help
|
+ exit %{return 0;}
|
+ show " "+ info %{start(out);
mod_info(out); end(out);} |
+ show " "+ fiber %{start(out);
fiber_info(out); end(out);} |
+ show " "+ configuration %show_configuration
|
+ show " "+ slab %{start(out);
slab_stat(out); end(out);} |
+ show " "+ palloc %{start(out);
palloc_stat(out); end(out);} |
+ show " "+ stat %{start(out);
stat_print(out);end(out);} |
+ save " "+ coredump %{coredump(60);
ok(out);} |
+ save " "+ snapshot %{snapshot(NULL, 0);
ok(out);} |
+ exec " "+ string %mod_exec
|
check " "+ slab %{slab_validate();
ok(out);});
main := commands eol;
@@ -147,8 +168,11 @@ admin_dispatch(void)
fiber->rbuf->len -= (void *)pe - (void *)fiber->rbuf->data;
fiber->rbuf->data = pe;
- if (p != pe)
+ if (p != pe) {
+ start(out);
tbuf_append(out, unknown_command, sizeof(unknown_command));
+ end(out);
+ }
return fiber_write(out->data, out->len);
}
diff --git a/core/fiber.c b/core/fiber.c
index 328e4d0..4ffdab0 100644
--- a/core/fiber.c
+++ b/core/fiber.c
@@ -1043,25 +1043,25 @@ void
fiber_info(struct tbuf *out)
{
struct fiber *fiber;
- tbuf_printf(out, "fibers:\n");
+ tbuf_printf(out, "fibers:" CRLF);
SLIST_FOREACH(fiber, &fibers, link) {
void *stack_top = fiber->coro.stack + fiber->coro.stack_size;
- tbuf_printf(out, " - fid: %4i\n", fiber->fid);
- tbuf_printf(out, " csw: %i\n", fiber->csw);
- tbuf_printf(out, " name: %s\n", fiber->name);
- tbuf_printf(out, " inbox: %i\n", ring_size(fiber->inbox));
- tbuf_printf(out, " fd: %4i\n", fiber->fd);
- tbuf_printf(out, " peer: %s\n", fiber_peer_name(fiber));
- tbuf_printf(out, " stack: %p\n", stack_top);
+ tbuf_printf(out, " - fid: %4i" CRLF, fiber->fid);
+ tbuf_printf(out, " csw: %i" CRLF, fiber->csw);
+ tbuf_printf(out, " name: %s" CRLF, fiber->name);
+ tbuf_printf(out, " inbox: %i" CRLF, ring_size(fiber->inbox));
+ tbuf_printf(out, " fd: %4i" CRLF, fiber->fd);
+ tbuf_printf(out, " peer: %s" CRLF, fiber_peer_name(fiber));
+ tbuf_printf(out, " stack: %p" CRLF, stack_top);
#if CORO_ASM
void *stack_bottom = fiber->coro.stack;
struct frame *frame = fiber->rbp;
- tbuf_printf(out, " backtrace:\n");
+ tbuf_printf(out, " backtrace:" CRLF);
while (stack_bottom < (void *)frame && (void *)frame <
stack_top) {
- tbuf_printf(out, " - { frame: %p, pc: %p }\n",
+ tbuf_printf(out, " - { frame: %p, pc: %p }" CRLF,
frame + 2 * sizeof(void *), frame->ret);
frame = frame->rbp;
}
diff --git a/core/palloc.c b/core/palloc.c
index 874fa9c..d47e14e 100644
--- a/core/palloc.c
+++ b/core/palloc.c
@@ -326,8 +326,8 @@ palloc_stat(struct tbuf *buf)
struct palloc_pool *pool;
int chunks[class_count];
- tbuf_printf(buf, "palloc statistic:\n");
- tbuf_printf(buf, " classes:\n");
+ tbuf_printf(buf, "palloc statistic:" CRLF);
+ tbuf_printf(buf, " classes:" CRLF);
TAILQ_FOREACH(class, &classes, link) {
int free_chunks = 0;
SLIST_FOREACH(chunk, &class->chunks, free_link)
@@ -335,20 +335,20 @@ palloc_stat(struct tbuf *buf)
tbuf_printf(buf,
" - { size: %"PRIu32
- ", free_chunks: %- 6i, busy_chunks: %- 6i }\n",
class->size,
+ ", free_chunks: %- 6i, busy_chunks: %- 6i }" CRLF,
class->size,
free_chunks, class->chunks_count - free_chunks);
}
- tbuf_printf(buf, " pools:\n");
+ tbuf_printf(buf, " pools:" CRLF);
SLIST_FOREACH(pool, &pools, link) {
for (int i = 0; i < class_count; i++)
chunks[i] = 0;
- tbuf_printf(buf, " - name: %s\n alloc: %" PRI_SZ "\n",
+ tbuf_printf(buf, " - name: %s\n alloc: %" PRI_SZ ""
CRLF,
pool->name, pool->allocated);
if (pool->allocated > 0) {
- tbuf_printf(buf, " busy chunks:\n");
+ tbuf_printf(buf, " busy chunks:" CRLF);
SLIST_FOREACH(chunk, &pool->chunks, busy_link)
chunks[chunk->class->i]++;
@@ -357,7 +357,7 @@ palloc_stat(struct tbuf *buf)
TAILQ_FOREACH(class, &classes, link) {
if (chunks[class->i] == 0)
continue;
- tbuf_printf(buf, " - { size: %"PRIu32",
used: %i }\n",
+ tbuf_printf(buf, " - { size: %"PRIu32",
used: %i }" CRLF,
class->size, chunks[class->i]);
if (indent == 0)
diff --git a/core/salloc.c b/core/salloc.c
index 7b845ab..7a78430 100644
--- a/core/salloc.c
+++ b/core/salloc.c
@@ -332,7 +332,7 @@ slab_stat(struct tbuf *t)
struct slab *slab;
int slabs;
i64 items, used, free, total_used = 0;
- tbuf_printf(t, "slab statistics:\n classes:\n");
+ tbuf_printf(t, "slab statistics:\n classes:" CRLF);
for (int i = 0; i < slab_active_classes; i++) {
slabs = items = used = free = 0;
TAILQ_FOREACH(slab, &slab_classes[i].slabs, class_link) {
@@ -348,12 +348,12 @@ slab_stat(struct tbuf *t)
tbuf_printf(t,
" - { item_size: %- 5i, slabs: %- 3i, items: %-
11" PRIi64
- ", bytes_used: %- 12" PRIi64 ", bytes_free: %- 12"
PRIi64 " }\n",
+ ", bytes_used: %- 12" PRIi64 ", bytes_free: %- 12"
PRIi64 " }" CRLF,
(int)slab_classes[i].item_size, slabs, items, used,
free);
}
- tbuf_printf(t, " items_used: %.2f\n", (double)total_used / arena.size
* 100);
- tbuf_printf(t, " arena_used: %.2f\n", (double)arena.used / arena.size
* 100);
+ tbuf_printf(t, " items_used: %.2f" CRLF, (double)total_used /
arena.size * 100);
+ tbuf_printf(t, " arena_used: %.2f" CRLF, (double)arena.used /
arena.size * 100);
}
void
diff --git a/core/stat.c b/core/stat.c
index 96b0ef0..85fd40f 100644
--- a/core/stat.c
+++ b/core/stat.c
@@ -81,7 +81,7 @@ void
stat_print(struct tbuf *buf)
{
int max_len = 0;
- tbuf_printf(buf, "statistics:\n");
+ tbuf_printf(buf, "statistics:" CRLF);
for (int i = 0; i <= stats_max; i++) {
if (stats[i].name == NULL)
@@ -99,7 +99,7 @@ stat_print(struct tbuf *buf)
diff /= SECS;
- tbuf_printf(buf, " %s:%*s{ rps: %- 6i, total: %- 12" PRIi64 "
}\n",
+ tbuf_printf(buf, " %s:%*s{ rps: %- 6i, total: %- 12" PRIi64 "
}" CRLF,
stats[i].name, 1 + max_len -
(int)strlen(stats[i].name), " ",
diff, stats[i].value[SECS]);
}
diff --git a/include/util.h b/include/util.h
index bc7e6f5..6c0dd7d 100644
--- a/include/util.h
+++ b/include/util.h
@@ -98,6 +98,8 @@ typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
+#define CRLF "\r\n"
+
#ifdef GCC
# define FORMAT_PRINTF gnu_printf
#else
diff --git a/test/box/show.result b/test/box/show.result
index 24a7b9e..f00b203 100644
Binary files a/test/box/show.result and b/test/box/show.result differ
diff --git a/test/lib/admin.py b/test/lib/admin.py
index 600bb1f..5145373 100644
--- a/test/lib/admin.py
+++ b/test/lib/admin.py
@@ -25,6 +25,7 @@ import socket
import sys
import string
import cStringIO
+import yaml
class Connection:
def __init__(self, host, port):
@@ -54,13 +55,12 @@ class Connection:
if not buf:
break
res = res + buf;
- if (res.rfind("\n---\r\n") >= 0 or
- res.rfind("module command\r\n") >= 0 or
- res.rfind("try typing help.\r\n") >= 0 or
- res.rfind("ok\r\n") >= 0):
+ if (res.rfind("\r\n...\r\n") >= 0):
break
+ res = yaml.dump(yaml.load(res))
return res
+
def write(self, fragment):
"""This is to support print >> admin, "command" syntax.
For every print statement, write is invoked twice: one to
--
Tarantool -- an efficient key/value data store
_______________________________________________
Mailing list: https://launchpad.net/~tarantool-developers
Post to : [email protected]
Unsubscribe : https://launchpad.net/~tarantool-developers
More help : https://help.launchpad.net/ListHelp