X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournald.c;h=442d2eb5ae58c890edd62a66322d8ca80b283197;hb=78b2e3a632748fbeae8a9eb70ab1940e4a70619a;hp=e9ac897de7fd37793f5fa654274ebf5ed65e063b;hpb=9447a7f1de5e5798cf324ef26579d0dd7e601203;p=elogind.git diff --git a/src/journal/journald.c b/src/journal/journald.c index e9ac897de..442d2eb5a 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -51,7 +50,7 @@ #ifdef HAVE_ACL #include #include -#include "acl-util.h" +#include "acl.h" #endif #ifdef HAVE_SELINUX @@ -154,24 +153,25 @@ static uint64_t available_space(Server *s) { for (;;) { struct stat st; struct dirent buf, *de; - int k; - k = readdir_r(d, &buf, &de); - if (k != 0) { - r = -k; - goto finish; - } + r = readdir_r(d, &buf, &de); + if (r != 0) + break; if (!de) break; - if (!dirent_is_file_with_suffix(de, ".journal")) + if (!endswith(de->d_name, ".journal") && + !endswith(de->d_name, ".journal~")) continue; if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) continue; - sum += (uint64_t) st.st_blocks * (uint64_t) st.st_blksize; + if (!S_ISREG(st.st_mode)) + continue; + + sum += (uint64_t) st.st_blocks * 512UL; } avail = sum >= m->max_use ? 0 : m->max_use - sum; @@ -308,8 +308,6 @@ static JournalFile* find_journal(Server *s, uid_t uid) { return s->system_journal; server_fix_perms(s, f, uid); - f->metrics = s->system_metrics; - f->compress = s->compress; r = hashmap_put(s->user_journals, UINT32_TO_PTR(uid), f); if (r < 0) { @@ -332,20 +330,26 @@ static void server_rotate(Server *s) { r = journal_file_rotate(&s->runtime_journal); if (r < 0) log_error("Failed to rotate %s: %s", s->runtime_journal->path, strerror(-r)); + else + server_fix_perms(s, s->runtime_journal, 0); } if (s->system_journal) { r = journal_file_rotate(&s->system_journal); if (r < 0) log_error("Failed to rotate %s: %s", s->system_journal->path, strerror(-r)); + else + server_fix_perms(s, s->system_journal, 0); } HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) { r = journal_file_rotate(&f); if (r < 0) log_error("Failed to rotate %s: %s", f->path, strerror(-r)); - else + else { hashmap_replace(s->user_journals, k, f); + server_fix_perms(s, s->system_journal, PTR_TO_UINT32(k)); + } } } @@ -604,7 +608,15 @@ retry: else { r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL); - if ((r == -EBADMSG || r == -E2BIG) && !vacuumed) { + if ((r == -E2BIG || /* hit limit */ + r == -EFBIG || /* hit fs limit */ + r == -EDQUOT || /* quota hit */ + r == -ENOSPC || /* disk full */ + r == -EBADMSG || /* corrupted */ + r == -ENODATA || /* truncated */ + r == -EHOSTDOWN || /* other machine */ + r == -EPROTONOSUPPORT) && /* unsupported feature */ + !vacuumed) { if (r == -E2BIG) log_info("Allocation limit reached, rotating."); @@ -1246,6 +1258,7 @@ static void process_native_message( p = e + 1; continue; } else { + le64_t l_le; uint64_t l; char *k; @@ -1254,8 +1267,8 @@ static void process_native_message( break; } - memcpy(&l, e + 1, sizeof(uint64_t)); - l = le64toh(l); + memcpy(&l_le, e + 1, sizeof(uint64_t)); + l = le64toh(l_le); if (remaining < e - p + 1 + sizeof(uint64_t) + l + 1 || e[1+sizeof(uint64_t)+l] != '\n') { @@ -1910,7 +1923,7 @@ static int system_journal_open(Server *s) { * if it already exists, so that we can flush * it into the system journal */ - r = journal_file_open_reliably(fn, O_RDWR, 0640, NULL, &s->runtime_journal); + r = journal_file_open(fn, O_RDWR, 0640, NULL, &s->runtime_journal); free(fn); if (r < 0) { @@ -2136,10 +2149,20 @@ static int process_event(Server *s, struct epoll_event *ev) { size_t label_len = 0; union { struct cmsghdr cmsghdr; + + /* We use NAME_MAX space for the + * SELinux label here. The kernel + * currently enforces no limit, but + * according to suggestions from the + * SELinux people this will change and + * it will probably be identical to + * NAME_MAX. For now we use that, but + * this should be updated one day when + * the final limit is known.*/ uint8_t buf[CMSG_SPACE(sizeof(struct ucred)) + CMSG_SPACE(sizeof(struct timeval)) + - CMSG_SPACE(sizeof(int)) + - CMSG_SPACE(PAGE_SIZE)]; /* selinux label */ + CMSG_SPACE(sizeof(int)) + /* fd */ + CMSG_SPACE(NAME_MAX)]; /* selinux label */ } control; ssize_t n; int v; @@ -2561,7 +2584,7 @@ static int server_parse_config_file(Server *s) { assert(s); - fn = "/etc/systemd/systemd-journald.conf"; + fn = "/etc/systemd/journald.conf"; f = fopen(fn, "re"); if (!f) { if (errno == ENOENT) @@ -2742,6 +2765,7 @@ int main(int argc, char *argv[]) { } log_set_target(LOG_TARGET_CONSOLE); + log_set_facility(LOG_SYSLOG); log_parse_environment(); log_open();