Use a POSIX lock for pkgdb and only issue pkgdb writes in exact points.

- Rather than using a POSIX named semaphore use a POSIX lock (lockf(3))
for pkgdb for writers. Writers that cannot acquire the pkgdb lock will
get EAGAIN rather then being blocked.

- Due to using a file lock we cannot write the pkgdb every time a package
is being unpacked, configured or removed. Instead pkgdb is only written
at the end of a specific point in the transaction (unpack, configure, remove)
or via xbps_pkgdb_unlock().
This commit is contained in:
Juan RP
2014-03-04 14:37:10 +01:00
parent 6335573180
commit 0416b067d0
11 changed files with 85 additions and 101 deletions

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2009-2013 Juan Romero Pardines.
* Copyright (c) 2009-2014 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -64,19 +64,7 @@ pkgdb_cb(struct xbps_handle *xhp _unused,
int
check_pkg_integrity_all(struct xbps_handle *xhp)
{
int rv;
/* force an update to get total pkg count */
(void)xbps_pkgdb_update(xhp, false);
rv = xbps_pkgdb_foreach_cb_multi(xhp, pkgdb_cb, NULL);
if ((rv = xbps_pkgdb_update(xhp, true)) != 0) {
xbps_error_printf("failed to write pkgdb: %s\n",
strerror(rv));
return rv;
}
return 0;
return xbps_pkgdb_foreach_cb_multi(xhp, pkgdb_cb, NULL);
}
int
@@ -151,8 +139,5 @@ do { \
#undef RUN_PKG_CHECK
if ((rv == 0) && (pkgd == NULL))
(void)xbps_pkgdb_update(xhp, true);
return 0;
}

View File

@@ -72,7 +72,7 @@ change_pkg_mode(struct xbps_handle *xhp, const char *pkgname, const char *mode)
else
usage(true);
return xbps_pkgdb_update(xhp, true);
return 0;
}
int

View File

@@ -153,17 +153,22 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
if (all) {
rv = xbps_configure_packages(&xh, true);
} else {
for (i = optind; i < argc; i++) {
rv = xbps_configure_pkg(&xh, argv[i],
true, false, true);
if (rv != 0)
fprintf(stderr, "Failed to reconfigure "
"`%s': %s\n", argv[i], strerror(rv));
}
if ((rv = xbps_pkgdb_lock(&xh)) != 0) {
fprintf(stderr, "failed to lock pkgdb: %s\n", strerror(rv));
exit(EXIT_FAILURE);
}
if (all) {
rv = xbps_configure_packages(&xh);
} else {
for (i = optind; i < argc; i++) {
rv = xbps_configure_pkg(&xh, argv[i], true, false);
if (rv != 0) {
fprintf(stderr, "Failed to reconfigure "
"`%s': %s\n", argv[i], strerror(rv));
}
}
}
xbps_pkgdb_unlock(&xh);
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
}