journalctl.c | journalctl.c | |||
---|---|---|---|---|
skipping to change at line 35 | skipping to change at line 35 | |||
#include <string.h> | #include <string.h> | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <unistd.h> | #include <unistd.h> | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#include <sys/poll.h> | #include <sys/poll.h> | |||
#include <time.h> | #include <time.h> | |||
#include <getopt.h> | #include <getopt.h> | |||
#include <sys/stat.h> | #include <sys/stat.h> | |||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | |||
#include <linux/fs.h> | #include <linux/fs.h> | |||
#include <locale.h> | ||||
#include <langinfo.h> | ||||
#include <systemd/sd-journal.h> | #include <systemd/sd-journal.h> | |||
#include "log.h" | #include "log.h" | |||
#include "util.h" | #include "util.h" | |||
#include "path-util.h" | #include "path-util.h" | |||
#include "build.h" | #include "build.h" | |||
#include "pager.h" | #include "pager.h" | |||
#include "logs-show.h" | #include "logs-show.h" | |||
#include "strv.h" | #include "strv.h" | |||
skipping to change at line 61 | skipping to change at line 63 | |||
#define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE) | #define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE) | |||
static OutputMode arg_output = OUTPUT_SHORT; | static OutputMode arg_output = OUTPUT_SHORT; | |||
static bool arg_follow = false; | static bool arg_follow = false; | |||
static bool arg_show_all = false; | static bool arg_show_all = false; | |||
static bool arg_no_pager = false; | static bool arg_no_pager = false; | |||
static int arg_lines = -1; | static int arg_lines = -1; | |||
static bool arg_no_tail = false; | static bool arg_no_tail = false; | |||
static bool arg_quiet = false; | static bool arg_quiet = false; | |||
static bool arg_local = false; | static bool arg_merge = false; | |||
static bool arg_this_boot = false; | static bool arg_this_boot = false; | |||
static const char *arg_directory = NULL; | static const char *arg_directory = NULL; | |||
static int arg_priorities = 0xFF; | static int arg_priorities = 0xFF; | |||
static const char *arg_verify_key = NULL; | static const char *arg_verify_key = NULL; | |||
#ifdef HAVE_GCRYPT | #ifdef HAVE_GCRYPT | |||
static usec_t arg_interval = DEFAULT_FSS_INTERVAL_USEC; | static usec_t arg_interval = DEFAULT_FSS_INTERVAL_USEC; | |||
#endif | #endif | |||
static enum { | static enum { | |||
ACTION_SHOW, | ACTION_SHOW, | |||
ACTION_NEW_ID128, | ACTION_NEW_ID128, | |||
ACTION_PRINT_HEADER, | ACTION_PRINT_HEADER, | |||
ACTION_SETUP_KEYS, | ACTION_SETUP_KEYS, | |||
ACTION_VERIFY | ACTION_VERIFY, | |||
ACTION_DISK_USAGE, | ||||
} arg_action = ACTION_SHOW; | } arg_action = ACTION_SHOW; | |||
static int help(void) { | static int help(void) { | |||
printf("%s [OPTIONS...] [MATCH]\n\n" | printf("%s [OPTIONS...] [MATCH]\n\n" | |||
"Send control commands to or query the journal.\n\n" | "Send control commands to or query the journal.\n\n" | |||
" -h --help Show this help\n" | " -h --help Show this help\n" | |||
" --version Show package version\n" | " --version Show package version\n" | |||
" --no-pager Do not pipe output into a pager\n" | " --no-pager Do not pipe output into a pager\n" | |||
" -a --all Show all fields, including long an d unprintable\n" | " -a --all Show all fields, including long an d unprintable\n" | |||
" -f --follow Follow journal\n" | " -f --follow Follow journal\n" | |||
" -n --lines=INTEGER Journal entries to show\n" | " -n --lines=INTEGER Journal entries to show\n" | |||
" --no-tail Show all lines, even in follow mod e\n" | " --no-tail Show all lines, even in follow mod e\n" | |||
" -o --output=STRING Change journal output mode (short, short-monotonic,\n" | " -o --output=STRING Change journal output mode (short, short-monotonic,\n" | |||
" verbose, export, json, cat)\n" | " verbose, export, json, json-pretty , cat)\n" | |||
" -q --quiet Don't show privilege warning\n" | " -q --quiet Don't show privilege warning\n" | |||
" -l --local Only local entries\n" | " -m --merge Show entries from all available jo urnals\n" | |||
" -b --this-boot Show data only from current boot\n " | " -b --this-boot Show data only from current boot\n " | |||
" -D --directory=PATH Show journal files from directory\ n" | " -D --directory=PATH Show journal files from directory\ n" | |||
" -p --priority=RANGE Show only messages within the spec ified priority range\n\n" | " -p --priority=RANGE Show only messages within the spec ified priority range\n\n" | |||
"Commands:\n" | "Commands:\n" | |||
" --new-id128 Generate a new 128 Bit ID\n" | " --new-id128 Generate a new 128 Bit ID\n" | |||
" --header Show journal header information\n" | " --header Show journal header information\n" | |||
" --disk-usage Show total disk usage\n" | ||||
#ifdef HAVE_GCRYPT | #ifdef HAVE_GCRYPT | |||
" --setup-keys Generate new FSS key pair\n" | " --setup-keys Generate new FSS key pair\n" | |||
" --interval=TIME Time interval for changing the FSS sealing key\n" | " --interval=TIME Time interval for changing the FSS sealing key\n" | |||
" --verify Verify journal file consistency\n" | " --verify Verify journal file consistency\n" | |||
" --verify-key=KEY Specify FSS verification key\n" | " --verify-key=KEY Specify FSS verification key\n" | |||
#endif | #endif | |||
, program_invocation_short_name); | , program_invocation_short_name); | |||
return 0; | return 0; | |||
} | } | |||
skipping to change at line 121 | skipping to change at line 125 | |||
enum { | enum { | |||
ARG_VERSION = 0x100, | ARG_VERSION = 0x100, | |||
ARG_NO_PAGER, | ARG_NO_PAGER, | |||
ARG_NO_TAIL, | ARG_NO_TAIL, | |||
ARG_NEW_ID128, | ARG_NEW_ID128, | |||
ARG_HEADER, | ARG_HEADER, | |||
ARG_SETUP_KEYS, | ARG_SETUP_KEYS, | |||
ARG_INTERVAL, | ARG_INTERVAL, | |||
ARG_VERIFY, | ARG_VERIFY, | |||
ARG_VERIFY_KEY | ARG_VERIFY_KEY, | |||
ARG_DISK_USAGE | ||||
}; | }; | |||
static const struct option options[] = { | static const struct option options[] = { | |||
{ "help", no_argument, NULL, 'h' }, | { "help", no_argument, NULL, 'h' }, | |||
{ "version" , no_argument, NULL, ARG_VERSION }, | { "version" , no_argument, NULL, ARG_VERSION }, | |||
{ "no-pager", no_argument, NULL, ARG_NO_PAGER }, | { "no-pager", no_argument, NULL, ARG_NO_PAGER }, | |||
{ "follow", no_argument, NULL, 'f' }, | { "follow", no_argument, NULL, 'f' }, | |||
{ "output", required_argument, NULL, 'o' }, | { "output", required_argument, NULL, 'o' }, | |||
{ "all", no_argument, NULL, 'a' }, | { "all", no_argument, NULL, 'a' }, | |||
{ "lines", required_argument, NULL, 'n' }, | { "lines", required_argument, NULL, 'n' }, | |||
{ "no-tail", no_argument, NULL, ARG_NO_TAIL }, | { "no-tail", no_argument, NULL, ARG_NO_TAIL }, | |||
{ "new-id128", no_argument, NULL, ARG_NEW_ID128 }, | { "new-id128", no_argument, NULL, ARG_NEW_ID128 }, | |||
{ "quiet", no_argument, NULL, 'q' }, | { "quiet", no_argument, NULL, 'q' }, | |||
{ "local", no_argument, NULL, 'l' }, | { "merge", no_argument, NULL, 'm' }, | |||
{ "this-boot", no_argument, NULL, 'b' }, | { "this-boot", no_argument, NULL, 'b' }, | |||
{ "directory", required_argument, NULL, 'D' }, | { "directory", required_argument, NULL, 'D' }, | |||
{ "header", no_argument, NULL, ARG_HEADER }, | { "header", no_argument, NULL, ARG_HEADER }, | |||
{ "priority", no_argument, NULL, 'p' }, | { "priority", no_argument, NULL, 'p' }, | |||
{ "setup-keys", no_argument, NULL, ARG_SETUP_KEYS }, | { "setup-keys", no_argument, NULL, ARG_SETUP_KEYS }, | |||
{ "interval", required_argument, NULL, ARG_INTERVAL }, | { "interval", required_argument, NULL, ARG_INTERVAL }, | |||
{ "verify", no_argument, NULL, ARG_VERIFY }, | { "verify", no_argument, NULL, ARG_VERIFY }, | |||
{ "verify-key", required_argument, NULL, ARG_VERIFY_KEY }, | { "verify-key", required_argument, NULL, ARG_VERIFY_KEY }, | |||
{ "disk-usage", no_argument, NULL, ARG_DISK_USAGE }, | ||||
{ NULL, 0, NULL, 0 } | { NULL, 0, NULL, 0 } | |||
}; | }; | |||
int c, r; | int c, r; | |||
assert(argc >= 0); | assert(argc >= 0); | |||
assert(argv); | assert(argv); | |||
while ((c = getopt_long(argc, argv, "hfo:an:qlbD:p:", options, NULL )) >= 0) { | while ((c = getopt_long(argc, argv, "hfo:an:qmbD:p:", options, NULL )) >= 0) { | |||
switch (c) { | switch (c) { | |||
case 'h': | case 'h': | |||
help(); | help(); | |||
return 0; | return 0; | |||
case ARG_VERSION: | case ARG_VERSION: | |||
puts(PACKAGE_STRING); | puts(PACKAGE_STRING); | |||
puts(DISTRIBUTION); | puts(DISTRIBUTION); | |||
skipping to change at line 207 | skipping to change at line 213 | |||
break; | break; | |||
case ARG_NEW_ID128: | case ARG_NEW_ID128: | |||
arg_action = ACTION_NEW_ID128; | arg_action = ACTION_NEW_ID128; | |||
break; | break; | |||
case 'q': | case 'q': | |||
arg_quiet = true; | arg_quiet = true; | |||
break; | break; | |||
case 'l': | case 'm': | |||
arg_local = true; | arg_merge = true; | |||
break; | break; | |||
case 'b': | case 'b': | |||
arg_this_boot = true; | arg_this_boot = true; | |||
break; | break; | |||
case 'D': | case 'D': | |||
arg_directory = optarg; | arg_directory = optarg; | |||
break; | break; | |||
case ARG_HEADER: | case ARG_HEADER: | |||
arg_action = ACTION_PRINT_HEADER; | arg_action = ACTION_PRINT_HEADER; | |||
break; | break; | |||
case ARG_VERIFY: | case ARG_VERIFY: | |||
arg_action = ACTION_VERIFY; | arg_action = ACTION_VERIFY; | |||
break; | break; | |||
case ARG_DISK_USAGE: | ||||
arg_action = ACTION_DISK_USAGE; | ||||
break; | ||||
#ifdef HAVE_GCRYPT | #ifdef HAVE_GCRYPT | |||
case ARG_SETUP_KEYS: | case ARG_SETUP_KEYS: | |||
arg_action = ACTION_SETUP_KEYS; | arg_action = ACTION_SETUP_KEYS; | |||
break; | break; | |||
case ARG_VERIFY_KEY: | case ARG_VERIFY_KEY: | |||
arg_action = ACTION_VERIFY; | arg_action = ACTION_VERIFY; | |||
arg_verify_key = optarg; | arg_verify_key = optarg; | |||
arg_local = true; | arg_merge = false; | |||
break; | break; | |||
case ARG_INTERVAL: | case ARG_INTERVAL: | |||
r = parse_usec(optarg, &arg_interval); | r = parse_usec(optarg, &arg_interval); | |||
if (r < 0 || arg_interval <= 0) { | if (r < 0 || arg_interval <= 0) { | |||
log_error("Failed to parse sealing key chan ge interval: %s", optarg); | log_error("Failed to parse sealing key chan ge interval: %s", optarg); | |||
return -EINVAL; | return -EINVAL; | |||
} | } | |||
break; | break; | |||
#else | #else | |||
skipping to change at line 628 | skipping to change at line 638 | |||
hn = gethostname_malloc(); | hn = gethostname_malloc(); | |||
if (hn) { | if (hn) { | |||
hostname_cleanup(hn); | hostname_cleanup(hn); | |||
fprintf(stderr, "\nThe keys have been generated for host %s/" SD_ID128_FORMAT_STR ".\n", hn, SD_ID128_FORMAT_VAL(machine)); | fprintf(stderr, "\nThe keys have been generated for host %s/" SD_ID128_FORMAT_STR ".\n", hn, SD_ID128_FORMAT_VAL(machine)); | |||
} else | } else | |||
fprintf(stderr, "\nThe keys have been generated for host " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(machine)); | fprintf(stderr, "\nThe keys have been generated for host " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(machine)); | |||
#ifdef HAVE_QRENCODE | #ifdef HAVE_QRENCODE | |||
fprintf(stderr, "\nTo transfer the verification key to your | /* If this is not an UTF-8 system don't print any QR codes | |||
phone please scan the QR code below:\n\n"); | */ | |||
print_qr_code(stderr, seed, seed_size, n, arg_interval, hn, | setlocale(LC_CTYPE, ""); | |||
machine); | ||||
if (streq_ptr(nl_langinfo(CODESET), "UTF-8")) { | ||||
fputs("\nTo transfer the verification key to your p | ||||
hone please scan the QR code below:\n\n", stderr); | ||||
print_qr_code(stderr, seed, seed_size, n, arg_inter | ||||
val, hn, machine); | ||||
} | ||||
#endif | #endif | |||
free(hn); | free(hn); | |||
} | } | |||
r = 0; | r = 0; | |||
finish: | finish: | |||
if (fd >= 0) | if (fd >= 0) | |||
close_nointr_nofail(fd); | close_nointr_nofail(fd); | |||
skipping to change at line 730 | skipping to change at line 745 | |||
} | } | |||
if (arg_action == ACTION_SETUP_KEYS) { | if (arg_action == ACTION_SETUP_KEYS) { | |||
r = setup_keys(); | r = setup_keys(); | |||
goto finish; | goto finish; | |||
} | } | |||
if (arg_directory) | if (arg_directory) | |||
r = sd_journal_open_directory(&j, arg_directory, 0); | r = sd_journal_open_directory(&j, arg_directory, 0); | |||
else | else | |||
r = sd_journal_open(&j, arg_local ? SD_JOURNAL_LOCAL_ONLY : 0); | r = sd_journal_open(&j, arg_merge ? 0 : SD_JOURNAL_LOCAL_ON LY); | |||
if (r < 0) { | if (r < 0) { | |||
log_error("Failed to open journal: %s", strerror(-r)); | log_error("Failed to open journal: %s", strerror(-r)); | |||
goto finish; | goto finish; | |||
} | } | |||
if (arg_action == ACTION_VERIFY) { | if (arg_action == ACTION_VERIFY) { | |||
r = verify(j); | r = verify(j); | |||
goto finish; | goto finish; | |||
} | } | |||
if (arg_action == ACTION_PRINT_HEADER) { | if (arg_action == ACTION_PRINT_HEADER) { | |||
journal_print_header(j); | journal_print_header(j); | |||
r = 0; | r = 0; | |||
goto finish; | goto finish; | |||
} | } | |||
if (arg_action == ACTION_DISK_USAGE) { | ||||
uint64_t bytes; | ||||
char sbytes[FORMAT_BYTES_MAX]; | ||||
r = sd_journal_get_usage(j, &bytes); | ||||
if (r < 0) | ||||
goto finish; | ||||
printf("Journals take up %s on disk.\n", format_bytes(sbyte | ||||
s, sizeof(sbytes), bytes)); | ||||
r = 0; | ||||
goto finish; | ||||
} | ||||
#ifdef HAVE_ACL | #ifdef HAVE_ACL | |||
if (access("/var/log/journal", F_OK) < 0 && geteuid() != 0 && in_gr oup("adm") <= 0) { | if (access("/var/log/journal", F_OK) < 0 && geteuid() != 0 && in_gr oup("adm") <= 0) { | |||
log_error("Unprivileged users can't see messages unless per sistent log storage is enabled. Users in the group 'adm' can always see mes sages."); | log_error("Unprivileged users can't see messages unless per sistent log storage is enabled. Users in the group 'adm' can always see mes sages."); | |||
r = -EACCES; | r = -EACCES; | |||
goto finish; | goto finish; | |||
} | } | |||
if (!arg_quiet && geteuid() != 0 && in_group("adm") <= 0) | if (!arg_quiet && geteuid() != 0 && in_group("adm") <= 0) | |||
log_warning("Showing user generated messages only. Users in the group 'adm' can see all messages. Pass -q to turn this notice off."); | log_warning("Showing user generated messages only. Users in the group 'adm' can see all messages. Pass -q to turn this notice off."); | |||
#else | #else | |||
skipping to change at line 823 | skipping to change at line 851 | |||
} | } | |||
if (r < 0) { | if (r < 0) { | |||
log_error("Failed to iterate through journal: %s", strerror (-r)); | log_error("Failed to iterate through journal: %s", strerror (-r)); | |||
goto finish; | goto finish; | |||
} | } | |||
on_tty(); | on_tty(); | |||
have_pager = !arg_no_pager && !arg_follow && pager_open(); | have_pager = !arg_no_pager && !arg_follow && pager_open(); | |||
if (arg_output == OUTPUT_JSON) { | ||||
fputc('[', stdout); | ||||
fflush(stdout); | ||||
} | ||||
for (;;) { | for (;;) { | |||
for (;;) { | for (;;) { | |||
sd_id128_t boot_id; | ||||
int flags = | int flags = | |||
arg_show_all * OUTPUT_SHOW_ALL | | arg_show_all * OUTPUT_SHOW_ALL | | |||
have_pager * OUTPUT_FULL_WIDTH | | have_pager * OUTPUT_FULL_WIDTH | | |||
on_tty() * OUTPUT_COLOR; | on_tty() * OUTPUT_COLOR; | |||
if (need_seek) { | if (need_seek) { | |||
r = sd_journal_next(j); | r = sd_journal_next(j); | |||
if (r < 0) { | if (r < 0) { | |||
log_error("Failed to iterate throug h journal: %s", strerror(-r)); | log_error("Failed to iterate throug h journal: %s", strerror(-r)); | |||
goto finish; | goto finish; | |||
} | } | |||
} | } | |||
if (r == 0) | if (r == 0) | |||
break; | break; | |||
r = sd_journal_get_monotonic_usec(j, NULL, &boot_id | if (!arg_merge) { | |||
); | sd_id128_t boot_id; | |||
if (r >= 0) { | ||||
if (previous_boot_id_valid && | r = sd_journal_get_monotonic_usec(j, NULL, | |||
!sd_id128_equal(boot_id, previous_boot_ | &boot_id); | |||
id)) | if (r >= 0) { | |||
printf(ANSI_HIGHLIGHT_ON "----- Reb | if (previous_boot_id_valid && | |||
oot -----" ANSI_HIGHLIGHT_OFF "\n"); | !sd_id128_equal(boot_id, previo | |||
us_boot_id)) | ||||
printf(ANSI_HIGHLIGHT_ON "- | ||||
---- Reboot -----" ANSI_HIGHLIGHT_OFF "\n"); | ||||
previous_boot_id = boot_id; | previous_boot_id = boot_id; | |||
previous_boot_id_valid = true; | previous_boot_id_valid = true; | |||
} | ||||
} | } | |||
line ++; | line ++; | |||
r = output_journal(j, arg_output, line, 0, flags); | r = output_journal(j, arg_output, line, 0, flags); | |||
if (r < 0) | if (r < 0) | |||
goto finish; | goto finish; | |||
need_seek = true; | need_seek = true; | |||
} | } | |||
skipping to change at line 876 | skipping to change at line 902 | |||
if (!arg_follow) | if (!arg_follow) | |||
break; | break; | |||
r = sd_journal_wait(j, (uint64_t) -1); | r = sd_journal_wait(j, (uint64_t) -1); | |||
if (r < 0) { | if (r < 0) { | |||
log_error("Couldn't wait for log event: %s", strerr or(-r)); | log_error("Couldn't wait for log event: %s", strerr or(-r)); | |||
goto finish; | goto finish; | |||
} | } | |||
} | } | |||
if (arg_output == OUTPUT_JSON) | ||||
fputs("\n]\n", stdout); | ||||
finish: | finish: | |||
if (j) | if (j) | |||
sd_journal_close(j); | sd_journal_close(j); | |||
pager_close(); | pager_close(); | |||
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; | |||
} | } | |||
End of changes. 21 change blocks. | ||||
34 lines changed or deleted | 59 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |