commit 83800f991b30f8a5dc3a54f74d4a2efca4762d8f
parent cef3435935b046fde93f3d51aed867547103a60b
Author: Drew DeVault <sir@cmpwn.com>
Date: Mon, 22 Nov 2021 10:14:30 +0100
os::exec: fix dependencies and +freebsd
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
3 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/os/exec/exec+freebsd.ha b/os/exec/exec+freebsd.ha
@@ -17,6 +17,29 @@ export fn fork() (int | void | error) = {
};
};
+// Creates an anonymous pipe for use with [[addfile]]. Any data written to the
+// second file may be read from the first file. The caller should close one or
+// both of the file descriptors after they have transferred them to another
+// process, and after they have finished using them themselves, if applicable.
+//
+// This function will abort the process if the system is unable to allocate the
+// resources for a pipe. If you need to handle this error gracefully, you may
+// call [[unix::pipe]] yourself, but this may reduce the portability of your
+// software.
+//
+// To capture the standard output of a process:
+//
+// let pipe = exec::pipe();
+// exec::addfile(&cmd, pipe.1, os::stdout_file);
+// exec::start(&cmd);
+// io::close(pipe.1);
+//
+// let data = io::drain(pipe.0)!;
+// io::close(pipe.0);
+export fn pipe() (io::file, io::file) = {
+ return unix::pipe()!;
+};
+
fn open(path: str) (platform_cmd | error) = {
// TODO: This is racy, rewrite with TOCTOU
match (rt::access(path, rt::X_OK)) {
diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib
@@ -871,14 +871,14 @@ os_exec() {
process+linux.ha \
types.ha \
cmd.ha
- gen_ssa -plinux os::exec os strings fmt bytes path errors
+ gen_ssa -plinux os::exec os strings fmt bytes path errors unix
gen_srcs -pfreebsd os::exec \
exec+freebsd.ha \
process+freebsd.ha \
types.ha \
cmd.ha
- gen_ssa -pfreebsd os::exec os strings fmt bytes path errors
+ gen_ssa -pfreebsd os::exec os strings fmt bytes path errors unix
}
path() {
diff --git a/stdlib.mk b/stdlib.mk
@@ -1419,7 +1419,7 @@ stdlib_os_exec_linux_srcs= \
$(STDLIB)/os/exec/types.ha \
$(STDLIB)/os/exec/cmd.ha
-$(HARECACHE)/os/exec/os_exec-linux.ssa: $(stdlib_os_exec_linux_srcs) $(stdlib_rt) $(stdlib_os_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_path_$(PLATFORM)) $(stdlib_errors_$(PLATFORM))
+$(HARECACHE)/os/exec/os_exec-linux.ssa: $(stdlib_os_exec_linux_srcs) $(stdlib_rt) $(stdlib_os_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_path_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_unix_$(PLATFORM))
@printf 'HAREC \t$@\n'
@mkdir -p $(HARECACHE)/os/exec
@HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nos::exec \
@@ -1432,7 +1432,7 @@ stdlib_os_exec_freebsd_srcs= \
$(STDLIB)/os/exec/types.ha \
$(STDLIB)/os/exec/cmd.ha
-$(HARECACHE)/os/exec/os_exec-freebsd.ssa: $(stdlib_os_exec_freebsd_srcs) $(stdlib_rt) $(stdlib_os_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_path_$(PLATFORM)) $(stdlib_errors_$(PLATFORM))
+$(HARECACHE)/os/exec/os_exec-freebsd.ssa: $(stdlib_os_exec_freebsd_srcs) $(stdlib_rt) $(stdlib_os_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_path_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_unix_$(PLATFORM))
@printf 'HAREC \t$@\n'
@mkdir -p $(HARECACHE)/os/exec
@HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nos::exec \
@@ -3171,7 +3171,7 @@ testlib_os_exec_linux_srcs= \
$(STDLIB)/os/exec/types.ha \
$(STDLIB)/os/exec/cmd.ha
-$(TESTCACHE)/os/exec/os_exec-linux.ssa: $(testlib_os_exec_linux_srcs) $(testlib_rt) $(testlib_os_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_path_$(PLATFORM)) $(testlib_errors_$(PLATFORM))
+$(TESTCACHE)/os/exec/os_exec-linux.ssa: $(testlib_os_exec_linux_srcs) $(testlib_rt) $(testlib_os_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_path_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_unix_$(PLATFORM))
@printf 'HAREC \t$@\n'
@mkdir -p $(TESTCACHE)/os/exec
@HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nos::exec \
@@ -3184,7 +3184,7 @@ testlib_os_exec_freebsd_srcs= \
$(STDLIB)/os/exec/types.ha \
$(STDLIB)/os/exec/cmd.ha
-$(TESTCACHE)/os/exec/os_exec-freebsd.ssa: $(testlib_os_exec_freebsd_srcs) $(testlib_rt) $(testlib_os_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_path_$(PLATFORM)) $(testlib_errors_$(PLATFORM))
+$(TESTCACHE)/os/exec/os_exec-freebsd.ssa: $(testlib_os_exec_freebsd_srcs) $(testlib_rt) $(testlib_os_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_path_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_unix_$(PLATFORM))
@printf 'HAREC \t$@\n'
@mkdir -p $(TESTCACHE)/os/exec
@HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nos::exec \