lock_file(): exit early if lockfile cannot be opened
[gitweb.git] / lockfile.c
index 23847fc9f2d0f678a34b343902d304a8d022840a..a8f32e5495d8b064e921e73fa4268f11d19b1c2b 100644 (file)
@@ -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;
 }