X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fsd-journal.c;h=bb116df0474a568163303010ee06c63a4b2192e8;hb=30caf8f3afd29da8507c0edbcead7935604c9f3e;hp=2ba7ca4559988a9573f8358bf23b7e2217a7b49b;hpb=1ae464e09376853c52075ec4d8a6bfc4b4036d0c;p=elogind.git diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 2ba7ca455..bb116df04 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -41,6 +41,7 @@ #include "missing.h" #include "catalog.h" #include "replace-var.h" +#include "fileio.h" #define JOURNAL_FILES_MAX 1024 @@ -1477,6 +1478,9 @@ static int add_root_directory(sd_journal *j, const char *p) { !path_startswith(p, "/run")) return -EINVAL; + if (j->prefix) + p = strappenda(j->prefix, p); + d = opendir(p); if (!d) return -errno; @@ -1612,8 +1616,8 @@ static int add_current_paths(sd_journal *j) { * treat them as fatal. */ HASHMAP_FOREACH(f, j->files, i) { - int r; _cleanup_free_ char *dir; + int r; dir = dirname_malloc(f->path); if (!dir) @@ -1684,12 +1688,7 @@ _public_ int sd_journal_open(sd_journal **ret, int flags) { int r; assert_return(ret, -EINVAL); - - if (flags & ~(SD_JOURNAL_LOCAL_ONLY| - SD_JOURNAL_RUNTIME_ONLY| - SD_JOURNAL_SYSTEM| - SD_JOURNAL_CURRENT_USER)) - return -EINVAL; + assert_return((flags & ~(SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_RUNTIME_ONLY|SD_JOURNAL_SYSTEM|SD_JOURNAL_CURRENT_USER)) == 0, -EINVAL); j = journal_new(flags, NULL); if (!j) @@ -1708,6 +1707,48 @@ fail: return r; } +_public_ int sd_journal_open_container(sd_journal **ret, const char *machine, int flags) { + _cleanup_free_ char *root = NULL, *class = NULL; + sd_journal *j; + char *p; + int r; + + assert_return(machine, -EINVAL); + assert_return(ret, -EINVAL); + assert_return((flags & ~(SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_SYSTEM)) == 0, -EINVAL); + assert_return(filename_is_safe(machine), -EINVAL); + + p = strappenda("/run/systemd/machines/", machine); + r = parse_env_file(p, NEWLINE, "ROOT", &root, "CLASS", &class, NULL); + if (r == -ENOENT) + return -EHOSTDOWN; + if (r < 0) + return r; + if (!root) + return -ENODATA; + + if (!streq_ptr(class, "container")) + return -EIO; + + j = journal_new(flags, NULL); + if (!j) + return -ENOMEM; + + j->prefix = root; + root = NULL; + + r = add_search_paths(j); + if (r < 0) + goto fail; + + *ret = j; + return 0; + +fail: + sd_journal_close(j); + return r; +} + _public_ int sd_journal_open_directory(sd_journal **ret, const char *path, int flags) { sd_journal *j; int r; @@ -1798,6 +1839,7 @@ _public_ void sd_journal_close(sd_journal *j) { } free(j->path); + free(j->prefix); free(j->unique_field); set_free(j->errors); free(j);