xC: fix relay handling of missing log files
Intermediate error messages would trash the prepared static buffer.
This commit is contained in:
parent
f60ca43156
commit
b9cdabca5d
21
xC.c
21
xC.c
|
@ -15543,14 +15543,13 @@ static void
|
||||||
client_process_buffer_log
|
client_process_buffer_log
|
||||||
(struct client *c, uint32_t seq, struct buffer *buffer)
|
(struct client *c, uint32_t seq, struct buffer *buffer)
|
||||||
{
|
{
|
||||||
struct relay_event_data_response *e = relay_prepare_response (c->ctx, seq);
|
// XXX: We log failures to the global buffer,
|
||||||
e->data.command = RELAY_COMMAND_BUFFER_LOG;
|
// so the client just receives nothing if there is no log file.
|
||||||
|
struct str log = str_make ();
|
||||||
char *path = buffer_get_log_path (buffer);
|
char *path = buffer_get_log_path (buffer);
|
||||||
FILE *fp = open_log_path (c->ctx, buffer, path);
|
FILE *fp = open_log_path (c->ctx, buffer, path);
|
||||||
if (fp)
|
if (fp)
|
||||||
{
|
{
|
||||||
struct str log = str_make ();
|
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
size_t len;
|
size_t len;
|
||||||
while ((len = fread (buf, 1, sizeof buf, fp)))
|
while ((len = fread (buf, 1, sizeof buf, fp)))
|
||||||
|
@ -15558,17 +15557,15 @@ client_process_buffer_log
|
||||||
if (ferror (fp))
|
if (ferror (fp))
|
||||||
log_global_error (c->ctx, "Failed to read `#l': #l",
|
log_global_error (c->ctx, "Failed to read `#l': #l",
|
||||||
path, strerror (errno));
|
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);
|
fclose (fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: We log failures to the global buffer,
|
|
||||||
// so the client just receives nothing if there is no log file.
|
|
||||||
|
|
||||||
free (path);
|
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);
|
relay_send (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue