From 541fb2704d9ff8f4a3fdf50333c2331876f9ecd5 Mon Sep 17 00:00:00 2001 From: Tom Briden Date: Fri, 3 Oct 2025 10:03:21 +0100 Subject: [PATCH] recording: only update metafile offset after successfully parsing the change when under load it's possible that a metafile gets updated by rtpengine while it's still being read by the recording daemon. this can result in a WARNING being logged and the loop breaking. That section ends up unprocessed and any changes in it don't get applied. This change only updates the offset after a successful section read. Therefore, if a section is incomplete and the loop breaks, the next inotify event will retry that incomplete section and it should succeed --- recording-daemon/metafile.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/recording-daemon/metafile.c b/recording-daemon/metafile.c index f0e8270b6..4112b77b8 100644 --- a/recording-daemon/metafile.c +++ b/recording-daemon/metafile.c @@ -395,8 +395,6 @@ void metafile_change(char *name) { g_string_append_len(s, buf, ret); } - // save read position and close file - mf->pos = lseek(fd, 0, SEEK_CUR); close(fd); // process contents of metadata file @@ -404,6 +402,7 @@ void metafile_change(char *name) { char *head = s->str; char *endp = s->str + s->len; while (head < endp) { + char *section_start = head; // section header char *nl = memchr(head, '\n', endp - head); if (!nl || nl == head) { @@ -412,6 +411,8 @@ void metafile_change(char *name) { } if (memchr(head, '\0', nl - head)) { ilog(LOG_WARN, "NUL character in section header in %s%s%s", FMT_M(name)); + // jump to the end of the read so we don't continually try and process this bad data + mf->pos += (endp - section_start); break; } *(nl++) = '\0'; @@ -447,6 +448,8 @@ void metafile_change(char *name) { char *content = head; if (memchr(content, '\0', slen)) { ilog(LOG_WARN, "NUL character in content in section %s in %s%s%s", section, FMT_M(name)); + // jump to the end of the read so we don't continually try and process this bad data + mf->pos += (endp - section_start); break; } @@ -460,6 +463,10 @@ void metafile_change(char *name) { head += 2; meta_section(mf, section, content, slen); + // update read position by the amount of data we processed + // so that any issues causing a break above will resume at the + // correct position on the next inotify event + mf->pos += (head - section_start); } g_string_free(s, TRUE);