aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/fexecv.ccm
diff options
context:
space:
mode:
Diffstat (limited to 'nihil.posix/fexecv.ccm')
-rw-r--r--nihil.posix/fexecv.ccm53
1 files changed, 53 insertions, 0 deletions
diff --git a/nihil.posix/fexecv.ccm b/nihil.posix/fexecv.ccm
new file mode 100644
index 0000000..5ad6c62
--- /dev/null
+++ b/nihil.posix/fexecv.ccm
@@ -0,0 +1,53 @@
+/*
+ * This source code is released into the public domain.
+ */
+
+module;
+
+#include <expected>
+#include <string>
+
+#include "nihil.hh"
+
+#ifdef NIHIL_HAVE_FEXECVE
+
+export module nihil.posix:fexecv;
+
+import nihil.error;
+import :argv;
+import :executor;
+import :fd;
+
+namespace nihil {
+
+/*
+ * fexecv: use a file descriptor and an argument vector to call ::fexecve().
+ * This is the lowest-level executor which all others are implemented
+ * in terms of (if it's available).
+ *
+ * TODO: Should have a way to pass the environment (envp).
+ */
+export struct fexecv final {
+ using tag = exec_tag;
+
+ fexecv(fd &&execfd, argv &&args) noexcept;
+
+ [[nodiscard]] auto exec(this fexecv &self)
+ -> std::expected<void, error>;
+
+ // Movable
+ fexecv(fexecv &&) noexcept;
+ auto operator=(this fexecv &, fexecv &&) noexcept -> fexecv&;
+
+ // Not copyable (because we hold the open fd object)
+ fexecv(fexecv const &) = delete;
+ auto operator=(this fexecv &, fexecv const &) -> fexecv& = delete;
+
+private:
+ fd m_execfd;
+ argv m_args;
+};
+
+} // namespace nihil
+
+#endif // NIHIL_HAVE_FEXECVE \ No newline at end of file