Skip to content

chore!: drop daemonize crate#372

Open
ethanpailes wants to merge 1 commit into
masterfrom
drop-daemonize-crate
Open

chore!: drop daemonize crate#372
ethanpailes wants to merge 1 commit into
masterfrom
drop-daemonize-crate

Conversation

@ethanpailes
Copy link
Copy Markdown
Contributor

Issue Link

The nightly cargo deny tests have been failing for a while. This is me attempting to clean them up.

AI Policy Ack

Ack

This PR was:

  • mostly or completely vibe coded
  • mostly or completely meat coded
  • bit of both

I vibed the tests

Description

This patch drops teh daemonize crate in favor of our own daemonization implementation. The daemonize crate is apparently unmaintained, so we need to migrate off of it for security.

In writing this patch, I realized that libshpool::run was technically unsound (though in practice, no reasonable caller would trigger unsoundness). Unfortunately, to fix it properly I needed to mark the entrypoint unsafe and document the required preconditions (can't call from a multi-threaded program in a situation where it might be self-execed to auto-daemonize). Unfortunately this requires a breaking version upgrade.

This patch drops teh daemonize crate in favor of our
own daemonization implementation. The daemonize crate
is apparently unmaintained, so we need to migrate off
of it for security.

In writing this patch, I realized that libshpool::run
was technically unsound (though in practice, no reasonable
caller would trigger unsoundness). Unfortunately, to fix
it properly I needed to mark the entrypoint `unsafe` and
document the required preconditions (can't call from a multi-threaded
program in a situation where it might be self-execed to auto-daemonize).
Unfortunately this requires a breaking version upgrade.
@ethanpailes ethanpailes requested a review from maxhbooth May 12, 2026 03:57
return Err(anyhow!("redirecting stdin to /dev/null: {}", nix::errno::Errno::last()));
}
// Safety: nullfd is valid and newfd need not be open for saftey
let fd = unsafe { libc::dup2(nullfd, libc::STDOUT_FILENO) };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should you be using nix's dup2 instead? https://docs.rs/nix/latest/nix/unistd/fn.dup2.html


fn redirect_std_fds_to_null() -> anyhow::Result<()> {
// Safety: path is a valid null terminated string, O_RDWR is a valid flag.
let nullfd = unsafe { libc::open(b"/dev/null\0" as *const [u8; 10] as _, libc::O_RDWR) };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to close nullfd after we finish duping?


fn redirect_std_fds_to_null() -> anyhow::Result<()> {
// Safety: path is a valid null terminated string, O_RDWR is a valid flag.
let nullfd = unsafe { libc::open(b"/dev/null\0" as *const [u8; 10] as _, libc::O_RDWR) };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nix::fcntl::open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants