Skip to content

Commit

Permalink
style: replace try with ?
Browse files Browse the repository at this point in the history
  • Loading branch information
knsd committed Mar 26, 2019
1 parent 97028fc commit 63b506a
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,19 +386,15 @@ impl<T> Daemonize<T> {
unsafe {
let pid_file_fd = maptry!(self.pid_file.clone(), create_pid_file);

try!(perform_fork(Some(self.exit_action)));
perform_fork(Some(self.exit_action))?;

try!(set_current_dir(&self.directory).map_err(|_| DaemonizeError::ChangeDirectory));
try!(set_sid());
set_current_dir(&self.directory).map_err(|_| DaemonizeError::ChangeDirectory)?;
set_sid()?;
umask(self.umask);

try!(perform_fork(None));
perform_fork(None)?;

try!(redirect_standard_streams(
self.stdin,
self.stdout,
self.stderr
));
redirect_standard_streams(self.stdin, self.stdout, self.stderr)?;

let uid = maptry!(self.user, get_user);
let gid = maptry!(self.group, get_group);
Expand Down Expand Up @@ -480,7 +476,7 @@ unsafe fn get_group(group: Group) -> Result<gid_t> {
match group {
Group::Id(id) => Ok(id),
Group::Name(name) => {
let s = try!(CString::new(name).map_err(|_| DaemonizeError::GroupContainsNul));
let s = CString::new(name).map_err(|_| DaemonizeError::GroupContainsNul)?;
match get_gid_by_name(&s) {
Some(id) => get_group(Group::Id(id)),
None => Err(DaemonizeError::GroupNotFound),
Expand All @@ -497,7 +493,7 @@ unsafe fn get_user(user: User) -> Result<uid_t> {
match user {
User::Id(id) => Ok(id),
User::Name(name) => {
let s = try!(CString::new(name).map_err(|_| DaemonizeError::UserContainsNul));
let s = CString::new(name).map_err(|_| DaemonizeError::UserContainsNul)?;
match get_uid_by_name(&s) {
Some(id) => get_user(User::Id(id)),
None => Err(DaemonizeError::UserNotFound),
Expand All @@ -511,7 +507,7 @@ unsafe fn set_user(user: uid_t) -> Result<()> {
}

unsafe fn create_pid_file(path: PathBuf) -> Result<libc::c_int> {
let path_c = try!(pathbuf_into_cstring(path));
let path_c = pathbuf_into_cstring(path)?;

let fd = open(path_c.as_ptr(), libc::O_WRONLY | libc::O_CREAT, 0o666);
if -1 == fd {
Expand All @@ -526,7 +522,7 @@ unsafe fn create_pid_file(path: PathBuf) -> Result<libc::c_int> {
}

unsafe fn chown_pid_file(path: PathBuf, uid: uid_t, gid: gid_t) -> Result<()> {
let path_c = try!(pathbuf_into_cstring(path));
let path_c = pathbuf_into_cstring(path)?;
tryret!(
libc::chown(path_c.as_ptr(), uid, gid),
Ok(()),
Expand Down

0 comments on commit 63b506a

Please sign in to comment.