xbps-rindex: switch named semaphore only for the target architecture.
This commit is contained in:
@ -85,8 +85,13 @@ int sign_repo(struct xbps_handle *, const char *, const char *,
|
|||||||
bool repodata_flush(struct xbps_handle *, const char *,
|
bool repodata_flush(struct xbps_handle *, const char *,
|
||||||
xbps_dictionary_t, xbps_dictionary_t, xbps_dictionary_t);
|
xbps_dictionary_t, xbps_dictionary_t, xbps_dictionary_t);
|
||||||
|
|
||||||
|
struct idxlock {
|
||||||
|
sem_t *sem;
|
||||||
|
char *semname;
|
||||||
|
};
|
||||||
|
|
||||||
/* From sem.c */
|
/* From sem.c */
|
||||||
sem_t *index_lock(void);
|
struct idxlock *index_lock(struct xbps_handle *);
|
||||||
void index_unlock(sem_t *);
|
void index_unlock(struct idxlock *);
|
||||||
|
|
||||||
#endif /* !_XBPS_RINDEX_DEFS_H_ */
|
#endif /* !_XBPS_RINDEX_DEFS_H_ */
|
||||||
|
@ -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_array_t array, pkg_files, pkg_links, pkg_cffiles;
|
||||||
xbps_dictionary_t idx, idxmeta, idxfiles, binpkgd, pkg_filesd, curpkgd;
|
xbps_dictionary_t idx, idxmeta, idxfiles, binpkgd, pkg_filesd, curpkgd;
|
||||||
xbps_object_t obj, fileobj;
|
xbps_object_t obj, fileobj;
|
||||||
sem_t *sem;
|
struct idxlock *il;
|
||||||
struct xbps_repo *repo;
|
struct xbps_repo *repo;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
const char *arch;
|
const char *arch;
|
||||||
@ -51,7 +51,7 @@ index_add(struct xbps_handle *xhp, int argc, char **argv, bool force)
|
|||||||
int rv = 0, ret = 0;
|
int rv = 0, ret = 0;
|
||||||
bool flush = false, found = false;
|
bool flush = false, found = false;
|
||||||
|
|
||||||
if ((sem = index_lock()) == NULL)
|
if ((il = index_lock(xhp)) == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
/*
|
/*
|
||||||
* Read the repository data or create index dictionaries otherwise.
|
* 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));
|
printf("index-files: %u packages registered.\n", xbps_dictionary_count(idxfiles));
|
||||||
|
|
||||||
out:
|
out:
|
||||||
index_unlock(sem);
|
index_unlock(il);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
@ -122,12 +122,12 @@ index_clean(struct xbps_handle *xhp, const char *repodir)
|
|||||||
xbps_dictionary_t idx = NULL, idxmeta = NULL, idxfiles = NULL;
|
xbps_dictionary_t idx = NULL, idxmeta = NULL, idxfiles = NULL;
|
||||||
struct xbps_repo *repo;
|
struct xbps_repo *repo;
|
||||||
struct cbdata cbd;
|
struct cbdata cbd;
|
||||||
sem_t *sem;
|
struct idxlock *il;
|
||||||
char *keyname, *pkgname;
|
char *keyname, *pkgname;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
bool flush = false;
|
bool flush = false;
|
||||||
|
|
||||||
if ((sem = index_lock()) == NULL)
|
if ((il = index_lock(xhp)) == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
repo = xbps_repo_open(xhp, repodir);
|
repo = xbps_repo_open(xhp, repodir);
|
||||||
@ -207,7 +207,7 @@ index_clean(struct xbps_handle *xhp, const char *repodir)
|
|||||||
xbps_dictionary_count(idxfiles));
|
xbps_dictionary_count(idxfiles));
|
||||||
|
|
||||||
out:
|
out:
|
||||||
index_unlock(sem);
|
index_unlock(il);
|
||||||
|
|
||||||
if (idx)
|
if (idx)
|
||||||
xbps_object_release(idx);
|
xbps_object_release(idx);
|
||||||
|
@ -32,33 +32,44 @@
|
|||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
sem_t *
|
struct idxlock *
|
||||||
index_lock(void)
|
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.
|
* Create/open the POSIX named semaphore.
|
||||||
*/
|
*/
|
||||||
sem = sem_open(_XBPS_RINDEX_SEMNAME, O_CREAT, 0660, 1);
|
il->sem = sem_open(il->semname, O_CREAT, 0660, 1);
|
||||||
if (sem == SEM_FAILED) {
|
if (il->sem == SEM_FAILED) {
|
||||||
fprintf(stderr, "%s: failed to create/open named "
|
fprintf(stderr, "%s: failed to create/open named "
|
||||||
"semaphore: %s\n", _XBPS_RINDEX, strerror(errno));
|
"semaphore: %s\n", _XBPS_RINDEX, strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (sem_wait(sem) == -1) {
|
if (sem_wait(il->sem) == -1) {
|
||||||
fprintf(stderr, "%s: failed to lock named semaphore: %s\n",
|
fprintf(stderr, "%s: failed to lock named semaphore: %s\n",
|
||||||
_XBPS_RINDEX, strerror(errno));
|
_XBPS_RINDEX, strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sem;
|
return il;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
index_unlock(sem_t *sem)
|
index_unlock(struct idxlock *il)
|
||||||
{
|
{
|
||||||
/* Unblock semaphore, close and destroy it (if possible) */
|
/* Unlock semaphore, close and destroy it (if possible) */
|
||||||
sem_post(sem);
|
sem_post(il->sem);
|
||||||
sem_close(sem);
|
sem_close(il->sem);
|
||||||
sem_unlink(_XBPS_RINDEX_SEMNAME);
|
sem_unlink(il->semname);
|
||||||
|
free(il->semname);
|
||||||
|
free(il);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ int
|
|||||||
sign_repo(struct xbps_handle *xhp, const char *repodir,
|
sign_repo(struct xbps_handle *xhp, const char *repodir,
|
||||||
const char *privkey, const char *signedby)
|
const char *privkey, const char *signedby)
|
||||||
{
|
{
|
||||||
sem_t *sem;
|
struct idxlock *il;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct xbps_repo *repo;
|
struct xbps_repo *repo;
|
||||||
xbps_dictionary_t pkgd, meta = NULL;
|
xbps_dictionary_t pkgd, meta = NULL;
|
||||||
@ -137,7 +137,7 @@ sign_repo(struct xbps_handle *xhp, const char *repodir,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((sem = index_lock()) == NULL)
|
if ((il = index_lock(xhp)) == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -296,7 +296,7 @@ sign_repo(struct xbps_handle *xhp, const char *repodir,
|
|||||||
xbps_dictionary_count(repo->idx) == 1 ? "" : "s");
|
xbps_dictionary_count(repo->idx) == 1 ? "" : "s");
|
||||||
|
|
||||||
out:
|
out:
|
||||||
index_unlock(sem);
|
index_unlock(il);
|
||||||
|
|
||||||
if (rsa) {
|
if (rsa) {
|
||||||
RSA_free(rsa);
|
RSA_free(rsa);
|
||||||
|
Reference in New Issue
Block a user