chiark / gitweb /
tmpfiles: add 'a' type to set ACLs
[elogind.git] / src / journal / journald-server.c
index 3bee18b35bf30430d40fb37ff73bd2ff10b5be24..87b459b3cace465ae627131b98f787b29aaac1f9 100644 (file)
 #include "journald-native.h"
 #include "journald-audit.h"
 #include "journald-server.h"
-
-#ifdef HAVE_ACL
-#include <sys/acl.h>
-#include <acl/libacl.h>
 #include "acl-util.h"
-#endif
 
 #ifdef HAVE_SELINUX
 #include <selinux/selinux.h>
@@ -297,8 +292,13 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
         return f;
 }
 
-static int do_rotate(Server *s, JournalFile **f, const char* name,
-                     bool seal, uint32_t uid) {
+static int do_rotate(
+                Server *s,
+                JournalFile **f,
+                const char* name,
+                bool seal,
+                uint32_t uid) {
+
         int r;
         assert(s);
 
@@ -308,13 +308,12 @@ static int do_rotate(Server *s, JournalFile **f, const char* name,
         r = journal_file_rotate(f, s->compress, seal);
         if (r < 0)
                 if (*f)
-                        log_error_errno(r, "Failed to rotate %s: %m",
-                                        (*f)->path);
+                        log_error_errno(r, "Failed to rotate %s: %m", (*f)->path);
                 else
-                        log_error_errno(r, "Failed to create new %s journal: %m",
-                                        name);
+                        log_error_errno(r, "Failed to create new %s journal: %m", name);
         else
                 server_fix_perms(s, *f, uid);
+
         return r;
 }
 
@@ -366,15 +365,20 @@ void server_sync(Server *s) {
         s->sync_scheduled = false;
 }
 
-static void do_vacuum(Server *s, char *ids, JournalFile *f, const char* path,
-                      JournalMetrics *metrics) {
-        char *p;
+static void do_vacuum(
+                Server *s,
+                const char *id,
+                JournalFile *f,
+                const char* path,
+                JournalMetrics *metrics) {
+
+        const char *p;
         int r;
 
         if (!f)
                 return;
 
-        p = strappenda(path, ids);
+        p = strappenda(path, id);
         r = journal_directory_vacuum(p, metrics->max_use, s->max_retention_usec, &s->oldest_file_usec, false);
         if (r < 0 && r != -ENOENT)
                 log_error_errno(r, "Failed to vacuum %s: %m", p);
@@ -446,18 +450,20 @@ static void server_cache_hostname(Server *s) {
         s->hostname_field = x;
 }
 
-bool shall_try_append_again(JournalFile *f, int r) {
+static bool shall_try_append_again(JournalFile *f, int r) {
 
         /* -E2BIG            Hit configured limit
            -EFBIG            Hit fs limit
            -EDQUOT           Quota limit hit
            -ENOSPC           Disk full
+           -EIO              I/O error of some kind (mmap)
            -EHOSTDOWN        Other machine
            -EBUSY            Unclean shutdown
            -EPROTONOSUPPORT  Unsupported feature
            -EBADMSG          Corrupted
            -ENODATA          Truncated
-           -ESHUTDOWN        Already archived */
+           -ESHUTDOWN        Already archived
+           -EIDRM            Journal file has been deleted */
 
         if (r == -E2BIG || r == -EFBIG || r == -EDQUOT || r == -ENOSPC)
                 log_debug("%s: Allocation limit reached, rotating.", f->path);
@@ -469,6 +475,10 @@ bool shall_try_append_again(JournalFile *f, int r) {
                 log_info("%s: Unsupported feature, rotating.", f->path);
         else if (r == -EBADMSG || r == -ENODATA || r == ESHUTDOWN)
                 log_warning("%s: Journal file corrupted, rotating.", f->path);
+        else if (r == -EIO)
+                log_warning("%s: IO error, rotating.", f->path);
+        else if (r == -EIDRM)
+                log_warning("%s: Journal file has been deleted, rotating.", f->path);
         else
                 return false;
 
@@ -506,12 +516,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned
         }
 
         if (vacuumed || !shall_try_append_again(f, r)) {
-                size_t size = 0;
-                unsigned i;
-                for (i = 0; i < n; i++)
-                        size += iovec[i].iov_len;
-
-                log_error_errno(r, "Failed to write entry (%d items, %zu bytes), ignoring: %m", n, size);
+                log_error_errno(r, "Failed to write entry (%d items, %zu bytes), ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n));
                 return;
         }
 
@@ -524,14 +529,9 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned
 
         log_debug("Retrying write.");
         r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
-        if (r < 0) {
-                size_t size = 0;
-                unsigned i;
-                for (i = 0; i < n; i++)
-                        size += iovec[i].iov_len;
-
-                log_error_errno(r, "Failed to write entry (%d items, %zu bytes) despite vacuuming, ignoring: %m", n, size);
-        } else
+        if (r < 0)
+                log_error_errno(r, "Failed to write entry (%d items, %zu bytes) despite vacuuming, ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n));
+        else
                 server_schedule_sync(s, priority);
 }
 
@@ -811,7 +811,7 @@ static void dispatch_message_real(
                  * realuid is not root, in order not to accidentally
                  * leak privileged information to the user that is
                  * logged by a privileged process that is part of an
-                 * unprivileged session.*/
+                 * unprivileged session. */
                 journal_uid = owner;
         else
                 journal_uid = 0;
@@ -1103,7 +1103,7 @@ finish:
         return r;
 }
 
-int process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata) {
+int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata) {
         Server *s = userdata;
 
         assert(s);
@@ -1131,7 +1131,7 @@ int process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userda
                          * 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.*/
+                         * 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)) + /* fd */
@@ -1158,7 +1158,7 @@ int process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userda
                  * don't rely on it. */
                 (void) ioctl(fd, SIOCINQ, &v);
 
-                /* Fix it up, if it is too small. We use the same fixed value as auditd here. Awful!*/
+                /* Fix it up, if it is too small. We use the same fixed value as auditd here. Awful! */
                 m = PAGE_ALIGN(MAX3((size_t) v + 1,
                                     (size_t) LINE_MAX,
                                     ALIGN(sizeof(struct nlmsghdr)) + ALIGN((size_t) MAX_AUDIT_MESSAGE_LENGTH)) + 1);
@@ -1457,6 +1457,7 @@ static int server_open_hostname(Server *s) {
 }
 
 int server_init(Server *s) {
+        _cleanup_fdset_free_ FDSet *fds = NULL;
         int n, r, fd;
 
         assert(s);
@@ -1552,19 +1553,34 @@ int server_init(Server *s) {
 
                         s->audit_fd = fd;
 
-                } else
-                        log_error("Unknown socket passed as file descriptor %d, ignoring.", fd);
+                } else {
+
+                        if (!fds) {
+                                fds = fdset_new();
+                                if (!fds)
+                                        return log_oom();
+                        }
+
+                        r = fdset_put(fds, fd);
+                        if (r < 0)
+                                return log_oom();
+                }
         }
 
-        r = server_open_syslog_socket(s);
+        r = server_open_stdout_socket(s, fds);
         if (r < 0)
                 return r;
 
-        r = server_open_native_socket(s);
+        if (fdset_size(fds) > 0) {
+                log_warning("%u unknown file descriptors passed, closing.", fdset_size(fds));
+                fds = fdset_free(fds);
+        }
+
+        r = server_open_syslog_socket(s);
         if (r < 0)
                 return r;
 
-        r = server_open_stdout_socket(s);
+        r = server_open_native_socket(s);
         if (r < 0)
                 return r;