[systemd-devel] [PATCH 2/3] journal: Try to pass log via /dev/shm to avoid waking up journal

Karol Lewandowski k.lewandowsk at samsung.com
Thu Dec 12 05:12:55 PST 2013


Enabled by default for test purposes.
---
 src/journal/journal-send.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
index 281e154..9c4acc2 100644
--- a/src/journal/journal-send.c
+++ b/src/journal/journal-send.c
@@ -196,6 +196,41 @@ finish:
         return r;
 }
 
+static int write_snippet(const struct iovec *iov, int n) {
+
+        static const char dir[] = "/dev/shm";
+        char path[PATH_MAX]; /* FIXME */
+        struct timespec ts;
+        struct stat st;
+        int fd;
+        int r;
+
+        if (stat(dir, &st) < 0 || !S_ISDIR(st.st_mode))
+                return -1;
+
+        do {
+                clock_gettime(CLOCK_REALTIME, &ts);
+                snprintf(path, PATH_MAX, "%s/journal-snippet.%lu.%lu", dir, ts.tv_sec, ts.tv_nsec); /* FIXME */
+
+                fd = open(path, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+
+        } while (fd < 0 && errno == EEXIST);
+
+        if (fd < 0)
+                return -errno;
+
+        r = writev(fd, iov, n);
+        if (r < 0)
+                r = -errno;
+        else
+                r = 1;
+
+        close_nointr_nofail(fd);
+
+        return r;
+}
+
+
 _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
         PROTECT_ERRNO;
         int fd, buffer_fd;
@@ -289,6 +324,10 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
                 IOVEC_SET_STRING(w[j++], "\n");
         }
 
+        /* Try to drop journald snippet for delayed processing */
+        if (write_snippet(w, j) > 0)
+                return 0;
+
         fd = journal_fd();
         if (_unlikely_(fd < 0))
                 return fd;
-- 
1.8.4.rc3



More information about the systemd-devel mailing list