diff --git a/lib/pkgdb.c b/lib/pkgdb.c index 7e865e7d..011bc7a6 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -61,6 +62,7 @@ static int pkgdb_fd; int xbps_pkgdb_lock(struct xbps_handle *xhp) { + mode_t prev_umask; int rv; /* * Use a mandatory file lock to only allow one writer to pkgdb, @@ -89,13 +91,18 @@ xbps_pkgdb_lock(struct xbps_handle *xhp) return rv; } } + + prev_umask = umask(022); if ((pkgdb_fd = open(xhp->pkgdb_plist, O_CREAT|O_RDWR|O_CLOEXEC, 0664)) == -1) { rv = errno; xbps_dbg_printf(xhp, "[pkgdb] cannot open pkgdb for locking " "%s: %s\n", xhp->pkgdb_plist, strerror(rv)); free(xhp->pkgdb_plist); + umask(prev_umask); return rv; } + umask(prev_umask); + if (lockf(pkgdb_fd, F_TLOCK, 0) == -1) { rv = errno; xbps_dbg_printf(xhp, "[pkgdb] cannot lock pkgdb: %s\n", strerror(rv));