Commit 11c4f5f6 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

criu: pie, log -- Print tid of writting process

For more convenient log parsing.
Reported-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 969b87e9
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
struct simple_buf { struct simple_buf {
char buf[LOG_SIMPLE_CHUNK]; char buf[LOG_SIMPLE_CHUNK];
char *bp; char *bp;
int prefix_len;
void (*flush)(struct simple_buf *b); void (*flush)(struct simple_buf *b);
}; };
...@@ -18,22 +19,38 @@ static void sbuf_log_flush(struct simple_buf *b); ...@@ -18,22 +19,38 @@ static void sbuf_log_flush(struct simple_buf *b);
static void sbuf_log_init(struct simple_buf *b) static void sbuf_log_init(struct simple_buf *b)
{ {
char pid_buf[12], *s;
int n;
/*
* Format:
*
* pie: pid: string-itself
*/
b->prefix_len = vprint_num(pid_buf, sizeof(pid_buf), sys_gettid(), &s);
b->buf[0] = 'p'; b->buf[0] = 'p';
b->buf[1] = 'i'; b->buf[1] = 'i';
b->buf[2] = 'e'; b->buf[2] = 'e';
b->buf[3] = ':'; b->buf[3] = ':';
b->buf[4] = ' '; b->buf[4] = ' ';
b->bp = b->buf + 5;
for (n = 0; n < b->prefix_len; n++)
b->buf[n + 5] = s[n];
b->buf[n + 5] = ':';
b->buf[n + 6] = ' ';
b->prefix_len += 7;
b->bp = b->buf + b->prefix_len;
b->flush = sbuf_log_flush; b->flush = sbuf_log_flush;
} }
static void sbuf_log_flush(struct simple_buf *b) static void sbuf_log_flush(struct simple_buf *b)
{ {
if (b->bp == b->buf + 5) if (b->bp == b->buf + b->prefix_len)
return; return;
sys_write(logfd, b->buf, b->bp - b->buf); sys_write(logfd, b->buf, b->bp - b->buf);
sbuf_log_init(b); b->bp = b->buf + b->prefix_len;
} }
static void sbuf_putc(struct simple_buf *b, char c) static void sbuf_putc(struct simple_buf *b, char c)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment