Skip to content

Commit

Permalink
Merge pull request ish-app#649 from thunderkeys/fix_lock_flags
Browse files Browse the repository at this point in the history
Fix lockfile flag checks
  • Loading branch information
tbodt authored Feb 26, 2020
2 parents 47078b8 + fb7826f commit 47747dc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fs/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ int fcntl_getlk(struct fd *fd, struct flock_ *flock) {
int fcntl_setlk(struct fd *fd, struct flock_ *flock, bool blocking) {
if (flock->type != F_RDLCK_ && flock->type != F_WRLCK_ && flock->type != F_UNLCK_)
return _EINVAL;
if (flock->type == F_RDLCK_ && !(fd_getflags(fd) & (O_RDONLY_|O_RDWR_)))
int fd_mode = fd_getflags(fd) & O_ACCMODE_;
if (flock->type == F_RDLCK_ && fd_mode == O_WRONLY_)
return _EBADF;
if (flock->type == F_WRLCK_ && !(fd_getflags(fd) & (O_WRONLY_|O_RDWR_)))
if (flock->type == F_WRLCK_ && fd_mode == O_RDONLY_)
return _EBADF;

struct inode_data *inode = fd->inode;
Expand Down
1 change: 1 addition & 0 deletions kernel/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ int mount_remove(struct mount *mount);
extern struct list mounts;

// open flags
#define O_ACCMODE_ 3
#define O_RDONLY_ 0
#define O_WRONLY_ (1 << 0)
#define O_RDWR_ (1 << 1)
Expand Down

0 comments on commit 47747dc

Please sign in to comment.