Browse code

Improve error reporting when following journals

When we set up to start following a journal, if we get error results
from sd_journal_get_fd() or sd_journal_get_events() that prevent us from
following the journal, report the error instead of just mysteriously
failing.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com> (github: nalind)

Nalin Dahyabhai authored on 2016/03/18 07:25:14
Showing 1 changed files
... ...
@@ -63,11 +63,11 @@ package journald
63 63
 //		fds[0].events = POLLHUP;
64 64
 //		fds[1].fd = sd_journal_get_fd(j);
65 65
 //		if (fds[1].fd < 0) {
66
-//			return -1;
66
+//			return fds[1].fd;
67 67
 //		}
68 68
 //		jevents = sd_journal_get_events(j);
69 69
 //		if (jevents < 0) {
70
-//			return -1;
70
+//			return jevents;
71 71
 //		}
72 72
 //		fds[1].events = jevents;
73 73
 //		sd_journal_get_timeout(j, &when);
... ...
@@ -81,7 +81,7 @@ package journald
81 81
 //		i = poll(fds, 2, timeout);
82 82
 //		if ((i == -1) && (errno != EINTR)) {
83 83
 //			/* An unexpected error. */
84
-//			return -1;
84
+//			return (errno != 0) ? -errno : -EINTR;
85 85
 //		}
86 86
 //		if (fds[0].revents & POLLHUP) {
87 87
 //			/* The close notification pipe was closed. */
... ...
@@ -101,6 +101,7 @@ import (
101 101
 	"time"
102 102
 	"unsafe"
103 103
 
104
+	"github.com/Sirupsen/logrus"
104 105
 	"github.com/coreos/go-systemd/journal"
105 106
 	"github.com/docker/docker/daemon/logger"
106 107
 )
... ...
@@ -177,9 +178,18 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
177 177
 	s.readers.readers[logWatcher] = logWatcher
178 178
 	s.readers.mu.Unlock()
179 179
 	go func() {
180
-		// Keep copying journal data out until we're notified to stop.
181
-		for C.wait_for_data_or_close(j, pfd[0]) == 1 {
180
+		// Keep copying journal data out until we're notified to stop
181
+		// or we hit an error.
182
+		status := C.wait_for_data_or_close(j, pfd[0])
183
+		for status == 1 {
182 184
 			cursor = s.drainJournal(logWatcher, config, j, cursor)
185
+			status = C.wait_for_data_or_close(j, pfd[0])
186
+		}
187
+		if status < 0 {
188
+			cerrstr := C.strerror(C.int(-status))
189
+			errstr := C.GoString(cerrstr)
190
+			fmtstr := "error %q while attempting to follow journal for container %q"
191
+			logrus.Errorf(fmtstr, errstr, s.vars["CONTAINER_ID_FULL"])
183 192
 		}
184 193
 		// Clean up.
185 194
 		C.close(pfd[0])