chiark / gitweb /
systemctl: shortcut log output for non-service, non-socket, non-mount, non-swap units
[elogind.git] / src / journal / journald.c
index 5c8e713657409e9a57e920c94809c891fdcc0051..b029ab97814d1845ff5cf18c454e8b453dc55243 100644 (file)
@@ -306,14 +306,11 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
         return f;
 }
 
-static void server_vacuum(Server *s) {
-        Iterator i;
+static void server_rotate(Server *s) {
+        JournalFile *f;
         void *k;
-        char *p;
-        char ids[33];
-        sd_id128_t machine;
+        Iterator i;
         int r;
-        JournalFile *f;
 
         log_info("Rotating...");
 
@@ -336,6 +333,13 @@ static void server_vacuum(Server *s) {
                 else
                         hashmap_replace(s->user_journals, k, f);
         }
+}
+
+static void server_vacuum(Server *s) {
+        char *p;
+        char ids[33];
+        sd_id128_t machine;
+        int r;
 
         log_info("Vacuuming...");
 
@@ -391,7 +395,9 @@ static char *shortened_cgroup_path(pid_t pid) {
                 return NULL;
         }
 
-        if (streq(init_path, "/"))
+        if (endswith(init_path, "/system"))
+                init_path[strlen(init_path) - 7] = 0;
+        else if (streq(init_path, "/"))
                 init_path[0] = 0;
 
         if (startswith(process_path, init_path)) {
@@ -425,7 +431,7 @@ static void dispatch_message_real(Server *s,
                 *comm = NULL, *cmdline = NULL, *hostname = NULL,
                 *audit_session = NULL, *audit_loginuid = NULL,
                 *exe = NULL, *cgroup = NULL, *session = NULL,
-                *owner_uid = NULL, *service = NULL;
+                *owner_uid = NULL, *unit = NULL;
 
         char idbuf[33];
         sd_id128_t id;
@@ -509,12 +515,12 @@ static void dispatch_message_real(Server *s,
                                 IOVEC_SET_STRING(iovec[n++], session);
                 }
 
-                if (sd_pid_get_service(ucred->pid, &t) >= 0) {
-                        service = strappend("_SYSTEMD_SERVICE=", t);
+                if (sd_pid_get_unit(ucred->pid, &t) >= 0) {
+                        unit = strappend("_SYSTEMD_UNIT=", t);
                         free(t);
 
-                        if (service)
-                                IOVEC_SET_STRING(iovec[n++], service);
+                        if (unit)
+                                IOVEC_SET_STRING(iovec[n++], unit);
                 }
 
                 if (sd_pid_get_owner_uid(ucred->uid, &owner) >= 0)
@@ -563,6 +569,7 @@ retry:
                 if (r == -E2BIG && !vacuumed) {
                         log_info("Allocation limit reached.");
 
+                        server_rotate(s);
                         server_vacuum(s);
                         vacuumed = true;
 
@@ -589,7 +596,7 @@ retry:
         free(cgroup);
         free(session);
         free(owner_uid);
-        free(service);
+        free(unit);
 }
 
 static void dispatch_message(Server *s,
@@ -1196,12 +1203,10 @@ static int system_journal_open(Server *s) {
                         fix_perms(s->system_journal, 0);
                 } else if (r < 0) {
 
-                        if (r == -ENOENT || r == -EROFS)
-                                r = 0;
-                        else {
-                                log_error("Failed to open system journal: %s", strerror(-r));
-                                return r;
-                        }
+                        if (r != -ENOENT && r != -EROFS)
+                                log_warning("Failed to open system journal: %s", strerror(-r));
+
+                        r = 0;
                 }
         }
 
@@ -1221,13 +1226,10 @@ static int system_journal_open(Server *s) {
                         free(fn);
 
                         if (r < 0) {
+                                if (r != -ENOENT)
+                                        log_warning("Failed to open runtime journal: %s", strerror(-r));
 
-                                if (r == -ENOENT)
-                                        r = 0;
-                                else {
-                                        log_error("Failed to open runtime journal: %s", strerror(-r));
-                                        return r;
-                                }
+                                r = 0;
                         }
 
                 } else {
@@ -1311,6 +1313,7 @@ static int server_flush_to_var(Server *s) {
                         log_info("Allocation limit reached.");
 
                         journal_file_post_change(s->system_journal);
+                        server_rotate(s);
                         server_vacuum(s);
 
                         r = journal_file_copy_entry(f, s->system_journal, o, f->current_offset, NULL, NULL, NULL);