mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-10-27 01:55:32 +03:00
journal: immediately sync to disk as soon as we receieve an EMERG/ALERT/CRIT message
This commit is contained in:
parent
8b18fdc195
commit
d07f7b9ef2
2
TODO
2
TODO
@ -74,8 +74,6 @@ Features:
|
||||
|
||||
* journald: optionally, log debug messages to /run but everything else to /var
|
||||
|
||||
* journald: optionally, when messages with a high log priority are logged, sync() immediately.
|
||||
|
||||
* systemctl list-unit-files should list generated files (and probably with a new state "generated" for them, or so)
|
||||
|
||||
* do we really need both hasprefix() and startswith()?
|
||||
|
@ -348,9 +348,17 @@
|
||||
<varlistentry>
|
||||
<term><varname>SyncIntervalSec=</varname></term>
|
||||
|
||||
<listitem><para>The timeout before synchronizing journal
|
||||
data to disk. After syncing, journal files have
|
||||
the OFFLINE state. Default timeout is 5 minutes.
|
||||
<listitem><para>The timeout before
|
||||
synchronizing journal files to
|
||||
disk. After syncing, journal files are
|
||||
placed in the OFFLINE state. Note that
|
||||
syncing is unconditionally done
|
||||
immediately after a log message of
|
||||
priority CRIT, ALERT or EMERG has been
|
||||
logged, this setting hence applies
|
||||
only to messages of the levels ERR,
|
||||
WARNING, NOTICE, INFO, DEBUG. The
|
||||
default timeout is 5 minutes.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
@ -352,13 +352,12 @@ void server_rotate(Server *s) {
|
||||
}
|
||||
|
||||
void server_sync(Server *s) {
|
||||
static const struct itimerspec sync_timer_disable = {};
|
||||
JournalFile *f;
|
||||
void *k;
|
||||
Iterator i;
|
||||
int r;
|
||||
|
||||
static const struct itimerspec sync_timer_disable = {};
|
||||
|
||||
if (s->system_journal) {
|
||||
r = journal_file_set_offline(s->system_journal);
|
||||
if (r < 0)
|
||||
@ -443,7 +442,7 @@ bool shall_try_append_again(JournalFile *f, int r) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned n) {
|
||||
static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned n, int priority) {
|
||||
JournalFile *f;
|
||||
bool vacuumed = false;
|
||||
int r;
|
||||
@ -469,7 +468,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned
|
||||
|
||||
r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
|
||||
if (r >= 0) {
|
||||
server_schedule_sync(s);
|
||||
server_schedule_sync(s, priority);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -499,7 +498,8 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned
|
||||
size += iovec[i].iov_len;
|
||||
|
||||
log_error("Failed to write entry (%d items, %zu bytes) despite vacuuming, ignoring: %s", n, size, strerror(-r));
|
||||
}
|
||||
} else
|
||||
server_schedule_sync(s, priority);
|
||||
}
|
||||
|
||||
static void dispatch_message_real(
|
||||
@ -509,6 +509,7 @@ static void dispatch_message_real(
|
||||
struct timeval *tv,
|
||||
const char *label, size_t label_len,
|
||||
const char *unit_id,
|
||||
int priority,
|
||||
pid_t object_pid) {
|
||||
|
||||
char pid[sizeof("_PID=") + DECIMAL_STR_MAX(pid_t)],
|
||||
@ -523,7 +524,6 @@ static void dispatch_message_real(
|
||||
o_owner_uid[sizeof("OBJECT_SYSTEMD_OWNER_UID=") + DECIMAL_STR_MAX(uid_t)];
|
||||
uid_t object_uid;
|
||||
gid_t object_gid;
|
||||
|
||||
char *x;
|
||||
sd_id128_t id;
|
||||
int r;
|
||||
@ -786,7 +786,7 @@ static void dispatch_message_real(
|
||||
else
|
||||
journal_uid = 0;
|
||||
|
||||
write_to_journal(s, journal_uid, iovec, n);
|
||||
write_to_journal(s, journal_uid, iovec, n, priority);
|
||||
}
|
||||
|
||||
void server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...) {
|
||||
@ -820,7 +820,7 @@ void server_driver_message(Server *s, sd_id128_t message_id, const char *format,
|
||||
ucred.uid = getuid();
|
||||
ucred.gid = getgid();
|
||||
|
||||
dispatch_message_real(s, iovec, n, ELEMENTSOF(iovec), &ucred, NULL, NULL, 0, NULL, 0);
|
||||
dispatch_message_real(s, iovec, n, ELEMENTSOF(iovec), &ucred, NULL, NULL, 0, NULL, LOG_INFO, 0);
|
||||
}
|
||||
|
||||
void server_dispatch_message(
|
||||
@ -886,7 +886,7 @@ void server_dispatch_message(
|
||||
"Suppressed %u messages from %s", rl - 1, path);
|
||||
|
||||
finish:
|
||||
dispatch_message_real(s, iovec, n, m, ucred, tv, label, label_len, unit_id, object_pid);
|
||||
dispatch_message_real(s, iovec, n, m, ucred, tv, label, label_len, unit_id, priority, object_pid);
|
||||
}
|
||||
|
||||
|
||||
@ -1423,11 +1423,17 @@ static int server_open_sync_timer(Server *s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int server_schedule_sync(Server *s) {
|
||||
int server_schedule_sync(Server *s, int priority) {
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
|
||||
if (priority <= LOG_CRIT) {
|
||||
/* Immediately sync to disk when this is of priority CRIT, ALERT, EMERG */
|
||||
server_sync(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (s->sync_scheduled)
|
||||
return 0;
|
||||
|
||||
|
@ -153,7 +153,7 @@ void server_done(Server *s);
|
||||
void server_sync(Server *s);
|
||||
void server_vacuum(Server *s);
|
||||
void server_rotate(Server *s);
|
||||
int server_schedule_sync(Server *s);
|
||||
int server_schedule_sync(Server *s, int priority);
|
||||
int server_flush_to_var(Server *s);
|
||||
int process_event(Server *s, struct epoll_event *ev);
|
||||
void server_maybe_append_tags(Server *s);
|
||||
|
Loading…
Reference in New Issue
Block a user