summaryrefslogtreecommitdiff
path: root/src/journal/journalctl.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-01-04 04:00:14 +0100
committerLennart Poettering <lennart@poettering.net>2012-01-04 04:00:14 +0100
commit6f003b43043da7b57c0ebe15b86856c8248fea4a (patch)
treea175d63a75747b6a1bb4ae5dc5bc32e606940b1e /src/journal/journalctl.c
parentcf5eb6a110c39b36dd07457180b749f32488bcf5 (diff)
journalctl: fix counting of -n parameter
Diffstat (limited to 'src/journal/journalctl.c')
-rw-r--r--src/journal/journalctl.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index fc1fed277c..0e1fb66de6 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -148,6 +148,7 @@ int main(int argc, char *argv[]) {
int r, i, fd;
sd_journal *j = NULL;
unsigned line = 0;
+ bool need_seek = false;
log_parse_environment();
log_open();
@@ -184,16 +185,19 @@ int main(int argc, char *argv[]) {
}
r = sd_journal_previous_skip(j, arg_lines);
- if (r < 0) {
- log_error("Failed to iterate through journal: %s", strerror(-r));
- goto finish;
- }
} else {
r = sd_journal_seek_head(j);
if (r < 0) {
log_error("Failed to seek to head: %s", strerror(-r));
goto finish;
}
+
+ r = sd_journal_next(j);
+ }
+
+ if (r < 0) {
+ log_error("Failed to iterate through journal: %s", strerror(-r));
+ goto finish;
}
if (!arg_no_pager && !arg_follow) {
@@ -210,11 +214,12 @@ int main(int argc, char *argv[]) {
struct pollfd pollfd;
for (;;) {
- r = sd_journal_next(j);
-
- if (r < 0) {
- log_error("Failed to iterate through journal: %s", strerror(-r));
- goto finish;
+ if (need_seek) {
+ r = sd_journal_next(j);
+ if (r < 0) {
+ log_error("Failed to iterate through journal: %s", strerror(-r));
+ goto finish;
+ }
}
if (r == 0)
@@ -225,6 +230,8 @@ int main(int argc, char *argv[]) {
r = output_journal(j, arg_output, line, arg_show_all);
if (r < 0)
goto finish;
+
+ need_seek = true;
}
if (!arg_follow)