-/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
- This file is part of systemd.
-
- Copyright 2014 Zbigniew Jędrzejewski-Szmek
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <curl/curl.h>
#include <stdbool.h>
+#include "sd-daemon.h"
+
#include "alloc-util.h"
#include "journal-upload.h"
#include "log.h"
+#include "string-util.h"
#include "utf8.h"
#include "util.h"
-#include "sd-daemon.h"
/**
* Write up to size bytes to buf. Return negative on error, and number of
r = snprintf(buf + pos, size - pos,
"__CURSOR=%s\n", u->current_cursor);
- if (pos + r > size)
+ assert(r >= 0);
+ if ((size_t) r > size - pos)
/* not enough space */
return pos;
}
pos += r;
- } /* fall through */
-
+ }
+ _fallthrough_;
case ENTRY_REALTIME: {
usec_t realtime;
r = snprintf(buf + pos, size - pos,
"__REALTIME_TIMESTAMP="USEC_FMT"\n", realtime);
- if (r + pos > size)
+ assert(r >= 0);
+ if ((size_t) r > size - pos)
/* not enough space */
return pos;
}
pos += r;
- } /* fall through */
-
+ }
+ _fallthrough_;
case ENTRY_MONOTONIC: {
usec_t monotonic;
sd_id128_t boot_id;
r = snprintf(buf + pos, size - pos,
"__MONOTONIC_TIMESTAMP="USEC_FMT"\n", monotonic);
- if (r + pos > size)
+ assert(r >= 0);
+ if ((size_t) r > size - pos)
/* not enough space */
return pos;
}
pos += r;
- } /* fall through */
-
+ }
+ _fallthrough_;
case ENTRY_BOOT_ID: {
sd_id128_t boot_id;
- char sid[33];
+ char sid[SD_ID128_STRING_MAX];
r = sd_journal_get_monotonic_usec(u->journal, NULL, &boot_id);
if (r < 0)
r = snprintf(buf + pos, size - pos,
"_BOOT_ID=%s\n", sd_id128_to_string(boot_id, sid));
- if (r + pos > size)
+ assert(r >= 0);
+ if ((size_t) r > size - pos)
/* not enough space */
return pos;
}
pos += r;
- } /* fall through */
-
+ }
+ _fallthrough_;
case ENTRY_NEW_FIELD: {
u->field_pos = 0;
continue;
}
- if (!utf8_is_printable_newline(u->field_data,
- u->field_length, false)) {
+ /* We already printed the boot id from the data in
+ * the header, hence let's suppress it here */
+ if (memory_startswith(u->field_data, u->field_length, "_BOOT_ID="))
+ continue;
+
+ if (!utf8_is_printable_newline(u->field_data, u->field_length, false)) {
u->entry_state = ENTRY_BINARY_FIELD_START;
continue;
}
u->entry_state++;
- } /* fall through */
-
+ }
+ _fallthrough_;
case ENTRY_TEXT_FIELD:
case ENTRY_BINARY_FIELD: {
bool done;
size_t len;
c = memchr(u->field_data, '=', u->field_length);
- if (!c || c == u->field_data) {
- log_error("Invalid field.");
- return -EINVAL;
- }
+ if (!c || c == u->field_data)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid field.");
len = c - (const char*)u->field_data;
u->field_pos = len + 1;
u->entry_state++;
- } /* fall through */
-
+ }
+ _fallthrough_;
case ENTRY_BINARY_FIELD_SIZE: {
uint64_t le64;
return pos;
default:
- assert_not_reached("WTF?");
+ assert_not_reached();
}
}
- assert_not_reached("WTF?");
+ assert_not_reached();
}
-static inline void check_update_watchdog(Uploader *u) {
+static void check_update_watchdog(Uploader *u) {
usec_t after;
usec_t elapsed_time;
return log_error_errno(r, "Failed to register input event: %m");
log_debug("Listening for journal events on fd:%d, timeout %d",
- fd, u->timeout == (uint64_t) -1 ? -1 : (int) u->timeout);
+ fd, u->timeout == UINT64_MAX ? -1 : (int) u->timeout);
} else
log_debug("Not listening for journal events.");
cursor);
}
- return process_journal_input(u, 1 + !!after_cursor);
+ return process_journal_input(u, !!after_cursor);
}