diff --git a/bin/xbps-rindex/defs.h b/bin/xbps-rindex/defs.h index 2f0fa122..b2ce6668 100644 --- a/bin/xbps-rindex/defs.h +++ b/bin/xbps-rindex/defs.h @@ -85,8 +85,13 @@ int sign_repo(struct xbps_handle *, const char *, const char *, bool repodata_flush(struct xbps_handle *, const char *, xbps_dictionary_t, xbps_dictionary_t, xbps_dictionary_t); +struct idxlock { + sem_t *sem; + char *semname; +}; + /* From sem.c */ -sem_t *index_lock(void); -void index_unlock(sem_t *); +struct idxlock *index_lock(struct xbps_handle *); +void index_unlock(struct idxlock *); #endif /* !_XBPS_RINDEX_DEFS_H_ */ diff --git a/bin/xbps-rindex/index-add.c b/bin/xbps-rindex/index-add.c index 2208f88c..35647a79 100644 --- a/bin/xbps-rindex/index-add.c +++ b/bin/xbps-rindex/index-add.c @@ -43,7 +43,7 @@ index_add(struct xbps_handle *xhp, int argc, char **argv, bool force) xbps_array_t array, pkg_files, pkg_links, pkg_cffiles; xbps_dictionary_t idx, idxmeta, idxfiles, binpkgd, pkg_filesd, curpkgd; xbps_object_t obj, fileobj; - sem_t *sem; + struct idxlock *il; struct xbps_repo *repo; struct stat st; const char *arch; @@ -51,7 +51,7 @@ index_add(struct xbps_handle *xhp, int argc, char **argv, bool force) int rv = 0, ret = 0; bool flush = false, found = false; - if ((sem = index_lock()) == NULL) + if ((il = index_lock(xhp)) == NULL) return EINVAL; /* * Read the repository data or create index dictionaries otherwise. @@ -263,7 +263,7 @@ index_add(struct xbps_handle *xhp, int argc, char **argv, bool force) printf("index-files: %u packages registered.\n", xbps_dictionary_count(idxfiles)); out: - index_unlock(sem); + index_unlock(il); return rv; } diff --git a/bin/xbps-rindex/index-clean.c b/bin/xbps-rindex/index-clean.c index 95eea6f5..39a15122 100644 --- a/bin/xbps-rindex/index-clean.c +++ b/bin/xbps-rindex/index-clean.c @@ -122,12 +122,12 @@ index_clean(struct xbps_handle *xhp, const char *repodir) xbps_dictionary_t idx = NULL, idxmeta = NULL, idxfiles = NULL; struct xbps_repo *repo; struct cbdata cbd; - sem_t *sem; + struct idxlock *il; char *keyname, *pkgname; int rv = 0; bool flush = false; - if ((sem = index_lock()) == NULL) + if ((il = index_lock(xhp)) == NULL) return EINVAL; repo = xbps_repo_open(xhp, repodir); @@ -207,7 +207,7 @@ index_clean(struct xbps_handle *xhp, const char *repodir) xbps_dictionary_count(idxfiles)); out: - index_unlock(sem); + index_unlock(il); if (idx) xbps_object_release(idx); diff --git a/bin/xbps-rindex/sem.c b/bin/xbps-rindex/sem.c index d34c40ed..8684af12 100644 --- a/bin/xbps-rindex/sem.c +++ b/bin/xbps-rindex/sem.c @@ -32,33 +32,44 @@ #include "defs.h" -sem_t * -index_lock(void) +struct idxlock * +index_lock(struct xbps_handle *xhp) { - sem_t *sem; + struct idxlock *il; + + if ((il = malloc(sizeof(struct idxlock))) == NULL) + return NULL; + + /* + * Generate semaphore name for target architecture. + */ + il->semname = xbps_xasprintf("/xbps-rindex-%s", + xhp->target_arch ? xhp->target_arch : xhp->native_arch); /* * Create/open the POSIX named semaphore. */ - sem = sem_open(_XBPS_RINDEX_SEMNAME, O_CREAT, 0660, 1); - if (sem == SEM_FAILED) { + il->sem = sem_open(il->semname, O_CREAT, 0660, 1); + if (il->sem == SEM_FAILED) { fprintf(stderr, "%s: failed to create/open named " "semaphore: %s\n", _XBPS_RINDEX, strerror(errno)); return NULL; } - if (sem_wait(sem) == -1) { + if (sem_wait(il->sem) == -1) { fprintf(stderr, "%s: failed to lock named semaphore: %s\n", _XBPS_RINDEX, strerror(errno)); return NULL; } - return sem; + return il; } void -index_unlock(sem_t *sem) +index_unlock(struct idxlock *il) { - /* Unblock semaphore, close and destroy it (if possible) */ - sem_post(sem); - sem_close(sem); - sem_unlink(_XBPS_RINDEX_SEMNAME); + /* Unlock semaphore, close and destroy it (if possible) */ + sem_post(il->sem); + sem_close(il->sem); + sem_unlink(il->semname); + free(il->semname); + free(il); } diff --git a/bin/xbps-rindex/sign.c b/bin/xbps-rindex/sign.c index 49966141..e6178b87 100644 --- a/bin/xbps-rindex/sign.c +++ b/bin/xbps-rindex/sign.c @@ -116,7 +116,7 @@ int sign_repo(struct xbps_handle *xhp, const char *repodir, const char *privkey, const char *signedby) { - sem_t *sem; + struct idxlock *il; struct stat st; struct xbps_repo *repo; xbps_dictionary_t pkgd, meta = NULL; @@ -137,7 +137,7 @@ sign_repo(struct xbps_handle *xhp, const char *repodir, return -1; } - if ((sem = index_lock()) == NULL) + if ((il = index_lock(xhp)) == NULL) return EINVAL; /* @@ -296,7 +296,7 @@ sign_repo(struct xbps_handle *xhp, const char *repodir, xbps_dictionary_count(repo->idx) == 1 ? "" : "s"); out: - index_unlock(sem); + index_unlock(il); if (rsa) { RSA_free(rsa);