summaryrefslogtreecommitdiff
path: root/lockfile.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2014-10-01 10:28:18 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-10-01 20:45:12 (GMT)
commite31e949b9f9b5e6dcff42e2242cf1a6fb3686b91 (patch)
tree614d90b3ae196a0ab24ec13c5bebeeb944b007be /lockfile.c
parent35ff08be099b36d0be855040a296f985d25dfd0a (diff)
downloadgit-e31e949b9f9b5e6dcff42e2242cf1a6fb3686b91.zip
git-e31e949b9f9b5e6dcff42e2242cf1a6fb3686b91.tar.gz
git-e31e949b9f9b5e6dcff42e2242cf1a6fb3686b91.tar.bz2
lock_file(): exit early if lockfile cannot be opened
This is a bit easier to read than the old version, which nested part of the non-error code in an "if" block. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Ronnie Sahlberg <sahlberg@google.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'lockfile.c')
-rw-r--r--lockfile.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/lockfile.c b/lockfile.c
index 23847fc..a8f32e5 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -197,19 +197,18 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
resolve_symlink(lk->filename, max_path_len);
strcat(lk->filename, LOCK_SUFFIX);
lk->fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
- if (0 <= lk->fd) {
- lk->owner = getpid();
- if (adjust_shared_perm(lk->filename)) {
- int save_errno = errno;
- error("cannot fix permission bits on %s",
- lk->filename);
- rollback_lock_file(lk);
- errno = save_errno;
- return -1;
- }
- }
- else
+ if (lk->fd < 0) {
lk->filename[0] = 0;
+ return -1;
+ }
+ lk->owner = getpid();
+ if (adjust_shared_perm(lk->filename)) {
+ int save_errno = errno;
+ error("cannot fix permission bits on %s", lk->filename);
+ rollback_lock_file(lk);
+ errno = save_errno;
+ return -1;
+ }
return lk->fd;
}