size_t string_offset = 0;
size_t remaining = length;
while (offset + remaining > BUFSIZE) {
- strncpy(buf+offset, string+string_offset, BUFSIZE-offset);
- string_offset += BUFSIZE-offset;
+ 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);
+ strncpy(buf + offset, string + string_offset, remaining);
offset += remaining;
}
size_t l;
int r = sd_journal_get_data(j, "_PID", (const void **)&d, &l);
if (r < 0) {
- // we sometimes have no pid
+ // we sometimes have no pid, e.g., kernel messages
return;
}
fprintf(stderr, "ERROR: %s\n", error);
}
fprintf(stderr, "usage: %s [OPTIONS]\n", progname);
- fprintf(stderr, " -b begin\tbegin at this UNIX epoch based timestamp\n");
- fprintf(stderr, " -e end\tend at this UNIX epoch based timestamp\n");
- fprintf(stderr, " -d directory\tpath to journal directory\n");
- fprintf(stderr, " -n number\tprint the last number entries\n");
- fprintf(stderr, " -f from\tprint from this cursor\n");
- fprintf(stderr, " -t to\tprint to this cursor\n");
- fprintf(stderr, " -h \t\tthis help\n");
- fprintf(stderr, "\n");
- fprintf(stderr, "giving a range conflicts with -n\n");
- fprintf(stderr, "-b and -f conflict\n");
- fprintf(stderr, "-e and -t conflict\n");
+ fprintf(stderr,
+ " -b <timestamp>\tbegin at this UNIX epoch based timestamp\n"
+ " -e <timestamp>\tend at this UNIX epoch based timestamp\n"
+ " -d <directory>\tpath to a journal directory\n"
+ " -n <integer>\t\tprint the last number entries logged\n"
+ " -f <cursor>\t\tprint from this cursor\n"
+ " -t <cursor>\t\tprint to this cursor\n"
+ " -h \t\t\tthis help\n"
+ "\n"
+ "Passing no range option will dump all the available journal\n"
+ "Giving a range conflicts with -n\n"
+ "-b and -f conflict\n"
+ "-e and -t conflict\n");
exit(error ? 1 : 0);
}
// 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;
}