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

Close input/output handles when running in background #489

Merged
merged 1 commit into from
Aug 31, 2023
Merged
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
7 changes: 7 additions & 0 deletions mountpoint-s3/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::env;
use std::fs::File;
use std::io::{Read, Write};
use std::os::fd::AsRawFd;
use std::os::unix::prelude::FromRawFd;
use std::path::{Path, PathBuf};
use std::time::Duration;
Expand Down Expand Up @@ -309,6 +310,12 @@ fn main() -> anyhow::Result<()> {
.context("Failed to write data to the pipe")?;
drop(pipe_file);

// Logging is set up and the mount succeeded, so we can hang up
// stdin/out/err now to cleanly daemonize ourselves
nix::unistd::close(std::io::stdin().as_raw_fd()).context("couldn't close stdin")?;
nix::unistd::close(std::io::stdout().as_raw_fd()).context("couldn't close stdout")?;
nix::unistd::close(std::io::stderr().as_raw_fd()).context("couldn't close stderr")?;

session.join().context("failed to join session")?;
}
Err(e) => {
Expand Down