From 63b506af6c65b8446f4ab74efeab6a47a52bffd3 Mon Sep 17 00:00:00 2001 From: Fedor Gogolev Date: Tue, 26 Mar 2019 22:15:41 +0300 Subject: [PATCH] style: replace try with ? --- src/lib.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index abfd33e00..488d8c5ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -386,19 +386,15 @@ impl Daemonize { 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); @@ -480,7 +476,7 @@ unsafe fn get_group(group: Group) -> Result { 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), @@ -497,7 +493,7 @@ unsafe fn get_user(user: User) -> Result { 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), @@ -511,7 +507,7 @@ unsafe fn set_user(user: uid_t) -> Result<()> { } unsafe fn create_pid_file(path: PathBuf) -> Result { - 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 { @@ -526,7 +522,7 @@ unsafe fn create_pid_file(path: PathBuf) -> Result { } 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(()),