static int utab_lock(struct libmnt_update *upd)
{
	char *lfile;
	int rc;
	sigset_t sigs;

	assert(upd);
	assert(upd->filename);
	assert(upd->userspace_only);

	if (asprintf(&lfile, "%s.lock", upd->filename) == -1)
		return -1;

	DBG(UPDATE, mnt_debug("%s: locking", lfile));

	sigemptyset(&upd->oldsigmask);
	sigfillset(&sigs);
	sigprocmask(SIG_BLOCK, &sigs, &upd->oldsigmask);

	upd->utab_lock = open(lfile, O_RDONLY|O_CREAT|O_CLOEXEC, S_IWUSR|
			             S_IRUSR|S_IRGRP|S_IROTH);
	free(lfile);

	if (upd->utab_lock < 0) {
		rc = -errno;
		goto err;
	}

	while (flock(upd->utab_lock, LOCK_EX) < 0) {
		int errsv;
		if (errno == EINTR)
			continue;
		errsv = errno;
		close(upd->utab_lock);
		upd->utab_lock = -1;
		rc = -errsv;
		goto err;
	}
	return 0;
err:
	sigprocmask(SIG_SETMASK, &upd->oldsigmask, NULL);
	return rc;
}
static int utab_lock(struct libmnt_update *upd)
{
	char *lfile;
	int rc;
	sigset_t sigs;

	assert(upd);
	assert(upd->filename);
	assert(upd->userspace_only);

	if (asprintf(&lfile, "%s.lock", upd->filename) == -1)
		return -1;

	DBG(UPDATE, mnt_debug("%s: locking", lfile));

	sigemptyset(&upd->oldsigmask);
	sigfillset(&sigs);
	sigprocmask(SIG_BLOCK, &sigs, &upd->oldsigmask);

	upd->utab_lock = open(lfile, O_RDONLY|O_CREAT|O_CLOEXEC, S_IWUSR|
			             S_IRUSR|S_IRGRP|S_IROTH);
	free(lfile);

	if (upd->utab_lock < 0) {
		rc = -errno;
		goto err;
	}

	while (flock(upd->utab_lock, LOCK_EX) < 0) {
		int errsv;
		if (errno == EINTR)
			continue;
		errsv = errno;
		close(upd->utab_lock);
		upd->utab_lock = -1;
		rc = -errsv;
		goto err;
	}
	return 0;
err:
	sigprocmask(SIG_SETMASK, &upd->oldsigmask, NULL);
	return rc;
}