Commit 77143ecc authored by g3gg0's avatar g3gg0
Browse files

mlv_rec: embed VERS blocks into MLV file so there is no uncertainity about the...

mlv_rec: embed VERS blocks into MLV file so there is no uncertainity about the modules used for a given recording

--HG--
branch : unified
parent 7319f0752ea8
......@@ -2527,6 +2527,73 @@ static uint32_t raw_get_next_filenum()
return fileNum;
}
static int write_mlv_vers_blocks(FILE *f)
{
int mod = -1;
int error = 0;
do
{
/* get next loaded module id */
mod = module_get_next_loaded(mod);
/* make sure thats a valid one */
if(mod >= 0)
{
/* fetch information from module loader */
const char *mod_name = module_get_name(mod);
const char *mod_build_date = module_get_string(mod, "Build date");
const char *mod_last_update = module_get_string(mod, "Last update");
if(mod_name != NULL)
{
/* just in case that ever happens */
if(mod_build_date == NULL)
{
mod_build_date = "(no build date)";
}
if(mod_last_update == NULL)
{
mod_last_update = "(no version)";
}
/* separating the format string allows us to measure its length for malloc */
const char *fmt_string = "%s built %s; commit %s";
int buf_length = strlen(fmt_string) + strlen(mod_name) + strlen(mod_build_date) + strlen(mod_last_update) + 1;
char *version_string = malloc(buf_length);
/* now build the string */
snprintf(version_string, buf_length, fmt_string, mod_name, mod_build_date, mod_last_update);
/* and finally remove any newlines, they are annoying */
for(unsigned int pos = 0; pos < strlen(version_string); pos++)
{
if(version_string[pos] == '\n')
{
version_string[pos] = ' ';
}
}
/* let the mlv helpers build the block for us */
mlv_vers_hdr_t *hdr = NULL;
mlv_build_vers(&hdr, mlv_start_timestamp, version_string);
/* try to write to output file */
if(FIO_WriteFile(f, hdr, hdr->blockSize) != (int)hdr->blockSize)
{
error = 1;
}
/* free both temporary string and allocated mlv block */
free(version_string);
free(hdr);
}
}
} while(mod >= 0 && !error);
return error;
}
static void raw_prepare_chunk(FILE *f, mlv_file_hdr_t *hdr)
{
if(f == NULL)
......@@ -2570,6 +2637,7 @@ static void raw_prepare_chunk(FILE *f, mlv_file_hdr_t *hdr)
mlv_write_hdr(f, (mlv_hdr_t *)&idnt_hdr);
mlv_write_hdr(f, (mlv_hdr_t *)&wbal_hdr);
mlv_write_hdr(f, (mlv_hdr_t *)&styl_hdr);
write_mlv_vers_blocks(f);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment