Skip to content

Commit 6526684

Browse files
committed
Fix file permission selection in libinput interface
The correct way to obtain the access mode is to use the O_ACCMODE mask.
1 parent 54cfc45 commit 6526684

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use input::{
2222
keyboard::{KeyboardEvent, KeyboardEventTrait, KeyState}
2323
}
2424
};
25-
use libc::{O_RDONLY, O_RDWR, O_WRONLY, c_char};
25+
use libc::{O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY, c_char};
2626
use input_linux::{uinput::UInputHandle, EventKind, Key, SynchronizeKind};
2727
use input_linux_sys::{uinput_setup, input_id, timeval, input_event};
2828
use nix::poll::{poll, PollFd, PollFlags};
@@ -152,10 +152,12 @@ struct Interface;
152152

153153
impl LibinputInterface for Interface {
154154
fn open_restricted(&mut self, path: &Path, flags: i32) -> Result<OwnedFd, i32> {
155+
let mode = flags & O_ACCMODE;
156+
155157
OpenOptions::new()
156158
.custom_flags(flags)
157-
.read((flags & O_RDONLY != 0) | (flags & O_RDWR != 0))
158-
.write((flags & O_WRONLY != 0) | (flags & O_RDWR != 0))
159+
.read(mode == O_RDONLY || mode == O_RDWR)
160+
.write(mode == O_WRONLY || mode == O_RDWR)
159161
.open(path)
160162
.map(|file| file.into())
161163
.map_err(|err| err.raw_os_error().unwrap())

0 commit comments

Comments
 (0)