chiark / gitweb /
journald: fix calculation of disk space
[elogind.git] / src / journal / journald.c
index 50f66be9d9c59a79592150b5c8360a8a91019e9a..ee270e79af8a24b25912d6fafee7d8b48c9595c5 100644 (file)
@@ -171,7 +171,10 @@ static uint64_t available_space(Server *s) {
                 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;
@@ -301,15 +304,13 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
                 journal_file_close(f);
         }
 
-        r = journal_file_open(p, O_RDWR|O_CREAT, 0640, s->system_journal, &f);
+        r = journal_file_open_reliably(p, O_RDWR|O_CREAT, 0640, s->system_journal, &f);
         free(p);
 
         if (r < 0)
                 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) {
@@ -604,8 +605,12 @@ retry:
         else {
                 r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
 
-                if (r == -E2BIG && !vacuumed) {
-                        log_info("Allocation limit reached.");
+                if ((r == -EBADMSG || r == -E2BIG) && !vacuumed) {
+
+                        if (r == -E2BIG)
+                                log_info("Allocation limit reached, rotating.");
+                        else
+                                log_warning("Journal file corrupted, rotating.");
 
                         server_rotate(s);
                         server_vacuum(s);
@@ -1875,7 +1880,7 @@ static int system_journal_open(Server *s) {
                 if (!fn)
                         return -ENOMEM;
 
-                r = journal_file_open(fn, O_RDWR|O_CREAT, 0640, NULL, &s->system_journal);
+                r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, NULL, &s->system_journal);
                 free(fn);
 
                 if (r >= 0) {
@@ -1906,7 +1911,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(fn, O_RDWR, 0640, NULL, &s->runtime_journal);
+                        r = journal_file_open_reliably(fn, O_RDWR, 0640, NULL, &s->runtime_journal);
                         free(fn);
 
                         if (r < 0) {
@@ -1922,7 +1927,7 @@ static int system_journal_open(Server *s) {
                          * it if necessary. */
 
                         (void) mkdir_parents(fn, 0755);
-                        r = journal_file_open(fn, O_RDWR|O_CREAT, 0640, NULL, &s->runtime_journal);
+                        r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, NULL, &s->runtime_journal);
                         free(fn);
 
                         if (r < 0) {
@@ -2308,7 +2313,7 @@ static int open_syslog_socket(Server *s) {
                 return -errno;
         }
 
-#ifdef HAVE_SE
+#ifdef HAVE_SELINUX
         one = 1;
         r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSSEC, &one, sizeof(one));
         if (r < 0)
@@ -2666,10 +2671,6 @@ static int server_init(Server *s) {
         if (r < 0)
                 return r;
 
-        r = system_journal_open(s);
-        if (r < 0)
-                return r;
-
         r = open_signalfd(s);
         if (r < 0)
                 return r;
@@ -2678,6 +2679,10 @@ static int server_init(Server *s) {
         if (!s->rate_limit)
                 return -ENOMEM;
 
+        r = system_journal_open(s);
+        if (r < 0)
+                return r;
+
         return 0;
 }