version 1.19, 2008/02/03 23:34:41 |
version 1.20, 2008/03/09 03:14:52 |
|
|
} |
} |
|
|
void |
void |
cvs_repository_lock(const char *repo) |
cvs_repository_lock(const char *repo, int wantlock) |
{ |
{ |
int i; |
int i; |
|
uid_t myuid; |
struct stat st; |
struct stat st; |
char fpath[MAXPATHLEN]; |
char fpath[MAXPATHLEN]; |
struct passwd *pw; |
struct passwd *pw; |
|
|
if (cvs_noexec == 1 || cvs_readonlyfs == 1) |
if (cvs_noexec == 1 || cvs_readonlyfs == 1) |
return; |
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); |
(void)xsnprintf(fpath, sizeof(fpath), "%s/%s", repo, CVS_LOCK); |
|
|
|
myuid = getuid(); |
|
|
for (i = 0; i < CVS_LOCK_TRIES; i++) { |
for (i = 0; i < CVS_LOCK_TRIES; i++) { |
if (cvs_quit) |
if (cvs_quit) |
fatal("received signal %d", sig_received); |
fatal("received signal %d", sig_received); |
|
|
if (stat(fpath, &st) == -1) |
if (stat(fpath, &st) == -1) |
break; |
break; |
|
|
|
if (st.st_uid == myuid) |
|
return; |
|
|
if ((pw = getpwuid(st.st_uid)) == NULL) |
if ((pw = getpwuid(st.st_uid)) == NULL) |
fatal("cvs_repository_lock: %s", strerror(errno)); |
fatal("cvs_repository_lock: %s", strerror(errno)); |
|
|
|
|
|
|
if (i == CVS_LOCK_TRIES) |
if (i == CVS_LOCK_TRIES) |
fatal("maximum wait time for lock inside '%s' reached", repo); |
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 ((i = open(fpath, O_WRONLY|O_CREAT|O_TRUNC, 0755)) < 0) { |
if (errno == EEXIST) |
if (errno == EEXIST) |