diff options
author | dimitri staessens <[email protected]> | 2016-10-20 19:52:02 +0200 |
---|---|---|
committer | dimitri staessens <[email protected]> | 2016-10-21 14:17:51 +0200 |
commit | 02976060919566d1a217b818ca8f33297700d56d (patch) | |
tree | b8b6d7a4ff6f3b763891b6285248d6495e267a6a /src/lib/shm_rbuff.c | |
parent | f516b51169020ea1957010fbd1005d746f01b1d9 (diff) | |
download | ouroboros-02976060919566d1a217b818ca8f33297700d56d.tar.gz ouroboros-02976060919566d1a217b818ca8f33297700d56d.zip |
lib: Move rbuff creation/destruction to IRMd
This stabilises flow allocation now that the rbuffs are created upon
flow allocation. Only the IRMd can sync this process sufficiently.
Diffstat (limited to 'src/lib/shm_rbuff.c')
-rw-r--r-- | src/lib/shm_rbuff.c | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/src/lib/shm_rbuff.c b/src/lib/shm_rbuff.c index cf094488..a933fbff 100644 --- a/src/lib/shm_rbuff.c +++ b/src/lib/shm_rbuff.c @@ -68,7 +68,7 @@ struct shm_rbuff { int port_id; /* port_id of the flow */ }; -struct shm_rbuff * shm_rbuff_create(int port_id) +struct shm_rbuff * shm_rbuff_create(pid_t api, int port_id) { struct shm_rbuff * rb; int shm_fd; @@ -78,7 +78,7 @@ struct shm_rbuff * shm_rbuff_create(int port_id) char fn[FN_MAX_CHARS]; mode_t mask; - sprintf(fn, SHM_RBUFF_PREFIX "%d.%d", getpid(), port_id); + sprintf(fn, SHM_RBUFF_PREFIX "%d.%d", api, port_id); rb = malloc(sizeof(*rb)); if (rb == NULL) { @@ -148,9 +148,12 @@ struct shm_rbuff * shm_rbuff_create(int port_id) *rb->head = 0; *rb->tail = 0; - rb->api = getpid(); + rb->api = api; rb->port_id = port_id; + if (munmap(rb->shm_base, SHM_RBUFF_FILE_SIZE) == -1) + LOG_DBG("Couldn't unmap shared memory."); + return rb; } @@ -221,36 +224,14 @@ void shm_rbuff_close(struct shm_rbuff * rb) void shm_rbuff_destroy(struct shm_rbuff * rb) { char fn[25]; - struct lockfile * lf = NULL; - - assert(rb); - if (rb->api != getpid()) { - lf = lockfile_open(); - if (lf == NULL) { - LOG_ERR("Failed to open lockfile."); - return; - } - - if (lockfile_owner(lf) == getpid()) { - LOG_DBG("Ringbuffer %d destroyed by IRMd %d.", - rb->api, getpid()); - lockfile_close(lf); - } else { - LOG_ERR("AP-I %d tried to destroy rbuff owned by %d.", - getpid(), rb->api); - lockfile_close(lf); - return; - } - } + if (rb == NULL) + return; sprintf(fn, SHM_RBUFF_PREFIX "%d.%d", rb->api, rb->port_id); - if (munmap(rb->shm_base, SHM_RBUFF_FILE_SIZE) == -1) - LOG_DBG("Couldn't unmap shared memory."); - if (shm_unlink(fn) == -1) - LOG_DBG("Failed to unlink shm."); + LOG_DBG("Failed to unlink shm %s.", fn); free(rb); } |