Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/libach_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,11 @@ libach_open_posix( ach_channel_t *chan, const char *channel_name,
return ACH_BAD_SHM_FILE;

/* calculate mmaping size */
len = sizeof(ach_header_t) + sizeof(ach_index_t)*shm->index_cnt + shm->data_size;
len = sizeof(ach_header_t) + sizeof(ach_index_t)*shm->index_cnt +
shm->data_size + 3 * sizeof(uint64_t);
if( len != shm->len )
return ACH_BAD_SHM_FILE;


/* remap */
if( -1 == munmap( shm, sizeof(ach_header_t) ) )
Expand Down
41 changes: 41 additions & 0 deletions src/test/achtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,44 @@ int test_basic() {
return 0;
}

/*
* Test opening channel immediately after creating it which may fail if
* size of trailing guard isn't properly accounted for while opening channel.
*/
int test_guard() {
/* unlink */
ach_status_t r = ach_unlink(opt_channel_name);
if( ! ach_status_match(r, ACH_MASK_OK | ACH_MASK_ENOENT) ) {
fprintf(stderr, "ach_unlink failed: %s\n",
ach_result_to_string(r));
return -1;
}

size_t frame_size;

for (frame_size = 1; frame_size < 4096; ++ frame_size) {
/* create */
r = ach_create(opt_channel_name, 1ul, frame_size, NULL );
test(r, "ach_create");

ach_channel_t chan;

/* open */
r = ach_open(&chan, opt_channel_name, NULL);
test(r, "ach_open");

/* close */
r = ach_close(&chan);
test(r, "ach_close");

/* unlink */
r = ach_unlink(opt_channel_name);
test(r, "ach_unlink");
}

fprintf(stderr, "guard ok\n");
return 0;
}

static int publisher( int32_t i ) {
ach_channel_t chan;
Expand Down Expand Up @@ -417,6 +455,9 @@ int main( int argc, char **argv ){
r = test_basic();
if( 0 != r ) return r;

r = test_guard();
if( 0 != r ) return r;

r = test_multi();
if( 0 != r ) return r;

Expand Down