summaryrefslogtreecommitdiff
path: root/xC.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-07-28 04:22:59 +0200
committerPřemysl Eric Janouch <p@janouch.name>2023-07-28 04:30:45 +0200
commitb9cdabca5d0b7ea3b5b88b57502196e9f45c02e7 (patch)
tree0596e9288f7afbc10cd5d348532c492d49804bfb /xC.c
parentf60ca431568029b6910957a01661a2e6d85897da (diff)
downloadxK-b9cdabca5d0b7ea3b5b88b57502196e9f45c02e7.tar.gz
xK-b9cdabca5d0b7ea3b5b88b57502196e9f45c02e7.tar.xz
xK-b9cdabca5d0b7ea3b5b88b57502196e9f45c02e7.zip
xC: fix relay handling of missing log files
Intermediate error messages would trash the prepared static buffer.
Diffstat (limited to 'xC.c')
-rw-r--r--xC.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/xC.c b/xC.c
index a589836..5a59a8f 100644
--- a/xC.c
+++ b/xC.c
@@ -15543,14 +15543,13 @@ static void
client_process_buffer_log
(struct client *c, uint32_t seq, struct buffer *buffer)
{
- struct relay_event_data_response *e = relay_prepare_response (c->ctx, seq);
- e->data.command = RELAY_COMMAND_BUFFER_LOG;
-
+ // XXX: We log failures to the global buffer,
+ // so the client just receives nothing if there is no log file.
+ struct str log = str_make ();
char *path = buffer_get_log_path (buffer);
FILE *fp = open_log_path (c->ctx, buffer, path);
if (fp)
{
- struct str log = str_make ();
char buf[BUFSIZ];
size_t len;
while ((len = fread (buf, 1, sizeof buf, fp)))
@@ -15558,17 +15557,15 @@ client_process_buffer_log
if (ferror (fp))
log_global_error (c->ctx, "Failed to read `#l': #l",
path, strerror (errno));
-
- // On overflow, it will later fail serialization.
- e->data.buffer_log.log_len = MIN (UINT32_MAX, log.len);
- e->data.buffer_log.log = (uint8_t *) str_steal (&log);
fclose (fp);
}
-
- // XXX: We log failures to the global buffer,
- // so the client just receives nothing if there is no log file.
-
free (path);
+
+ struct relay_event_data_response *e = relay_prepare_response (c->ctx, seq);
+ e->data.command = RELAY_COMMAND_BUFFER_LOG;
+ // On overflow, it will later fail serialization (frame will be too long).
+ e->data.buffer_log.log_len = MIN (UINT32_MAX, log.len);
+ e->data.buffer_log.log = (uint8_t *) str_steal (&log);
relay_send (c);
}