Skip to content

Commit

Permalink
Merge #2746
Browse files Browse the repository at this point in the history
2746: Fix invoking `wasmer binfmt register` from `$PATH` r=syrusakbary a=jcaesar

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description
Currently, invoking `wasmer binfmt register` from `$PATH` fails. 
```
$ wasmer binfmt register 
error: Cannot get path to wasmer executable
```

(Currently, only invoking it by absolute path (`$(which wasmer) binfmt register`, e.g. as would be from a systemd unit) works.)


I also added a commit that changes some bit twiddling with file modes to a nicer semantic check, but it does add a dependency. Please tell me if you don't want that.

# Review

- [ ] Add a short description of the change to the CHANGELOG.md file - Not necessary?


Co-authored-by: Julius Michaelis <gitter@liftm.de>
  • Loading branch information
bors[bot] and jcaesar committed Jan 7, 2022
2 parents a9da483 + 3bb95d5 commit 59183dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/cli/Cargo.toml
Expand Up @@ -55,6 +55,9 @@ fern = { version = "0.6", features = ["colored"], optional = true }
log = { version = "0.4", optional = true }
tempfile = "3"

[target.'cfg(target_os = "linux")'.dependencies]
unix_mode = "0.1.3"

[features]
# Don't add the compiler features in default, please add them on the Makefile
# since we might want to autoconfigure them depending on the availability on the host.
Expand Down
9 changes: 4 additions & 5 deletions lib/cli/src/commands/binfmt.rs
Expand Up @@ -43,8 +43,9 @@ fn seccheck(path: &Path) -> Result<()> {
}
let m = std::fs::metadata(path)
.with_context(|| format!("Can't check permissions of {}", path.to_string_lossy()))?;
use unix_mode::*;
anyhow::ensure!(
m.mode() & 0o2 == 0 || m.mode() & 0o1000 != 0,
!is_allowed(Accessor::Other, Access::Write, m.mode()) || is_sticky(m.mode()),
"{} is world writeable and not sticky",
path.to_string_lossy()
);
Expand All @@ -62,10 +63,8 @@ impl Binfmt {
Register | Reregister => {
temp_dir = tempfile::tempdir().context("Make temporary directory")?;
seccheck(temp_dir.path())?;
let bin_path_orig: PathBuf = env::args_os()
.nth(0)
.map(Into::into)
.filter(|p: &PathBuf| p.exists())
let bin_path_orig: PathBuf = env::current_exe()
.and_then(|p| p.canonicalize())
.context("Cannot get path to wasmer executable")?;
let bin_path = temp_dir.path().join("wasmer-binfmt-interpreter");
fs::copy(&bin_path_orig, &bin_path).context("Copy wasmer binary to temp folder")?;
Expand Down

0 comments on commit 59183dd

Please sign in to comment.