Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open with O_CLOEXEC #130

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ project adheres to [Semantic Versioning](https://semver.org/).

* Update `bitflags` dependency to 2.4.0.
[#127](https://github.com/serialport/serialport-rs/pull/127)
- Open serial devices with `O_CLOEXEC` (Posix). This will close the device
handles when starting a child process. In particular this means that a serial
device can be reopened after making SW update of a Tauri application.
[#130](https://github.com/serialport/serialport-rs/pull/130)

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions src/posix/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl TTYPort {
let path = Path::new(&builder.path);
let fd = OwnedFd(nix::fcntl::open(
path,
OFlag::O_RDWR | OFlag::O_NOCTTY | OFlag::O_NONBLOCK,
OFlag::O_RDWR | OFlag::O_NOCTTY | OFlag::O_NONBLOCK | OFlag::O_CLOEXEC,
nix::sys::stat::Mode::empty(),
)?);

Expand Down Expand Up @@ -344,7 +344,7 @@ impl TTYPort {
///
/// This function returns an error if the serial port couldn't be cloned.
pub fn try_clone_native(&self) -> Result<TTYPort> {
let fd_cloned: i32 = fcntl(self.fd, nix::fcntl::F_DUPFD(self.fd))?;
let fd_cloned: i32 = fcntl(self.fd, nix::fcntl::F_DUPFD_CLOEXEC(self.fd))?;
Ok(TTYPort {
fd: fd_cloned,
exclusive: self.exclusive,
Expand Down
Loading