Browse Source

MT#55283 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

Closes #2008

Change-Id: Ie48b66e7578597f5b75f957e3b5cc793628282dd
rfuchs/2010
Tom Briden 2 months ago
committed by Richard Fuchs
parent
commit
0bb5f4e972
1 changed files with 9 additions and 2 deletions
  1. +9
    -2
      recording-daemon/metafile.c

+ 9
- 2
recording-daemon/metafile.c View File

@ -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);


Loading…
Cancel
Save