summaryrefslogtreecommitdiff
path: root/usr.bin/cvs/repository.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/cvs/repository.c')
-rw-r--r--usr.bin/cvs/repository.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/usr.bin/cvs/repository.c b/usr.bin/cvs/repository.c
index b5718ec3f2c..bc002c7f448 100644
--- a/usr.bin/cvs/repository.c
+++ b/usr.bin/cvs/repository.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: repository.c,v 1.19 2008/02/03 23:34:41 joris Exp $ */
+/* $OpenBSD: repository.c,v 1.20 2008/03/09 03:14:52 joris Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
*
@@ -41,9 +41,10 @@ cvs_repository_unlock(const char *repo)
}
void
-cvs_repository_lock(const char *repo)
+cvs_repository_lock(const char *repo, int wantlock)
{
int i;
+ uid_t myuid;
struct stat st;
char fpath[MAXPATHLEN];
struct passwd *pw;
@@ -51,10 +52,12 @@ cvs_repository_lock(const char *repo)
if (cvs_noexec == 1 || cvs_readonlyfs == 1)
return;
- cvs_log(LP_TRACE, "cvs_repository_lock(%s)", repo);
+ cvs_log(LP_TRACE, "cvs_repository_lock(%s, %d)", repo, wantlock);
(void)xsnprintf(fpath, sizeof(fpath), "%s/%s", repo, CVS_LOCK);
+ myuid = getuid();
+
for (i = 0; i < CVS_LOCK_TRIES; i++) {
if (cvs_quit)
fatal("received signal %d", sig_received);
@@ -62,6 +65,9 @@ cvs_repository_lock(const char *repo)
if (stat(fpath, &st) == -1)
break;
+ if (st.st_uid == myuid)
+ return;
+
if ((pw = getpwuid(st.st_uid)) == NULL)
fatal("cvs_repository_lock: %s", strerror(errno));
@@ -73,6 +79,9 @@ cvs_repository_lock(const char *repo)
if (i == CVS_LOCK_TRIES)
fatal("maximum wait time for lock inside '%s' reached", repo);
+ if (wantlock == 0)
+ return;
+
if ((i = open(fpath, O_WRONLY|O_CREAT|O_TRUNC, 0755)) < 0) {
if (errno == EEXIST)
fatal("cvs_repository_lock: somebody beat us");