]> git.proxmox.com Git - proxmox-mini-journalreader.git/blobdiff - src/mini-journalreader.c
correctly check write return value
[proxmox-mini-journalreader.git] / src / mini-journalreader.c
index c5a44d4b2e0ca05288b657cecd0ec535c00747de..508de0260ec263119e9cfecb62a949c063b7b471 100644 (file)
@@ -54,7 +54,10 @@ void print_to_buf(const char * string, uint32_t length) {
         strncpy(buf + offset, string + string_offset, BUFSIZE - offset);
         string_offset += BUFSIZE - offset;
         remaining = length - string_offset;
-        write (1, buf, BUFSIZE);
+        if (write (1, buf, BUFSIZE) <= 0) {
+            perror("write to stdout failed");
+            exit(1);
+        }
         offset = 0;
     }
     strncpy(buf + offset, string + string_offset, remaining);
@@ -351,10 +354,13 @@ int main(int argc, char *argv[]) {
 
     // print final cursor
     print_cursor(j);
+    sd_journal_close(j);
 
     // print remaining buffer
-    write(1, buf, offset);
-    sd_journal_close(j);
+    if (write (1, buf, offset) <= 0) {
+        perror("write to stdout failed");
+        return 1;
+    }
 
     return 0;
 }