chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
logind: fix operation precedence mix-up
[elogind.git]
/
src
/
journal
/
journalctl.c
diff --git
a/src/journal/journalctl.c
b/src/journal/journalctl.c
index 4c975d3e7c49c3b6c1bcea5df70918f1e86b23c5..e9810c9a3d1cf7b9bb18af0a592fb5563d2ae83c 100644
(file)
--- a/
src/journal/journalctl.c
+++ b/
src/journal/journalctl.c
@@
-40,6
+40,7
@@
#include "pager.h"
#include "logs-show.h"
#include "strv.h"
#include "pager.h"
#include "logs-show.h"
#include "strv.h"
+#include "journal-internal.h"
static OutputMode arg_output = OUTPUT_SHORT;
static bool arg_follow = false;
static OutputMode arg_output = OUTPUT_SHORT;
static bool arg_follow = false;
@@
-48,6
+49,7
@@
static bool arg_no_pager = false;
static int arg_lines = -1;
static bool arg_no_tail = false;
static bool arg_new_id128 = false;
static int arg_lines = -1;
static bool arg_no_tail = false;
static bool arg_new_id128 = false;
+static bool arg_print_header = false;
static bool arg_quiet = false;
static bool arg_local = false;
static bool arg_this_boot = false;
static bool arg_quiet = false;
static bool arg_local = false;
static bool arg_this_boot = false;
@@
-70,6
+72,7
@@
static int help(void) {
" -l --local Only local entries\n"
" -b --this-boot Show data only from current boot\n"
" -D --directory=PATH Show journal files from directory\n"
" -l --local Only local entries\n"
" -b --this-boot Show data only from current boot\n"
" -D --directory=PATH Show journal files from directory\n"
+ " --header Show journal header information\n"
" --new-id128 Generate a new 128 Bit id\n",
program_invocation_short_name);
" --new-id128 Generate a new 128 Bit id\n",
program_invocation_short_name);
@@
-82,7
+85,8
@@
static int parse_argv(int argc, char *argv[]) {
ARG_VERSION = 0x100,
ARG_NO_PAGER,
ARG_NO_TAIL,
ARG_VERSION = 0x100,
ARG_NO_PAGER,
ARG_NO_TAIL,
- ARG_NEW_ID128
+ ARG_NEW_ID128,
+ ARG_HEADER
};
static const struct option options[] = {
};
static const struct option options[] = {
@@
-99,6
+103,7
@@
static int parse_argv(int argc, char *argv[]) {
{ "local", no_argument, NULL, 'l' },
{ "this-boot", no_argument, NULL, 'b' },
{ "directory", required_argument, NULL, 'D' },
{ "local", no_argument, NULL, 'l' },
{ "this-boot", no_argument, NULL, 'b' },
{ "directory", required_argument, NULL, 'D' },
+ { "header", no_argument, NULL, ARG_HEADER },
{ NULL, 0, NULL, 0 }
};
{ NULL, 0, NULL, 0 }
};
@@
-174,6
+179,10
@@
static int parse_argv(int argc, char *argv[]) {
arg_directory = optarg;
break;
arg_directory = optarg;
break;
+ case ARG_HEADER:
+ arg_print_header = true;
+ break;
+
case '?':
return -EINVAL;
case '?':
return -EINVAL;
@@
-225,7
+234,9
@@
static int add_matches(sd_journal *j, char **args) {
STRV_FOREACH(i, args) {
STRV_FOREACH(i, args) {
- if (path_is_absolute(*i)) {
+ if (streq(*i, "+"))
+ r = sd_journal_add_disjunction(j);
+ else if (path_is_absolute(*i)) {
char *p;
const char *path;
struct stat st;
char *p;
const char *path;
struct stat st;
@@
-249,7
+260,7
@@
static int add_matches(sd_journal *j, char **args) {
return -ENOMEM;
}
return -ENOMEM;
}
- r = sd_journal_add_match(j, t,
strlen(t)
);
+ r = sd_journal_add_match(j, t,
0
);
free(t);
} else {
free(p);
free(t);
} else {
free(p);
@@
-259,10
+270,10
@@
static int add_matches(sd_journal *j, char **args) {
free(p);
} else
free(p);
} else
- r = sd_journal_add_match(j, *i,
strlen(*i)
);
+ r = sd_journal_add_match(j, *i,
0
);
if (r < 0) {
if (r < 0) {
- log_error("Failed to add match
: %s"
, strerror(-r));
+ log_error("Failed to add match
'%s': %s", *i
, strerror(-r));
return r;
}
}
return r;
}
}
@@
-299,6
+310,9
@@
int main(int argc, char *argv[]) {
sd_journal *j = NULL;
unsigned line = 0;
bool need_seek = false;
sd_journal *j = NULL;
unsigned line = 0;
bool need_seek = false;
+ sd_id128_t previous_boot_id;
+ bool previous_boot_id_valid = false;
+ bool have_pager;
log_parse_environment();
log_open();
log_parse_environment();
log_open();
@@
-327,6
+341,12
@@
int main(int argc, char *argv[]) {
goto finish;
}
goto finish;
}
+ if (arg_print_header) {
+ journal_print_header(j);
+ r = 0;
+ goto finish;
+ }
+
r = add_this_boot(j);
if (r < 0)
goto finish;
r = add_this_boot(j);
if (r < 0)
goto finish;
@@
-378,7
+398,8
@@
int main(int argc, char *argv[]) {
goto finish;
}
goto finish;
}
- if (!arg_no_pager && !arg_follow) {
+ have_pager = !arg_no_pager && !arg_follow;
+ if (have_pager) {
columns();
pager_open();
}
columns();
pager_open();
}
@@
-390,6
+411,10
@@
int main(int argc, char *argv[]) {
for (;;) {
for (;;) {
for (;;) {
for (;;) {
+ sd_id128_t boot_id;
+ int flags = (arg_show_all*OUTPUT_SHOW_ALL |
+ have_pager*OUTPUT_FULL_WIDTH);
+
if (need_seek) {
r = sd_journal_next(j);
if (r < 0) {
if (need_seek) {
r = sd_journal_next(j);
if (r < 0) {
@@
-401,9
+426,19
@@
int main(int argc, char *argv[]) {
if (r == 0)
break;
if (r == 0)
break;
+ r = sd_journal_get_monotonic_usec(j, NULL, &boot_id);
+ if (r >= 0) {
+ if (previous_boot_id_valid &&
+ !sd_id128_equal(boot_id, previous_boot_id))
+ printf(ANSI_HIGHLIGHT_ON "----- Reboot -----" ANSI_HIGHLIGHT_OFF "\n");
+
+ previous_boot_id = boot_id;
+ previous_boot_id_valid = true;
+ }
+
line ++;
line ++;
- r = output_journal(j, arg_output, line, 0,
arg_show_all
);
+ r = output_journal(j, arg_output, line, 0,
flags
);
if (r < 0)
goto finish;
if (r < 0)
goto finish;