xbps_pkgdb_lock(): check if rootfs is writable.

As shown in https://github.com/void-linux/xbps/issues/110
/var might be rw, while / might be ro.

Check this via xbps_pkgdb_lock() for both things.

Close #110

Signed-off-by: Juan RP <xtraeme@gmail.com>
This commit is contained in:
Juan RP 2019-06-13 17:04:32 +02:00 committed by Duncan Overbruck
parent c3b2d7ca53
commit f6116fc2ac

View File

@ -102,10 +102,20 @@ xbps_pkgdb_lock(struct xbps_handle *xhp)
goto ret;
}
/*
* If we've acquired the file lock, then pkgdb is writable.
*/
if (lockf(pkgdb_fd, F_TLOCK, 0) == -1) {
rv = errno;
xbps_dbg_printf(xhp, "[pkgdb] cannot lock pkgdb: %s\n", strerror(rv));
}
/*
* Check if rootdir is writable.
*/
if (access(xhp->rootdir, W_OK) == -1) {
rv = errno;
xbps_dbg_printf(xhp, "[pkgdb] rootdir %s: %s\n", xhp->rootdir, strerror(rv));
}
ret:
umask(prev_umask);