Skip to content

chore!: drop daemonize crate#372

Merged
ethanpailes merged 1 commit into
masterfrom
drop-daemonize-crate
Jun 12, 2026
Merged

chore!: drop daemonize crate#372
ethanpailes merged 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.

@ethanpailes ethanpailes requested a review from maxhbooth May 12, 2026 03:57
Comment thread libshpool/src/daemonize.rs Outdated
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I gave it a try, but there is no way to make a OwnedFd for the std file descriptors because they are shared globals. This made me realize I need to mark this function unsafe and document the precondution that the std file descriptors can't be under contention when it is called though (we were already meeting this precondition but the function needs to document it's preconditions in order to be sound).

Comment thread libshpool/src/daemonize.rs Outdated

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?

@ethanpailes ethanpailes Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, fixed with fcntl::open

Comment thread libshpool/src/daemonize.rs Outdated

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call, that takes care of cleaning up the fd as well.

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 force-pushed the drop-daemonize-crate branch from 630bc34 to 70f5c89 Compare June 12, 2026 16:50
@ethanpailes ethanpailes merged commit d14c636 into master Jun 12, 2026
11 checks passed
@ethanpailes ethanpailes deleted the drop-daemonize-crate branch June 12, 2026 20:45
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