Skip to content

Commit

Permalink
Make fcntl locks work on unseekable files too
Browse files Browse the repository at this point in the history
Fixes #2267
  • Loading branch information
tbodt committed Oct 20, 2024
1 parent c993ea7 commit f1ea54d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions fs/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,15 @@ static int file_lock_from_flock(struct fd *fd, struct flock_ *flock, struct file
offset = 0;
break;
case LSEEK_CUR:
lock(&fd->lock);
offset = fd->ops->lseek(fd, 0, LSEEK_CUR);
unlock(&fd->lock);
if (offset < 0)
return offset;
if (!fd->ops->lseek) {
offset = 0;
} else {
lock(&fd->lock);
offset = fd->ops->lseek(fd, 0, LSEEK_CUR);
unlock(&fd->lock);
if (offset < 0)
return offset;
}
break;
case LSEEK_END: {
struct statbuf stat;
Expand Down

1 comment on commit f1ea54d

@jaclu
Copy link

@jaclu jaclu commented on f1ea54d Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work - the native sudo no longer crashes!

Please sign in to comment.