Skip to content
Open
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
21 changes: 16 additions & 5 deletions daemonize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ pub struct Daemonize<T> {
directory: PathBuf,
pid_file: Option<PathBuf>,
chown_pid_file: bool,
set_group_and_user_id: bool,
user: Option<User>,
group: Option<Group>,
umask: Mask,
Expand All @@ -239,6 +240,7 @@ impl<T> fmt::Debug for Daemonize<T> {
.field("directory", &self.directory)
.field("pid_file", &self.pid_file)
.field("chown_pid_file", &self.chown_pid_file)
.field("set_group_and_user_id", &self.set_group_and_user_id)
.field("user", &self.user)
.field("group", &self.group)
.field("umask", &self.umask)
Expand All @@ -262,6 +264,7 @@ impl Daemonize<()> {
directory: Path::new("/").to_owned(),
pid_file: None,
chown_pid_file: false,
set_group_and_user_id: true,
user: None,
group: None,
umask: 0o027.into(),
Expand All @@ -287,6 +290,12 @@ impl<T> Daemonize<T> {
self
}

/// If `set` is true, daemonize will set the effective group and user ID of the calling process, if user or group are provided
pub fn set_group_and_user_id(mut self, set: bool) -> Self {
self.set_group_and_user_id = set;
self
}

/// Change working directory to `path` or `/` by default.
pub fn working_directory<F: AsRef<Path>>(mut self, path: F) -> Self {
self.directory = path.as_ref().to_owned();
Expand Down Expand Up @@ -414,12 +423,14 @@ impl<T> Daemonize<T> {
change_root(root)?;
}

if let Some(gid) = gid {
set_group(gid)?;
}
if self.set_group_and_user_id {
if let Some(gid) = gid {
set_group(gid)?;
}

if let Some(uid) = uid {
set_user(uid)?;
if let Some(uid) = uid {
set_user(uid)?;
}
}

if let Some(pid_file_fd) = pid_file_fd {
Expand Down