journal-upload: make watchdog state non-static
Also parse watchdog config when creating the Uploader object.
This commit is contained in:
@@ -244,24 +244,18 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
|
||||
}
|
||||
|
||||
static inline void check_update_watchdog(Uploader *u) {
|
||||
usec_t watchdog_usec;
|
||||
static usec_t before;
|
||||
usec_t after;
|
||||
usec_t elapsed_time;
|
||||
|
||||
if (sd_watchdog_enabled(false, &watchdog_usec) < 0)
|
||||
if (u->watchdog_usec <= 0)
|
||||
return;
|
||||
if (u->reset_reference_timestamp) {
|
||||
before = now(CLOCK_MONOTONIC);
|
||||
u->reset_reference_timestamp = false;
|
||||
} else {
|
||||
after = now(CLOCK_MONOTONIC);
|
||||
elapsed_time = usec_sub(after, before);
|
||||
if (elapsed_time > watchdog_usec / 2) {
|
||||
log_debug("Update watchdog timer");
|
||||
sd_notify(false, "WATCHDOG=1");
|
||||
u->reset_reference_timestamp = true;
|
||||
}
|
||||
|
||||
after = now(CLOCK_MONOTONIC);
|
||||
elapsed_time = usec_sub(after, u->watchdog_timestamp);
|
||||
if (elapsed_time > u->watchdog_usec / 2) {
|
||||
log_debug("Update watchdog timer");
|
||||
sd_notify(false, "WATCHDOG=1");
|
||||
u->watchdog_timestamp = after;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -463,6 +463,8 @@ static int setup_uploader(Uploader *u, const char *url, const char *state_file)
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to set up signals: %m");
|
||||
|
||||
(void) sd_watchdog_enabled(false, &u->watchdog_usec);
|
||||
|
||||
return load_cursor_state(u);
|
||||
}
|
||||
|
||||
@@ -494,7 +496,7 @@ static int perform_upload(Uploader *u) {
|
||||
|
||||
assert(u);
|
||||
|
||||
u->reset_reference_timestamp = true;
|
||||
u->watchdog_timestamp = now(CLOCK_MONOTONIC);
|
||||
code = curl_easy_perform(u->easy);
|
||||
if (code) {
|
||||
if (u->error[0])
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "sd-event.h"
|
||||
#include "sd-journal.h"
|
||||
#include "time-util.h"
|
||||
|
||||
typedef enum {
|
||||
ENTRY_CURSOR = 0, /* Nothing actually written yet. */
|
||||
@@ -48,7 +49,8 @@ typedef struct Uploader {
|
||||
|
||||
size_t entries_sent;
|
||||
char *last_cursor, *current_cursor;
|
||||
bool reset_reference_timestamp;
|
||||
usec_t watchdog_timestamp;
|
||||
usec_t watchdog_usec;
|
||||
} Uploader;
|
||||
|
||||
#define JOURNAL_UPLOAD_POLL_TIMEOUT (10 * USEC_PER_SEC)
|
||||
|
||||
Reference in New Issue
Block a user