chiark / gitweb /
journal: enforce limits on open journal files
authorLennart Poettering <lennart@poettering.net>
Sat, 17 Dec 2011 00:13:55 +0000 (01:13 +0100)
committerLennart Poettering <lennart@poettering.net>
Sat, 17 Dec 2011 00:13:55 +0000 (01:13 +0100)
src/journal/journald.c
src/journal/sd-journal.c
src/journal/sd-journal.h

index 453495a96456de0b9c106cfefaa5b2c2e821a904..6b774f499d361d945651a67c77deb5dea82acefe 100644 (file)
@@ -38,6 +38,8 @@
 #include "acl-util.h"
 #include "cgroup-util.h"
 
 #include "acl-util.h"
 #include "cgroup-util.h"
 
+#define USER_JOURNALS_MAX 1024
+
 typedef struct Server {
         int epoll_fd;
         int signal_fd;
 typedef struct Server {
         int epoll_fd;
         int signal_fd;
@@ -127,6 +129,13 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
         if (asprintf(&p, "/var/log/journal/%s/user-%lu.journal", sd_id128_to_string(machine, ids), (unsigned long) uid) < 0)
                 return s->system_journal;
 
         if (asprintf(&p, "/var/log/journal/%s/user-%lu.journal", sd_id128_to_string(machine, ids), (unsigned long) uid) < 0)
                 return s->system_journal;
 
+        while (hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) {
+                /* Too many open? Then let's close one */
+                f = hashmap_steal_first(s->user_journals);
+                assert(f);
+                journal_file_close(f);
+        }
+
         r = journal_file_open(p, O_RDWR|O_CREAT, 0640, s->system_journal, &f);
         free(p);
 
         r = journal_file_open(p, O_RDWR|O_CREAT, 0640, s->system_journal, &f);
         free(p);
 
index 85c57170d56be46d2e3c55b49ab32f303a8593e2..bcfcbfb9e1f6dd2ce1e7f8c86dd206969581e32f 100644 (file)
@@ -30,6 +30,8 @@
 #include "list.h"
 #include "lookup3.h"
 
 #include "list.h"
 #include "lookup3.h"
 
+#define JOURNAL_FILES_MAX 1024
+
 typedef struct Match Match;
 
 struct Match {
 typedef struct Match Match;
 
 struct Match {
@@ -932,6 +934,11 @@ static int add_file(sd_journal *j, const char *prefix, const char *dir, const ch
         assert(prefix);
         assert(filename);
 
         assert(prefix);
         assert(filename);
 
+        if (hashmap_size(j->files) >= JOURNAL_FILES_MAX) {
+                log_debug("Too many open journal files, ignoring.");
+                return 0;
+        }
+
         if (dir)
                 fn = join(prefix, "/", dir, "/", filename, NULL);
         else
         if (dir)
                 fn = join(prefix, "/", dir, "/", filename, NULL);
         else
@@ -952,7 +959,6 @@ static int add_file(sd_journal *j, const char *prefix, const char *dir, const ch
 
         journal_file_dump(f);
 
 
         journal_file_dump(f);
 
-
         r = hashmap_put(j->files, f->path, f);
         if (r < 0) {
                 journal_file_close(f);
         r = hashmap_put(j->files, f->path, f);
         if (r < 0) {
                 journal_file_close(f);
index e42293ffe74543a684570e900446d710a8b6b7d4..b167dcf097bdda01480686907e7e973ab64ddf8d 100644 (file)
  *   - check LE/BE conversion for 8bit, 16bit, 32bit values
  *   - implement inotify usage on client
  *   - implement audit gateway
  *   - check LE/BE conversion for 8bit, 16bit, 32bit values
  *   - implement inotify usage on client
  *   - implement audit gateway
- *   - implement native gateway
  *   - implement stdout gateway
  *   - extend hash tables table as we go
  *   - accelerate looking for "all hostnames" and suchlike.
  *   - throttling
  *   - implement stdout gateway
  *   - extend hash tables table as we go
  *   - accelerate looking for "all hostnames" and suchlike.
  *   - throttling
- *   - enforce limit on open journal files in journald and journalctl
  *   - cryptographic hash
  *   - fix space reservation logic
  *   - comm, argv can be manipulated, should it be _COMM=, _CMDLINE= or COMM=, CMDLINE=?
  *   - cryptographic hash
  *   - fix space reservation logic
  *   - comm, argv can be manipulated, should it be _COMM=, _CMDLINE= or COMM=, CMDLINE=?