Patchwork D8402: rust-chg: move get_umask() call out of run() function

login
register
mail settings
Submitter phabricator
Date April 11, 2020, 11:24 a.m.
Message ID <differential-rev-PHID-DREV-wu52ncywaqklni7z5qmo-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46065/
State Superseded
Headers show

Comments

phabricator - April 11, 2020, 11:24 a.m.
yuja created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  run() will be an async function, but get_umask() isn't thread safe.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8402

AFFECTED FILES
  rust/chg/src/main.rs

CHANGE DETAILS




To: yuja, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/rust/chg/src/main.rs b/rust/chg/src/main.rs
--- a/rust/chg/src/main.rs
+++ b/rust/chg/src/main.rs
@@ -59,15 +59,15 @@ 
 
     // TODO: add loop detection by $CHGINTERNALMARK
 
-    let code = run().unwrap_or_else(|err| {
+    let umask = unsafe { procutil::get_umask() }; // not thread safe
+    let code = run(umask).unwrap_or_else(|err| {
         writeln!(io::stderr(), "chg: abort: {}", err).unwrap_or(());
         255
     });
     process::exit(code);
 }
 
-fn run() -> io::Result<i32> {
-    let umask = unsafe { procutil::get_umask() }; // not thread safe
+fn run(umask: u32) -> io::Result<i32> {
     let mut loc = Locator::prepare_from_env()?;
     loc.set_early_args(locator::collect_early_args(env::args_os().skip(1)));
     let handler = ChgUiHandler::new();