Skip to content

Commit 279082e

Browse files
jayanthAPpoettering
authored andcommitted
Add a network timeout option to journal-upload
1 parent 5a750c4 commit 279082e

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

man/journal-upload.conf.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@
7474
<listitem><para>SSL CA certificate.</para></listitem>
7575
</varlistentry>
7676

77+
<varlistentry>
78+
<term><varname>NetworkTimeoutSec=</varname></term>
79+
80+
<listitem><para>When network connectivity to the server is lost, this option
81+
configures the time to wait for the connectivity to get restored. If the server is
82+
not reachable over the network for the configured time, <command>systemd-journal-upload</command>
83+
exits. Takes a value in seconds (or in other time units if suffixed with "ms", "min", "h", etc).
84+
For details, see <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
85+
</para></listitem>
86+
</varlistentry>
87+
7788
</variablelist>
7889

7990
</refsect1>

src/journal-remote/journal-upload.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static const char *arg_machine = NULL;
5353
static bool arg_merge = false;
5454
static int arg_follow = -1;
5555
static const char *arg_save_state = NULL;
56+
static usec_t arg_network_timeout_usec = USEC_INFINITY;
5657

5758
static void close_fd_input(Uploader *u);
5859

@@ -211,6 +212,12 @@ int start_upload(Uploader *u,
211212
return log_error_errno(SYNTHETIC_ERRNO(ENOSR),
212213
"Call to curl_easy_init failed.");
213214

215+
/* If configured, set a timeout for the curl operation. */
216+
if (arg_network_timeout_usec != USEC_INFINITY)
217+
easy_setopt(curl, CURLOPT_TIMEOUT,
218+
(long) DIV_ROUND_UP(arg_network_timeout_usec, USEC_PER_SEC),
219+
LOG_ERR, return -EXFULL);
220+
214221
/* tell it to POST to the URL */
215222
easy_setopt(curl, CURLOPT_POST, 1L,
216223
LOG_ERR, return -EXFULL);
@@ -561,10 +568,11 @@ static int config_parse_path_or_ignore(
561568

562569
static int parse_config(void) {
563570
const ConfigTableItem items[] = {
564-
{ "Upload", "URL", config_parse_string, 0, &arg_url },
565-
{ "Upload", "ServerKeyFile", config_parse_path_or_ignore, 0, &arg_key },
566-
{ "Upload", "ServerCertificateFile", config_parse_path_or_ignore, 0, &arg_cert },
567-
{ "Upload", "TrustedCertificateFile", config_parse_path_or_ignore, 0, &arg_trust },
571+
{ "Upload", "URL", config_parse_string, 0, &arg_url },
572+
{ "Upload", "ServerKeyFile", config_parse_path_or_ignore, 0, &arg_key },
573+
{ "Upload", "ServerCertificateFile", config_parse_path_or_ignore, 0, &arg_cert },
574+
{ "Upload", "TrustedCertificateFile", config_parse_path_or_ignore, 0, &arg_trust },
575+
{ "Upload", "NetworkTimeoutSec", config_parse_sec, 0, &arg_network_timeout_usec },
568576
{}
569577
};
570578

0 commit comments

Comments
 (0)