~sircmpwn/himitsu-devel

himitsu: Implement readiness notification v1 APPLIED

Hugo Osvaldo Barrera: 1
 Implement readiness notification

 2 files changed, 23 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/himitsu-devel/patches/53096/mbox | git am -3
Learn more about email & git

[PATCH himitsu] Implement readiness notification Export this patch

This allows ordering services that depend on himitsud to start after
himitsud is ready to accept connections.

The chosen readiness notification mechanism is compatible with s6, dinit
and systemd.
---
v2: properly reflect written value in man page
 cmd/himitsud/main.ha | 22 +++++++++++++++++++++-
 docs/himitsud.1.scd  |  2 ++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/cmd/himitsud/main.ha b/cmd/himitsud/main.ha
index fab1b9c..9ea132f 100644
--- a/cmd/himitsud/main.ha
+++ b/cmd/himitsud/main.ha
@@ -7,6 +7,8 @@ use os::exec;
use os;
use rt;
use secstore;
use strconv;
use strings;
use unix::signal;
use unix;

@@ -19,14 +21,24 @@ let sigwrite: io::file = -1;
export fn main() void = {
	const cmd = getopt::parse(os::args,
		// TODO: Add note warning against using this to himitsu man page
		('D', "daemonize (fork) after startup"));
		('D', "daemonize (fork) after startup"),
		('R', "fd", "notify readiness on file descriptor"),
	);
	defer getopt::finish(&cmd);

	let daemonize = false;
	let ready_fd: (void|io::file) = void;
	for (let opt &.. cmd.opts) {
		switch (opt.0) {
		case 'D' =>
			daemonize = true;
		case 'R' =>
			match (strconv::stoi(opt.1)) {
			case let err: (strconv::invalid | strconv::overflow) =>
				fmt::fatalf("Invalid parameter for -R: {}.", strconv::strerror(err));
			case let i: int =>
				ready_fd = i;
			};
		case => abort();
		};
	};
@@ -75,6 +87,14 @@ export fn main() void = {
	const flags = rt::fcntl(sock.sock, rt::F_GETFL, 0)!;
	rt::fcntl(sock.sock, rt::F_SETFL, flags | rt::O_CLOEXEC)!;

	match (ready_fd) {
	case let f: io::file => {
		io::write(f, strings::toutf8("READY=1\n"))!;
		io::close(f)!;
	};
	case void => void;
	};
	
	log::println("himitsud running");
	for (dispatch(&sock)) void;
	log::println("himitsud terminated");
diff --git a/docs/himitsud.1.scd b/docs/himitsud.1.scd
index 9897449..aa64d3e 100644
--- a/docs/himitsud.1.scd
+++ b/docs/himitsud.1.scd
@@ -26,6 +26,8 @@ The following options are recognized by *himitsud*:

*-D*
	Daemonize (fork) the himitsud process after startup.
*-R fd*
	Notify readiness by writing *READY=1\n* into *fd* and then closing.

# SEE ALSO

-- 
2.45.1
Thanks!

To https://git.sr.ht/~sircmpwn/himitsu
   c657d70..6becc84  master -> master