chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
mmap: resize arrays dynamically
[elogind.git]
/
src
/
journal
/
journald.c
diff --git
a/src/journal/journald.c
b/src/journal/journald.c
index 7c89689e843eacfd08ba4eafd1214160489118ea..f74c46158ac63d189c2baea5506ba23c257923b6 100644
(file)
--- a/
src/journal/journald.c
+++ b/
src/journal/journald.c
@@
-47,6
+47,7
@@
#include "list.h"
#include "journal-rate-limit.h"
#include "journal-internal.h"
#include "list.h"
#include "journal-rate-limit.h"
#include "journal-internal.h"
+#include "journal-vacuum.h"
#include "conf-parser.h"
#include "journald.h"
#include "virt.h"
#include "conf-parser.h"
#include "journald.h"
#include "virt.h"
@@
-281,7
+282,6
@@
static JournalFile* find_journal(Server *s, uid_t uid) {
char *p;
int r;
JournalFile *f;
char *p;
int r;
JournalFile *f;
- char ids[33];
sd_id128_t machine;
assert(s);
sd_id128_t machine;
assert(s);
@@
-305,7
+305,8
@@
static JournalFile* find_journal(Server *s, uid_t uid) {
if (f)
return f;
if (f)
return f;
- if (asprintf(&p, "/var/log/journal/%s/user-%lu.journal", sd_id128_to_string(machine, ids), (unsigned long) uid) < 0)
+ if (asprintf(&p, "/var/log/journal/" SD_ID128_FORMAT_STR "/user-%lu.journal",
+ SD_ID128_FORMAT_VAL(machine), (unsigned long) uid) < 0)
return s->system_journal;
while (hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) {
return s->system_journal;
while (hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) {
@@
-315,7
+316,7
@@
static JournalFile* find_journal(Server *s, uid_t uid) {
journal_file_close(f);
}
journal_file_close(f);
}
- r = journal_file_open_reliably(p, O_RDWR|O_CREAT, 0640,
&s->system_metrics
, s->system_journal, &f);
+ r = journal_file_open_reliably(p, O_RDWR|O_CREAT, 0640,
s->compress, false, &s->system_metrics, s->mmap
, s->system_journal, &f);
free(p);
if (r < 0)
free(p);
if (r < 0)
@@
-341,7
+342,7
@@
static void server_rotate(Server *s) {
log_info("Rotating...");
if (s->runtime_journal) {
log_info("Rotating...");
if (s->runtime_journal) {
- r = journal_file_rotate(&s->runtime_journal);
+ r = journal_file_rotate(&s->runtime_journal
, s->compress, false
);
if (r < 0)
if (s->runtime_journal)
log_error("Failed to rotate %s: %s", s->runtime_journal->path, strerror(-r));
if (r < 0)
if (s->runtime_journal)
log_error("Failed to rotate %s: %s", s->runtime_journal->path, strerror(-r));
@@
-352,7
+353,7
@@
static void server_rotate(Server *s) {
}
if (s->system_journal) {
}
if (s->system_journal) {
- r = journal_file_rotate(&s->system_journal);
+ r = journal_file_rotate(&s->system_journal
, s->compress, true
);
if (r < 0)
if (s->system_journal)
log_error("Failed to rotate %s: %s", s->system_journal->path, strerror(-r));
if (r < 0)
if (s->system_journal)
log_error("Failed to rotate %s: %s", s->system_journal->path, strerror(-r));
@@
-364,7
+365,7
@@
static void server_rotate(Server *s) {
}
HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
}
HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
- r = journal_file_rotate(&f);
+ r = journal_file_rotate(&f
, s->compress, false
);
if (r < 0)
if (f->path)
log_error("Failed to rotate %s: %s", f->path, strerror(-r));
if (r < 0)
if (f->path)
log_error("Failed to rotate %s: %s", f->path, strerror(-r));
@@
-2006,14
+2007,12
@@
static int system_journal_open(Server *s) {
if (!fn)
return -ENOMEM;
if (!fn)
return -ENOMEM;
- r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640,
&s->system_metrics
, NULL, &s->system_journal);
+ r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640,
s->compress, true, &s->system_metrics, s->mmap
, NULL, &s->system_journal);
free(fn);
free(fn);
- if (r >= 0) {
- s->system_journal->compress = s->compress;
-
+ if (r >= 0)
server_fix_perms(s, s->system_journal, 0);
server_fix_perms(s, s->system_journal, 0);
-
}
else if (r < 0) {
+ else if (r < 0) {
if (r != -ENOENT && r != -EROFS)
log_warning("Failed to open system journal: %s", strerror(-r));
if (r != -ENOENT && r != -EROFS)
log_warning("Failed to open system journal: %s", strerror(-r));
@@
-2035,7
+2034,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,
&s->runtime_metrics
, NULL, &s->runtime_journal);
+ r = journal_file_open(fn, O_RDWR, 0640,
s->compress, false, &s->runtime_metrics, s->mmap
, NULL, &s->runtime_journal);
free(fn);
if (r < 0) {
free(fn);
if (r < 0) {
@@
-2051,7
+2050,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_reliably(fn, O_RDWR|O_CREAT, 0640,
&s->runtime_metrics
, NULL, &s->runtime_journal);
+ r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640,
s->compress, false, &s->runtime_metrics, s->mmap
, NULL, &s->runtime_journal);
free(fn);
if (r < 0) {
free(fn);
if (r < 0) {
@@
-2060,11
+2059,8
@@
static int system_journal_open(Server *s) {
}
}
}
}
- if (s->runtime_journal) {
- s->runtime_journal->compress = s->compress;
-
+ if (s->runtime_journal)
server_fix_perms(s, s->runtime_journal, 0);
server_fix_perms(s, s->runtime_journal, 0);
- }
}
return r;
}
return r;
@@
-2798,6
+2794,10
@@
static int server_init(Server *s) {
if (!s->user_journals)
return log_oom();
if (!s->user_journals)
return log_oom();
+ s->mmap = mmap_cache_new();
+ if (!s->mmap)
+ return log_oom();
+
s->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (s->epoll_fd < 0) {
log_error("Failed to create epoll object: %m");
s->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (s->epoll_fd < 0) {
log_error("Failed to create epoll object: %m");
@@
-2924,6
+2924,9
@@
static void server_done(Server *s) {
free(s->buffer);
free(s->tty_path);
free(s->buffer);
free(s->tty_path);
+
+ if (s->mmap)
+ mmap_cache_unref(s->mmap);
}
int main(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
@@
-2942,6
+2945,7
@@
int main(int argc, char *argv[]) {
log_set_target(LOG_TARGET_SAFE);
log_set_facility(LOG_SYSLOG);
log_set_target(LOG_TARGET_SAFE);
log_set_facility(LOG_SYSLOG);
+ log_set_max_level(LOG_DEBUG);
log_parse_environment();
log_open();
log_parse_environment();
log_open();