chiark / gitweb /
journald: before closing /dev/kmsg let's unregister the event source
[elogind.git] / src / journal / journalctl.c
index e38721df45c841211a0893d5388e07ce2993bdd4..cc338e0987cf8b21fd03d930a379b8a97bb13ccd 100644 (file)
@@ -48,7 +48,6 @@
 #include "fileio.h"
 #include "build.h"
 #include "pager.h"
-#include "logs-show.h"
 #include "strv.h"
 #include "journal-internal.h"
 #include "journal-def.h"
@@ -94,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,
@@ -114,13 +114,24 @@ typedef struct boot_id_t {
         uint64_t last;
 } boot_id_t;
 
+static void pager_open_if_enabled(void) {
+
+        if (arg_no_pager)
+                return;
+
+        pager_open(arg_pager_end);
+}
+
 static int help(void) {
 
+        pager_open_if_enabled();
+
         printf("%s [OPTIONS...] [MATCHES...]\n\n"
                "Query the journal.\n\n"
                "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"
@@ -248,7 +259,8 @@ 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'                },
-                { NULL,             0,                 NULL, 0                  }
+                { "machine",        required_argument, NULL, 'M'                },
+                {}
         };
 
         int c, r;
@@ -256,13 +268,12 @@ 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) {
 
                 case 'h':
-                        help();
-                        return 0;
+                        return help();
 
                 case ARG_VERSION:
                         puts(PACKAGE_STRING);
@@ -391,6 +402,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;
@@ -543,9 +558,6 @@ static int parse_argv(int argc, char *argv[]) {
                                 return log_oom();
                         break;
 
-                case '?':
-                        return -EINVAL;
-
                 case 'F':
                         arg_field = optarg;
                         break;
@@ -570,17 +582,19 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_reverse = true;
                         break;
 
-                default:
-                        log_error("Unknown option code %c", c);
+                case '?':
                         return -EINVAL;
+
+                default:
+                        assert_not_reached("Unhandled option");
                 }
         }
 
         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;
         }
 
@@ -661,7 +675,7 @@ static int add_matches(sd_journal *j, char **args) {
                                 if (executable_is_script(path, &interpreter) > 0) {
                                         _cleanup_free_ char *comm;
 
-                                        comm = strndup(path_get_file_name(path), 15);
+                                        comm = strndup(basename(path), 15);
                                         if (!comm)
                                                 return log_oom();
 
@@ -884,7 +898,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];
@@ -1463,6 +1477,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) {
@@ -1641,8 +1657,8 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
-        if (!arg_no_pager && !arg_follow)
-                pager_open(arg_pager_end);
+        if (!arg_follow)
+                pager_open_if_enabled();
 
         if (!arg_quiet) {
                 usec_t start, end;