static bool arg_full = false;
static bool arg_all = false;
static bool arg_no_pager = false;
-static unsigned arg_lines = 0;
+static int arg_lines = -1;
static bool arg_no_tail = false;
static bool arg_quiet = false;
static bool arg_merge = false;
case 'n':
if (optarg) {
- r = safe_atou(optarg, &arg_lines);
- if (r < 0 || arg_lines <= 0) {
+ r = safe_atoi(optarg, &arg_lines);
+ if (r < 0 || arg_lines < 0) {
log_error("Failed to parse lines '%s'", optarg);
return -EINVAL;
}
- } else
- arg_lines = 10;
+ } else {
+ int n;
+
+ /* Hmm, no argument? Maybe the next
+ * word on the command line is
+ * supposed to be the argument? Let's
+ * see if there is one, and is
+ * parsable as a positive
+ * integer... */
+
+ if (optind < argc &&
+ safe_atoi(argv[optind], &n) >= 0 &&
+ n >= 0) {
+
+ arg_lines = n;
+ optind++;
+ } else
+ arg_lines = 10;
+ }
break;
}
}
- if (arg_follow && !arg_no_tail && arg_lines <= 0)
+ if (arg_follow && !arg_no_tail && arg_lines < 0)
arg_lines = 10;
- if (arg_since_set && arg_until_set && arg_since_set > arg_until_set) {
+ if (arg_since_set && arg_until_set && arg_since > arg_until) {
log_error("--since= must be before --until=.");
return -EINVAL;
}
"As UUID:\n"
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n\n"
"As macro:\n"
- "#define MESSAGE_XYZ SD_ID128_MAKE(",
+ "#define MESSAGE_XYZ SD_ID128_MAKE(",
SD_ID128_FORMAT_VAL(id),
SD_ID128_FORMAT_VAL(id));
-
for (i = 0; i < 16; i++)
printf("%02x%s", id.bytes[i], i != 15 ? "," : "");
+ fputs(")\n\n", stdout);
- fputs(")\n", stdout);
+ printf("As Python constant:\n"
+ ">>> import uuid\n"
+ ">>> MESSAGE_XYZ = uuid.UUID('" SD_ID128_FORMAT_STR "')\n",
+ SD_ID128_FORMAT_VAL(id));
return 0;
}
sd_journal *j = NULL;
bool need_seek = false;
sd_id128_t previous_boot_id;
- bool previous_boot_id_valid = false;
- unsigned n_shown = 0;
+ bool previous_boot_id_valid = false, first_line = true;
+ int n_shown = 0;
setlocale(LC_ALL, "");
log_parse_environment();
if (r < 0)
goto finish;
+ /* Opening the fd now means the first sd_journal_wait() will actually wait */
+ r = sd_journal_get_fd(j);
+ if (r < 0)
+ goto finish;
+
if (arg_field) {
const void *data;
size_t size;
SD_JOURNAL_FOREACH_UNIQUE(j, data, size) {
const void *eq;
- if (arg_lines > 0 && n_shown >= arg_lines)
+ if (arg_lines >= 0 && n_shown >= arg_lines)
break;
eq = memchr(data, '=', size);
}
r = sd_journal_next(j);
- } else if (arg_lines > 0) {
+ } else if (arg_lines >= 0) {
r = sd_journal_seek_tail(j);
if (r < 0) {
log_error("Failed to seek to tail: %s", strerror(-r));
}
for (;;) {
- while (arg_lines == 0 || arg_follow || n_shown < arg_lines) {
+ while (arg_lines < 0 || n_shown < arg_lines || (arg_follow && !first_line)) {
int flags;
if (need_seek) {
log_error("Failed to determine timestamp: %s", strerror(-r));
goto finish;
}
+ if (usec > arg_until)
+ goto finish;
}
if (!arg_merge) {
arg_catalog * OUTPUT_CATALOG;
r = output_journal(stdout, j, arg_output, 0, flags);
- if (r < 0)
+ if (r < 0 || ferror(stdout))
goto finish;
need_seek = true;
log_error("Couldn't wait for journal event: %s", strerror(-r));
goto finish;
}
+
+ first_line = false;
}
finish: