Skip to content

Commit

Permalink
[C] Do not fail if Aeron dir exists, but the CnC file does not. (#1481)
Browse files Browse the repository at this point in the history
If you try to start a C Media Driver with an existing directory,
but without a CnC file inside, it will fail:

ERROR: driver init (2) (2) No such file or directory
[aeron_open_file_rw, aeron_fileutil.c:428] Failed to open file: /dev/shm/empty/cnc.dat
[aeron_driver_init, aeron_driver.c:860] could not recreate aeron dir: /dev/shm/empty

ERROR: driver close (22) (22) Invalid argument
[aeron_driver_close, aeron_driver.c:1117] driver is null

It's not really an error, could be due to the directory being empty,
so it seems better to continue.

This aligns behaviour with the Java Media Driver.
  • Loading branch information
wojciech-adaptive committed Jul 13, 2023
1 parent 6ff518d commit aaa8c14
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions aeron-driver/src/main/c/aeron_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,28 +204,38 @@ int aeron_driver_ensure_dir_is_recreated(aeron_driver_context_t *context)
aeron_cnc_resolve_filename(dirname, filename, sizeof(filename));
if (aeron_map_existing_file(&cnc_mmap, filename) < 0)
{
snprintf(buffer, sizeof(buffer) - 1, "INFO: failed to mmap CnC file: %s", filename);
log_func(buffer);
return -1;
if (ENOENT == errno)
{
aeron_err_clear();
}
else
{
snprintf(buffer, sizeof(buffer) - 1, "INFO: failed to mmap CnC file: %s", filename);
log_func(buffer);
return -1;
}
}
else
{
snprintf(buffer, sizeof(buffer) - 1, "INFO: Aeron CnC file %s exists", filename);
log_func(buffer);

snprintf(buffer, sizeof(buffer) - 1, "INFO: Aeron CnC file %s exists", filename);
log_func(buffer);
if (aeron_is_driver_active_with_cnc(
&cnc_mmap, (int64_t)context->driver_timeout_ms, aeron_epoch_clock(), log_func))
{
aeron_unmap(&cnc_mmap);
return -1;
}

if (aeron_is_driver_active_with_cnc(
&cnc_mmap, (int64_t)context->driver_timeout_ms, aeron_epoch_clock(), log_func))
{
aeron_unmap(&cnc_mmap);
return -1;
}
if (aeron_report_existing_errors(&cnc_mmap, dirname) < 0)
{
aeron_unmap(&cnc_mmap);
return -1;
}

if (aeron_report_existing_errors(&cnc_mmap, dirname) < 0)
{
aeron_unmap(&cnc_mmap);
return -1;
}

aeron_unmap(&cnc_mmap);
if (aeron_delete_directory(context->aeron_dir) != 0)
{
snprintf(buffer, sizeof(buffer) - 1, "INFO: failed to delete %s", context->aeron_dir);
Expand Down

0 comments on commit aaa8c14

Please sign in to comment.