Skip to content

Commit

Permalink
open with O_CLOEXEC
Browse files Browse the repository at this point in the history
This fixes a problem with Tauri auto update: After updating the tauri
application it is restarted, but the serial files were not closed, and
therefore the application could not open them again.

With this flag the files are closed when executing `execve()` to start
the new application instance.

Change-Id: I102ba33411135a8e89e3203f9dad910d385feeee
  • Loading branch information
Morten Laursen committed Oct 19, 2023
1 parent 1546d77 commit 8a597ef
Showing 1 changed file with 2 additions and 2 deletions.
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

0 comments on commit 8a597ef

Please sign in to comment.