From 47b5eea0f69ba1594922259f8ebf21030c62468f Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Sun, 19 Jul 2015 11:47:09 +0200 Subject: [PATCH] set umask for pkgdb creation/access so that pkgdb remains readable for world, even if xbps tools have been called with a very restrictive umask --- lib/pkgdb.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/pkgdb.c b/lib/pkgdb.c index af75fd6e..0feb3aa0 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(0644); 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));