aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/fexecv.ccm
blob: 1fe57a8bd9a8efe581c2925044088f847512f017 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * This source code is released into the public domain.
 */

module;

#include <expected>
#include <string>

#include "nihil.hh"

export module nihil.posix:fexecv;

import nihil.error;
import :argv;
import :executor;
import :fd;

namespace nihil {

#ifdef NIHIL_HAVE_FEXECVE

/*
 * 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;
};

#endif	// NIHIL_HAVE_FEXECVE

} // namespace nihil