mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
sd-journal: add logic to open journal files of a specific OS tree
With this change a new flag SD_JOURNAL_OS_ROOT is introduced. If specified while opening the journal with the per-directory calls (specifically: sd_journal_open_directory() and sd_journal_open_directory_fd()) the passed directory is assumed to be the root directory of an OS tree, and the journal files are searched for in /var/log/journal, /run/log/journal relative to it. This is useful to allow usage of sd-journal on file descriptors returned by the OpenRootDirectory() call of machined.
This commit is contained in:
parent
ae20320785
commit
d077390cdf
@ -1809,12 +1809,15 @@ _public_ int sd_journal_open_directory(sd_journal **ret, const char *path, int f
|
|||||||
|
|
||||||
assert_return(ret, -EINVAL);
|
assert_return(ret, -EINVAL);
|
||||||
assert_return(path, -EINVAL);
|
assert_return(path, -EINVAL);
|
||||||
assert_return(flags == 0, -EINVAL);
|
assert_return((flags & ~SD_JOURNAL_OS_ROOT) == 0, -EINVAL);
|
||||||
|
|
||||||
j = journal_new(flags, path);
|
j = journal_new(flags, path);
|
||||||
if (!j)
|
if (!j)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
if (flags & SD_JOURNAL_OS_ROOT)
|
||||||
|
r = add_search_paths(j);
|
||||||
|
else
|
||||||
r = add_root_directory(j, path, false);
|
r = add_root_directory(j, path, false);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -1862,7 +1865,7 @@ _public_ int sd_journal_open_directory_fd(sd_journal **ret, int fd, int flags) {
|
|||||||
|
|
||||||
assert_return(ret, -EINVAL);
|
assert_return(ret, -EINVAL);
|
||||||
assert_return(fd >= 0, -EBADF);
|
assert_return(fd >= 0, -EBADF);
|
||||||
assert_return(flags == 0, -EINVAL);
|
assert_return((flags & ~SD_JOURNAL_OS_ROOT) == 0, -EINVAL);
|
||||||
|
|
||||||
if (fstat(fd, &st) < 0)
|
if (fstat(fd, &st) < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
@ -1876,6 +1879,9 @@ _public_ int sd_journal_open_directory_fd(sd_journal **ret, int fd, int flags) {
|
|||||||
|
|
||||||
j->toplevel_fd = fd;
|
j->toplevel_fd = fd;
|
||||||
|
|
||||||
|
if (flags & SD_JOURNAL_OS_ROOT)
|
||||||
|
r = add_search_paths(j);
|
||||||
|
else
|
||||||
r = add_root_directory(j, NULL, false);
|
r = add_root_directory(j, NULL, false);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -67,10 +67,11 @@ typedef struct sd_journal sd_journal;
|
|||||||
|
|
||||||
/* Open flags */
|
/* Open flags */
|
||||||
enum {
|
enum {
|
||||||
SD_JOURNAL_LOCAL_ONLY = 1,
|
SD_JOURNAL_LOCAL_ONLY = 1 << 0,
|
||||||
SD_JOURNAL_RUNTIME_ONLY = 2,
|
SD_JOURNAL_RUNTIME_ONLY = 1 << 1,
|
||||||
SD_JOURNAL_SYSTEM = 4,
|
SD_JOURNAL_SYSTEM = 1 << 2,
|
||||||
SD_JOURNAL_CURRENT_USER = 8,
|
SD_JOURNAL_CURRENT_USER = 1 << 3,
|
||||||
|
SD_JOURNAL_OS_ROOT = 1 << 4,
|
||||||
|
|
||||||
SD_JOURNAL_SYSTEM_ONLY = SD_JOURNAL_SYSTEM /* deprecated name */
|
SD_JOURNAL_SYSTEM_ONLY = SD_JOURNAL_SYSTEM /* deprecated name */
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user