diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-07-28 21:15:17 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-07-29 13:58:38 +0200 |
commit | ce401448d62f65956ed57b077af2b315f59efe94 (patch) | |
tree | afcfd1cb6399811f2275a7ebfc345f8e3f3afd27 /src/irmd/main.c | |
parent | 2d529f912c089033e2f40fd0978ccb741bfe2bbb (diff) | |
download | ouroboros-ce401448d62f65956ed57b077af2b315f59efe94.tar.gz ouroboros-ce401448d62f65956ed57b077af2b315f59efe94.zip |
lib: Portability to FreeBSD
Various portability fixes for FreeBSD. POSIX requires shm file names
to start with a "/" to be portable. lseek(2) can be undefined on
POSIX shm, replaced with ftruncate(2). IRMd check on existing lockfile
more portable.
FreeBSD 11.0 is preferred as it natively supports robust mutexes.
Full working LLC implementation pending.
Diffstat (limited to 'src/irmd/main.c')
-rw-r--r-- | src/irmd/main.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c index b071ff1c..1c731788 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1679,28 +1679,6 @@ static struct irm * irm_create() irmd->state = IRMD_NULL; - if (access("/dev/shm/" LOCKFILE_NAME, F_OK) != -1) { - struct lockfile * lf = lockfile_open(); - if (lf == NULL) { - LOG_ERR("Failed to open existing lockfile."); - free(irmd); - return NULL; - } - - if (kill(lockfile_owner(lf), 0) < 0) { - LOG_INFO("IRMd didn't properly shut down last time."); - shm_du_map_destroy(shm_du_map_open()); - LOG_INFO("Stale resources cleaned"); - lockfile_destroy(lf); - } else { - LOG_INFO("IRMd already running (%d), exiting.", - lockfile_owner(lf)); - lockfile_close(lf); - free(irmd); - return NULL; - } - } - if (pthread_rwlock_init(&irmd->state_lock, NULL)) { LOG_ERR("Failed to initialize rwlock."); free(irmd); @@ -1757,6 +1735,28 @@ static struct irm * irm_create() } if ((irmd->lf = lockfile_create()) == NULL) { + if ((irmd->lf = lockfile_open()) == NULL) { + LOG_ERR("Lockfile error."); + irm_destroy(); + return NULL; + } + + if (kill(lockfile_owner(irmd->lf), 0) < 0) { + LOG_INFO("IRMd didn't properly shut down last time."); + shm_du_map_destroy(shm_du_map_open()); + LOG_INFO("Stale resources cleaned"); + lockfile_destroy(irmd->lf); + irmd->lf = lockfile_create(); + } else { + LOG_INFO("IRMd already running (%d), exiting.", + lockfile_owner(irmd->lf)); + lockfile_close(irmd->lf); + free(irmd); + return NULL; + } + } + + if (irmd->lf == NULL) { irm_destroy(); return NULL; } @@ -1768,6 +1768,8 @@ static struct irm * irm_create() irmd->state = IRMD_RUNNING; + LOG_INFO("IRMd started..."); + return irmd; } |