Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
e9058803d3
|
|||
|
a4a556a5b6
|
|||
|
e2c03842a3
|
|||
|
0fd66bff38
|
|||
|
0c4923016e
|
2
Makefile
2
Makefile
@@ -19,7 +19,7 @@ PREFIX ?= /usr/local
|
|||||||
# for conditionally compiling OS features
|
# for conditionally compiling OS features
|
||||||
OS != uname
|
OS != uname
|
||||||
OS_INCLUDE != test -e include/$(OS).mk && printf 'include/$(OS).mk\n' \
|
OS_INCLUDE != test -e include/$(OS).mk && printf 'include/$(OS).mk\n' \
|
||||||
|| include/None.mk
|
|| printf '/dev/null\n'
|
||||||
|
|
||||||
# normalized prefix
|
# normalized prefix
|
||||||
PREFIX_N != dirname $(PREFIX)/.
|
PREFIX_N != dirname $(PREFIX)/.
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
* Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||||
* SPDX-License-Identifier: CC0
|
* SPDX-License-Identifier: CC0
|
||||||
*
|
*
|
||||||
* This work is marked with CC0 1.0. To view a copy of this license, visit
|
* This work is marked with CC0 1.0. To view a copy of this license, visit
|
||||||
@@ -10,9 +11,9 @@
|
|||||||
# include <unistd.h> /* pledge(2) */
|
# include <unistd.h> /* pledge(2) */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main() {
|
int main(void) {
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
pledge(NULL, NULL);
|
pledge(NULL, NULL);
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ use sysexits::EX_USAGE;
|
|||||||
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge };
|
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge };
|
||||||
#[cfg(target_os="openbsd")] use strerror::StrError;
|
#[cfg(target_os="openbsd")] use strerror::StrError;
|
||||||
|
|
||||||
|
|
||||||
fn usage(s: &str) -> ExitCode {
|
fn usage(s: &str) -> ExitCode {
|
||||||
eprintln!("Usage: {} [-egl] integer integer...", s);
|
eprintln!("Usage: {} [-egl] integer integer...", s);
|
||||||
ExitCode::from(EX_USAGE as u8)
|
ExitCode::from(EX_USAGE as u8)
|
||||||
|
|||||||
39
src/mm.rs
39
src/mm.rs
@@ -52,7 +52,7 @@ fn main() -> ExitCode {
|
|||||||
let usage = format!("Usage: {} [-aetu] [-i input] [-o output]", argv[0]);
|
let usage = format!("Usage: {} [-aetu] [-i input] [-o output]", argv[0]);
|
||||||
|
|
||||||
if cfg!(target_os="openbsd") {
|
if cfg!(target_os="openbsd") {
|
||||||
let promises = Promises::new("rpath stdio unveil");
|
let promises = Promises::new("cpath rpath stdio unveil wpath");
|
||||||
if let Err(e) = pledge(Some(promises), None) {
|
if let Err(e) = pledge(Some(promises), None) {
|
||||||
eprintln!("{}: {}", argv[0], e.strerror());
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
return ExitCode::from(EX_OSERR as u8);
|
return ExitCode::from(EX_OSERR as u8);
|
||||||
@@ -76,29 +76,11 @@ fn main() -> ExitCode {
|
|||||||
Ok("t") => t = false,
|
Ok("t") => t = false,
|
||||||
Ok("i") => { /* add inputs */
|
Ok("i") => { /* add inputs */
|
||||||
let input = opt.arg().unwrap();
|
let input = opt.arg().unwrap();
|
||||||
|
|
||||||
if cfg!(target_os="openbsd") {
|
|
||||||
let perms = UnveilPerms::new(vec!['r']);
|
|
||||||
if let Err(e) = unveil(Some(&input), Some(perms)) {
|
|
||||||
eprintln!("{}: {}", argv[0], e.strerror());
|
|
||||||
return ExitCode::from(EX_OSERR as u8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ins.push(input);
|
ins.push(input);
|
||||||
mode = Some(In); /* latest argument == -i */
|
mode = Some(In); /* latest argument == -i */
|
||||||
},
|
},
|
||||||
Ok("o") => { /* add output */
|
Ok("o") => { /* add output */
|
||||||
let output = opt.arg().unwrap();
|
let output = opt.arg().unwrap();
|
||||||
|
|
||||||
if cfg!(target_os="openbsd") {
|
|
||||||
let perms = UnveilPerms::new(vec!['w', 'c']);
|
|
||||||
if let Err(e) = unveil(Some(&output), Some(perms)) {
|
|
||||||
eprintln!("{}: {}", argv[0], e.strerror());
|
|
||||||
return ExitCode::from(EX_OSERR as u8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
outs.push(output);
|
outs.push(output);
|
||||||
mode = Some(Out); /* latest argument == -o */
|
mode = Some(Out); /* latest argument == -o */
|
||||||
},
|
},
|
||||||
@@ -125,6 +107,25 @@ fn main() -> ExitCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg!(target_os="openbsd") {
|
if cfg!(target_os="openbsd") {
|
||||||
|
|
||||||
|
for input in &ins {
|
||||||
|
let perms = UnveilPerms::new(vec!['r']);
|
||||||
|
|
||||||
|
if let Err(e) = unveil(Some(&input), Some(perms)) {
|
||||||
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
|
return ExitCode::from(EX_OSERR as u8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for output in &outs {
|
||||||
|
let perms = UnveilPerms::new(vec!['c', 'w']);
|
||||||
|
|
||||||
|
if let Err(e) = unveil(Some(&output), Some(perms)) {
|
||||||
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
|
return ExitCode::from(EX_OSERR as u8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Err(e) = unveil(None, None) {
|
if let Err(e) = unveil(None, None) {
|
||||||
eprintln!("{}: {}", argv[0], e.strerror());
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
return ExitCode::from(EX_OSERR as u8);
|
return ExitCode::from(EX_OSERR as u8);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
* Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||||
* SPDX-License-Identifier: CC0
|
* SPDX-License-Identifier: CC0
|
||||||
*
|
*
|
||||||
* This work is marked with CC0 1.0. To view a copy of this license, visit
|
* This work is marked with CC0 1.0. To view a copy of this license, visit
|
||||||
@@ -10,7 +11,7 @@
|
|||||||
# include <unistd.h> /* pledge(2) */
|
# include <unistd.h> /* pledge(2) */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main() {
|
int main(void) {
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
pledge(NULL, NULL);
|
pledge(NULL, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2024 E$(NAME)a Tebibyte <e$(NAME)a@tebibyte.media>
|
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PHONY: mm_tests
|
.PHONY: mm_tests
|
||||||
mm_tests: mm_args mm_help mm_stderr
|
mm_tests: mm_args mm_help mm_stderr mm_remaining
|
||||||
|
|
||||||
.PHONY: mm_none
|
.PHONY: mm_none
|
||||||
mm_none: $(BIN)/mm
|
mm_none: $(BIN)/mm
|
||||||
@@ -25,3 +25,10 @@ mm_help: $(BIN)/mm
|
|||||||
# check if stderr is empty upon specifying -e
|
# check if stderr is empty upon specifying -e
|
||||||
mm_stderr: $(BIN)/mm
|
mm_stderr: $(BIN)/mm
|
||||||
test "$$(printf 'test\n' | $(BIN)/mm -e 2>&1 >/dev/null )" = "test"
|
test "$$(printf 'test\n' | $(BIN)/mm -e 2>&1 >/dev/null )" = "test"
|
||||||
|
|
||||||
|
.PHONY: mm_remaining
|
||||||
|
# check to make sure remaining arguments are used
|
||||||
|
mm_remaining: $(BIN)/mm
|
||||||
|
test "$$($(BIN)/mm -i README COPYING)" = "$$(cat README COPYING)"
|
||||||
|
$(BIN)/mm -i README -o /tmp/mm_test0 /tmp/mm_test1
|
||||||
|
diff /tmp/mm_test0 /tmp/mm_test1
|
||||||
|
|||||||
Reference in New Issue
Block a user