summaryrefslogtreecommitdiff
path: root/src/journal/journalctl.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-12-11 22:04:03 +0100
committerLennart Poettering <lennart@poettering.net>2013-12-11 22:04:03 +0100
commitb6741478e7661c7e580e5dcfd6a6fccd1899c1d0 (patch)
treeb29e463c8113c914a21b45226a845424214ece21 /src/journal/journalctl.c
parent842129f58752864d4433792c9c47d40508c4439a (diff)
journal: add ability to browse journals of running OS containers
This adds the new library call sd_journal_open_container() and a new "-M" switch to journalctl. Particular care is taken that journalctl's "-b" switch resolves to the current boot ID of the container, not the host.
Diffstat (limited to 'src/journal/journalctl.c')
-rw-r--r--src/journal/journalctl.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index f74dde9c48..5d12c2b162 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -93,6 +93,7 @@ static bool arg_catalog = false;
static bool arg_reverse = false;
static int arg_journal_type = 0;
static const char *arg_root = NULL;
+static const char *arg_machine = NULL;
static enum {
ACTION_SHOW,
@@ -120,6 +121,7 @@ static int help(void) {
"Flags:\n"
" --system Show only the system journal\n"
" --user Show only the user journal for current user\n"
+ " -M --machine=CONTAINER Operate on local container\n"
" --since=DATE Start showing entries newer or of the specified date\n"
" --until=DATE Stop showing entries older or of the specified date\n"
" -c --cursor=CURSOR Start showing entries from specified cursor\n"
@@ -247,6 +249,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "dump-catalog", no_argument, NULL, ARG_DUMP_CATALOG },
{ "update-catalog", no_argument, NULL, ARG_UPDATE_CATALOG },
{ "reverse", no_argument, NULL, 'r' },
+ { "machine", required_argument, NULL, 'M' },
{}
};
@@ -255,7 +258,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hefo:aln::qmb::kD:p:c:u:F:xr", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hefo:aln::qmb::kD:p:c:u:F:xrM:", options, NULL)) >= 0) {
switch (c) {
@@ -389,6 +392,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_journal_type |= SD_JOURNAL_CURRENT_USER;
break;
+ case 'M':
+ arg_machine = optarg;
+ break;
+
case 'D':
arg_directory = optarg;
break;
@@ -576,8 +583,8 @@ static int parse_argv(int argc, char *argv[]) {
if (arg_follow && !arg_no_tail && arg_lines < 0)
arg_lines = 10;
- if (arg_directory && arg_file) {
- log_error("Please specify either -D/--directory= or --file=, not both.");
+ if (!!arg_directory + !!arg_file + !!arg_machine > 1) {
+ log_error("Please specify either -D/--directory= or --file= or -M/--machine=, not more than one.");
return -EINVAL;
}
@@ -881,7 +888,7 @@ static int add_boot(sd_journal *j) {
return 0;
if (!arg_boot_descriptor)
- return add_match_this_boot(j);
+ return add_match_this_boot(j, arg_machine);
if (strlen(arg_boot_descriptor) >= 32) {
char tmp = arg_boot_descriptor[32];
@@ -1460,6 +1467,8 @@ int main(int argc, char *argv[]) {
r = sd_journal_open_directory(&j, arg_directory, arg_journal_type);
else if (arg_file)
r = sd_journal_open_files(&j, (const char**) arg_file, 0);
+ else if (arg_machine)
+ r = sd_journal_open_container(&j, arg_machine, 0);
else
r = sd_journal_open(&j, !arg_merge*SD_JOURNAL_LOCAL_ONLY + arg_journal_type);
if (r < 0) {