chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
journal: if we encounter a corrupted file, rotate and go on
[elogind.git]
/
src
/
journal
/
journald.c
diff --git
a/src/journal/journald.c
b/src/journal/journald.c
index e9c00b443cff7decd1cf62df2b6e8fc82314337f..e9ac897de7fd37793f5fa654274ebf5ed65e063b 100644
(file)
--- a/
src/journal/journald.c
+++ b/
src/journal/journald.c
@@
-29,6
+29,7
@@
#include <sys/ioctl.h>
#include <linux/sockios.h>
#include <sys/statvfs.h>
#include <sys/ioctl.h>
#include <linux/sockios.h>
#include <sys/statvfs.h>
+#include <sys/user.h>
#include <systemd/sd-journal.h>
#include <systemd/sd-login.h>
#include <systemd/sd-journal.h>
#include <systemd/sd-login.h>
@@
-300,7
+301,7
@@
static JournalFile* find_journal(Server *s, uid_t uid) {
journal_file_close(f);
}
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)
free(p);
if (r < 0)
@@
-603,8
+604,12
@@
retry:
else {
r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
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);
server_rotate(s);
server_vacuum(s);
@@
-1309,6
+1314,7
@@
finish:
free(iovec[j].iov_base);
}
free(iovec[j].iov_base);
}
+ free(iovec);
free(identifier);
free(message);
}
free(identifier);
free(message);
}
@@
-1873,7
+1879,7
@@
static int system_journal_open(Server *s) {
if (!fn)
return -ENOMEM;
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) {
free(fn);
if (r >= 0) {
@@
-1904,7
+1910,7
@@
static int system_journal_open(Server *s) {
* if it already exists, so that we can flush
* it into the system journal */
* 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) {
free(fn);
if (r < 0) {
@@
-1920,7
+1926,7
@@
static int system_journal_open(Server *s) {
* it if necessary. */
(void) mkdir_parents(fn, 0755);
* 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) {
free(fn);
if (r < 0) {
@@
-2133,7
+2139,7
@@
static int process_event(Server *s, struct epoll_event *ev) {
uint8_t buf[CMSG_SPACE(sizeof(struct ucred)) +
CMSG_SPACE(sizeof(struct timeval)) +
CMSG_SPACE(sizeof(int)) +
uint8_t buf[CMSG_SPACE(sizeof(struct ucred)) +
CMSG_SPACE(sizeof(struct timeval)) +
CMSG_SPACE(sizeof(int)) +
- CMSG_SPACE(
LINE_MAX
)]; /* selinux label */
+ CMSG_SPACE(
PAGE_SIZE
)]; /* selinux label */
} control;
ssize_t n;
int v;
} control;
ssize_t n;
int v;
@@
-2306,10
+2312,12
@@
static int open_syslog_socket(Server *s) {
return -errno;
}
return -errno;
}
+#ifdef HAVE_SELINUX
one = 1;
r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSSEC, &one, sizeof(one));
if (r < 0)
log_warning("SO_PASSSEC failed: %m");
one = 1;
r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSSEC, &one, sizeof(one));
if (r < 0)
log_warning("SO_PASSSEC failed: %m");
+#endif
one = 1;
r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_TIMESTAMP, &one, sizeof(one));
one = 1;
r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_TIMESTAMP, &one, sizeof(one));
@@
-2367,10
+2375,12
@@
static int open_native_socket(Server*s) {
return -errno;
}
return -errno;
}
+#ifdef HAVE_SELINUX
one = 1;
r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSSEC, &one, sizeof(one));
if (r < 0)
log_warning("SO_PASSSEC failed: %m");
one = 1;
r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSSEC, &one, sizeof(one));
if (r < 0)
log_warning("SO_PASSSEC failed: %m");
+#endif
one = 1;
r = setsockopt(s->native_fd, SOL_SOCKET, SO_TIMESTAMP, &one, sizeof(one));
one = 1;
r = setsockopt(s->native_fd, SOL_SOCKET, SO_TIMESTAMP, &one, sizeof(one));
@@
-2660,10
+2670,6
@@
static int server_init(Server *s) {
if (r < 0)
return r;
if (r < 0)
return r;
- r = system_journal_open(s);
- if (r < 0)
- return r;
-
r = open_signalfd(s);
if (r < 0)
return r;
r = open_signalfd(s);
if (r < 0)
return r;
@@
-2672,6
+2678,10
@@
static int server_init(Server *s) {
if (!s->rate_limit)
return -ENOMEM;
if (!s->rate_limit)
return -ENOMEM;
+ r = system_journal_open(s);
+ if (r < 0)
+ return r;
+
return 0;
}
return 0;
}