mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
Merge pull request #3946 from keszybz/open-journal-root
Make journalctl more flexible
This commit is contained in:
commit
622a0f628c
@ -659,10 +659,12 @@
|
||||
<term><option>--root=<replaceable>ROOT</replaceable></option></term>
|
||||
|
||||
<listitem><para>Takes a directory path as an argument. If
|
||||
specified, journalctl will operate on catalog file hierarchy
|
||||
specified, journalctl will operate on journal directories and catalog file hierarchy
|
||||
underneath the specified directory instead of the root
|
||||
directory (e.g. <option>--update-catalog</option> will create
|
||||
<filename><replaceable>ROOT</replaceable>/var/lib/systemd/catalog/database</filename>).
|
||||
<filename><replaceable>ROOT</replaceable>/var/lib/systemd/catalog/database</filename>,
|
||||
and journal files under <filename><replaceable>ROOT</replaceable>/run/journal</filename>
|
||||
or <filename><replaceable>ROOT</replaceable>/var/log/journal</filename> will be displayed).
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
@ -129,10 +129,13 @@
|
||||
|
||||
<para><function>sd_journal_open_directory()</function> is similar to <function>sd_journal_open()</function> but
|
||||
takes an absolute directory path as argument. All journal files in this directory will be opened and interleaved
|
||||
automatically. This call also takes a flags argument. The only flags parameter accepted by this call is
|
||||
<constant>SD_JOURNAL_OS_ROOT</constant>. If specified, the journal files are searched below the usual
|
||||
<filename>/var/log/journal</filename> and <filename>/run/log/journal</filename> relative to the specified path,
|
||||
instead of directly beneath it.</para>
|
||||
automatically. This call also takes a flags argument. The flags parameters accepted by this call are
|
||||
<constant>SD_JOURNAL_OS_ROOT</constant>, <constant>SD_JOURNAL_SYSTEM</constant>, and
|
||||
<constant>SD_JOURNAL_CURRENT_USER</constant>. If <constant>SD_JOURNAL_OS_ROOT</constant> is specified, journal
|
||||
files are searched for below the usual <filename>/var/log/journal</filename> and
|
||||
<filename>/run/log/journal</filename> relative to the specified path, instead of directly beneath it.
|
||||
The other two flags limit which files are opened, the same as for <function>sd_journal_open()</function>.
|
||||
</para>
|
||||
|
||||
<para><function>sd_journal_open_directory_fd()</function> is similar to
|
||||
<function>sd_journal_open_directory()</function>, but takes a file descriptor referencing a directory in the file
|
||||
|
@ -310,7 +310,7 @@ static void help(void) {
|
||||
" -m --merge Show entries from all available journals\n"
|
||||
" -D --directory=PATH Show journal files from directory\n"
|
||||
" --file=PATH Show journal file\n"
|
||||
" --root=ROOT Operate on catalog files below a root directory\n"
|
||||
" --root=ROOT Operate on files below a root directory\n"
|
||||
#ifdef HAVE_GCRYPT
|
||||
" --interval=TIME Time interval for changing the FSS sealing key\n"
|
||||
" --verify-key=KEY Specify FSS verification key\n"
|
||||
@ -848,8 +848,8 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
if (arg_follow && !arg_no_tail && !arg_since && arg_lines == ARG_LINES_DEFAULT)
|
||||
arg_lines = 10;
|
||||
|
||||
if (!!arg_directory + !!arg_file + !!arg_machine > 1) {
|
||||
log_error("Please specify either -D/--directory= or --file= or -M/--machine=, not more than one.");
|
||||
if (!!arg_directory + !!arg_file + !!arg_machine + !!arg_root > 1) {
|
||||
log_error("Please specify at most one of -D/--directory=, --file=, -M/--machine=, --root.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -1267,7 +1267,7 @@ static int add_boot(sd_journal *j) {
|
||||
* We can do this only when we logs are coming from the current machine,
|
||||
* so take the slow path if log location is specified. */
|
||||
if (arg_boot_offset == 0 && sd_id128_is_null(arg_boot_id) &&
|
||||
!arg_directory && !arg_file)
|
||||
!arg_directory && !arg_file && !arg_root)
|
||||
|
||||
return add_match_this_boot(j, arg_machine);
|
||||
|
||||
@ -2161,6 +2161,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (arg_directory)
|
||||
r = sd_journal_open_directory(&j, arg_directory, arg_journal_type);
|
||||
else if (arg_root)
|
||||
r = sd_journal_open_directory(&j, arg_root, arg_journal_type | SD_JOURNAL_OS_ROOT);
|
||||
else if (arg_file_stdin) {
|
||||
int ifd = STDIN_FILENO;
|
||||
r = sd_journal_open_files_fd(&j, &ifd, 1, 0);
|
||||
|
@ -1719,9 +1719,16 @@ static sd_journal *journal_new(int flags, const char *path) {
|
||||
j->data_threshold = DEFAULT_DATA_THRESHOLD;
|
||||
|
||||
if (path) {
|
||||
j->path = strdup(path);
|
||||
if (!j->path)
|
||||
char *t;
|
||||
|
||||
t = strdup(path);
|
||||
if (!t)
|
||||
goto fail;
|
||||
|
||||
if (flags & SD_JOURNAL_OS_ROOT)
|
||||
j->prefix = t;
|
||||
else
|
||||
j->path = t;
|
||||
}
|
||||
|
||||
j->files = ordered_hashmap_new(&string_hash_ops);
|
||||
@ -1737,12 +1744,17 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define OPEN_ALLOWED_FLAGS \
|
||||
(SD_JOURNAL_LOCAL_ONLY | \
|
||||
SD_JOURNAL_RUNTIME_ONLY | \
|
||||
SD_JOURNAL_SYSTEM | SD_JOURNAL_CURRENT_USER)
|
||||
|
||||
_public_ int sd_journal_open(sd_journal **ret, int flags) {
|
||||
sd_journal *j;
|
||||
int r;
|
||||
|
||||
assert_return(ret, -EINVAL);
|
||||
assert_return((flags & ~(SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_RUNTIME_ONLY|SD_JOURNAL_SYSTEM|SD_JOURNAL_CURRENT_USER)) == 0, -EINVAL);
|
||||
assert_return((flags & ~OPEN_ALLOWED_FLAGS) == 0, -EINVAL);
|
||||
|
||||
j = journal_new(flags, NULL);
|
||||
if (!j)
|
||||
@ -1761,6 +1773,9 @@ fail:
|
||||
return r;
|
||||
}
|
||||
|
||||
#define OPEN_CONTAINER_ALLOWED_FLAGS \
|
||||
(SD_JOURNAL_LOCAL_ONLY | SD_JOURNAL_SYSTEM)
|
||||
|
||||
_public_ int sd_journal_open_container(sd_journal **ret, const char *machine, int flags) {
|
||||
_cleanup_free_ char *root = NULL, *class = NULL;
|
||||
sd_journal *j;
|
||||
@ -1772,7 +1787,7 @@ _public_ int sd_journal_open_container(sd_journal **ret, const char *machine, in
|
||||
|
||||
assert_return(machine, -EINVAL);
|
||||
assert_return(ret, -EINVAL);
|
||||
assert_return((flags & ~(SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_SYSTEM)) == 0, -EINVAL);
|
||||
assert_return((flags & ~OPEN_CONTAINER_ALLOWED_FLAGS) == 0, -EINVAL);
|
||||
assert_return(machine_name_is_valid(machine), -EINVAL);
|
||||
|
||||
p = strjoina("/run/systemd/machines/", machine);
|
||||
@ -1787,13 +1802,10 @@ _public_ int sd_journal_open_container(sd_journal **ret, const char *machine, in
|
||||
if (!streq_ptr(class, "container"))
|
||||
return -EIO;
|
||||
|
||||
j = journal_new(flags, NULL);
|
||||
j = journal_new(flags, root);
|
||||
if (!j)
|
||||
return -ENOMEM;
|
||||
|
||||
j->prefix = root;
|
||||
root = NULL;
|
||||
|
||||
r = add_search_paths(j);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
@ -1806,13 +1818,17 @@ fail:
|
||||
return r;
|
||||
}
|
||||
|
||||
#define OPEN_DIRECTORY_ALLOWED_FLAGS \
|
||||
(SD_JOURNAL_OS_ROOT | \
|
||||
SD_JOURNAL_SYSTEM | SD_JOURNAL_CURRENT_USER )
|
||||
|
||||
_public_ int sd_journal_open_directory(sd_journal **ret, const char *path, int flags) {
|
||||
sd_journal *j;
|
||||
int r;
|
||||
|
||||
assert_return(ret, -EINVAL);
|
||||
assert_return(path, -EINVAL);
|
||||
assert_return((flags & ~SD_JOURNAL_OS_ROOT) == 0, -EINVAL);
|
||||
assert_return((flags & ~OPEN_DIRECTORY_ALLOWED_FLAGS) == 0, -EINVAL);
|
||||
|
||||
j = journal_new(flags, path);
|
||||
if (!j)
|
||||
@ -1861,6 +1877,10 @@ fail:
|
||||
return r;
|
||||
}
|
||||
|
||||
#define OPEN_DIRECTORY_FD_ALLOWED_FLAGS \
|
||||
(SD_JOURNAL_OS_ROOT | \
|
||||
SD_JOURNAL_SYSTEM | SD_JOURNAL_CURRENT_USER )
|
||||
|
||||
_public_ int sd_journal_open_directory_fd(sd_journal **ret, int fd, int flags) {
|
||||
sd_journal *j;
|
||||
struct stat st;
|
||||
@ -1868,7 +1888,7 @@ _public_ int sd_journal_open_directory_fd(sd_journal **ret, int fd, int flags) {
|
||||
|
||||
assert_return(ret, -EINVAL);
|
||||
assert_return(fd >= 0, -EBADF);
|
||||
assert_return((flags & ~SD_JOURNAL_OS_ROOT) == 0, -EINVAL);
|
||||
assert_return((flags & ~OPEN_DIRECTORY_FD_ALLOWED_FLAGS) == 0, -EINVAL);
|
||||
|
||||
if (fstat(fd, &st) < 0)
|
||||
return -errno;
|
||||
|
Loading…
Reference in New Issue
Block a user