logs-show.c revision 86aa7ba4f9969bbfc75ebd51f944313695f1a0a1
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2012 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <time.h>
#include <assert.h>
#include <errno.h>
#include "logs-show.h"
#include "log.h"
#include "util.h"
#define PRINT_THRESHOLD 128
static bool contains_unprintable(const void *p, size_t l) {
const char *j;
for (j = p; j < (const char *) p + l; j++)
if (*j < ' ' || *j >= 127)
return true;
return false;
}
int r;
time_t t;
char buf[64];
const void *data;
size_t n = 0;
assert(j);
r = sd_journal_get_realtime_usec(j, &realtime);
if (r < 0) {
return r;
}
log_error("Failed to format time.");
return -EINVAL;
}
length < PRINT_THRESHOLD))) {
}
if (show_all)
else if (n < columns()) {
char *e;
if (!e)
else
printf(" %s", e);
free(e);
}
}
return 0;
}
const void *data;
char *cursor;
char ts[FORMAT_TIMESTAMP_MAX];
int r;
assert(j);
r = sd_journal_get_realtime_usec(j, &realtime);
if (r < 0) {
return r;
}
r = sd_journal_get_cursor(j, &cursor);
if (r < 0) {
return r;
}
printf("%s [%s]\n",
cursor);
const char *c;
if (!c) {
log_error("Invalid field.");
return -EINVAL;
}
printf("\t%.*s=[blob data]\n",
(int) (c - (const char*) data),
(const char*) data);
} else
}
return 0;
}
char sid[33];
int r;
char *cursor;
const void *data;
assert(j);
r = sd_journal_get_realtime_usec(j, &realtime);
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
r = sd_journal_get_cursor(j, &cursor);
if (r < 0) {
return r;
}
printf(".cursor=%s\n"
".realtime=%llu\n"
".monotonic=%llu\n"
".boot_id=%s\n",
(unsigned long long) realtime,
(unsigned long long) monotonic,
const char *c;
if (!c) {
log_error("Invalid field.");
return -EINVAL;
}
} else
}
return 0;
}
static void json_escape(const char* p, size_t l) {
if (contains_unprintable(p, l)) {
bool not_first = false;
while (l > 0) {
if (not_first)
else {
not_first = true;
}
p++;
l--;
}
} else {
while (l > 0) {
if (*p == '"' || *p == '\\') {
} else
p++;
l--;
}
}
}
char *cursor;
const void *data;
char sid[33];
int r;
assert(j);
r = sd_journal_get_realtime_usec(j, &realtime);
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
r = sd_journal_get_cursor(j, &cursor);
if (r < 0) {
return r;
}
if (line == 1)
else
printf("{\n"
"\t\".cursor\" : \"%s\",\n"
"\t\".realtime\" : %llu,\n"
"\t\".monotonic\" : %llu,\n"
"\t\".boot_id\" : \"%s\"",
(unsigned long long) realtime,
(unsigned long long) monotonic,
const char *c;
if (!c) {
log_error("Invalid field.");
return -EINVAL;
}
}
return 0;
}
[OUTPUT_SHORT] = output_short,
};
}
const char *service,
const char *prefix,
unsigned n_columns,
unsigned how_many,
bool show_all) {
char *m = NULL;
sd_journal *j;
int r;
unsigned i;
if (n_columns <= 0)
if (how_many <= 0)
how_many = 10;
if (!prefix)
prefix = "";
r = -ENOMEM;
goto finish;
}
if (r < 0)
goto finish;
r = sd_journal_add_match(j, m, strlen(m));
if (r < 0)
goto finish;
r = sd_journal_seek_tail(j);
if (r < 0)
goto finish;
for (i = 0; i < how_many; i++)
for (i = 0; i < how_many; i++) {
r = sd_journal_next(j);
if (r < 0)
goto finish;
if (r == 0)
break;
if (r < 0)
goto finish;
}
if (m)
free(m);
if (j)
sd_journal_close(j);
return r;
}