#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>
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);
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;
}
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);
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);
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;
}
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;
}
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);
}
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);
}
int server_init(Server *s) {
+ _cleanup_fdset_free_ FDSet *fds = NULL;
int n, r, fd;
assert(s);
s->audit_fd = fd;
} else {
- log_warning("Unknown socket passed as file descriptor %d, ignoring.", fd);
- /* Let's close the fd, better be safe than
- sorry. The fd might reference some resource
- that we really want to release if we don't
- make use of it. */
+ if (!fds) {
+ fds = fdset_new();
+ if (!fds)
+ return log_oom();
+ }
- safe_close(fd);
+ 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;