From f516b51169020ea1957010fbd1005d746f01b1d9 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 19 Oct 2016 22:25:46 +0200 Subject: lib: Demultiplex the fast path The fast path will now use an incoming ring buffer per flow per process. This necessitated the development of a new method for the asynchronous io call, which is now based on an event queue system for scalability (fqueue). The ipcpd's and tools have been updated to this API. --- src/lib/lockfile.c | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'src/lib/lockfile.c') diff --git a/src/lib/lockfile.c b/src/lib/lockfile.c index 04ce9324..a0222f18 100644 --- a/src/lib/lockfile.c +++ b/src/lib/lockfile.c @@ -39,10 +39,10 @@ struct lockfile { pid_t * api; - int fd; }; struct lockfile * lockfile_create() { + int fd; mode_t mask; struct lockfile * lf = malloc(sizeof(*lf)); if (lf == NULL) @@ -50,8 +50,8 @@ struct lockfile * lockfile_create() { mask = umask(0); - lf->fd = shm_open(LOCKFILE_NAME, O_CREAT | O_EXCL | O_RDWR, 0666); - if (lf->fd == -1) { + fd = shm_open(LOCKFILE_NAME, O_CREAT | O_EXCL | O_RDWR, 0666); + if (fd == -1) { LOG_DBGF("Could not create lock file."); free(lf); return NULL; @@ -59,30 +59,24 @@ struct lockfile * lockfile_create() { umask(mask); - if (ftruncate(lf->fd, LF_SIZE - 1) < 0) { + if (ftruncate(fd, LF_SIZE - 1) < 0) { LOG_DBGF("Failed to extend lockfile."); free(lf); return NULL; } -#ifndef __APPLE__ - if (write(lf->fd, "", 1) != 1) { - LOG_DBGF("Failed to finalise lockfile."); - free(lf); - return NULL; - } -#endif + lf->api = mmap(NULL, LF_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, - lf->fd, + fd, 0); + close (fd); + if (lf->api == MAP_FAILED) { LOG_DBGF("Failed to map lockfile."); - if (shm_unlink(LOCKFILE_NAME) == -1) LOG_DBGF("Failed to remove invalid lockfile."); - free(lf); return NULL; } @@ -93,12 +87,13 @@ struct lockfile * lockfile_create() { } struct lockfile * lockfile_open() { + int fd; struct lockfile * lf = malloc(sizeof(*lf)); if (lf == NULL) return NULL; - lf->fd = shm_open(LOCKFILE_NAME, O_RDWR, 0666); - if (lf->fd < 0) { + fd = shm_open(LOCKFILE_NAME, O_RDWR, 0666); + if (fd < 0) { LOG_DBGF("Could not open lock file."); free(lf); return NULL; @@ -107,15 +102,15 @@ struct lockfile * lockfile_open() { lf->api = mmap(NULL, LF_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, - lf->fd, + fd, 0); + close(fd); + if (lf->api == MAP_FAILED) { LOG_DBGF("Failed to map lockfile."); - if (shm_unlink(LOCKFILE_NAME) == -1) LOG_DBGF("Failed to remove invalid lockfile."); - free(lf); return NULL; } @@ -130,9 +125,6 @@ void lockfile_close(struct lockfile * lf) return; } - if (close(lf->fd) < 0) - LOG_DBGF("Couldn't close lockfile."); - if (munmap(lf->api, LF_SIZE) == -1) LOG_DBGF("Couldn't unmap lockfile."); @@ -151,9 +143,6 @@ void lockfile_destroy(struct lockfile * lf) return; } - if (close(lf->fd) < 0) - LOG_DBGF("Couldn't close lockfile."); - if (munmap(lf->api, LF_SIZE) == -1) LOG_DBGF("Couldn't unmap lockfile."); -- cgit v1.2.3