beterraba

commit 1ca1c892c1dc7718e27efa521d286fa1b72a2735

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

beterrabad: first attempt at a socket thing

 cmd/beterrabad/main.ha | 15 ++++++++++++++-


diff --git a/cmd/beterrabad/main.ha b/cmd/beterrabad/main.ha
index 3e5ff18eeea5561650dd163edbfc0a603b5c8ff9..ab58cba695ea8fe1e9dc0f73444d9fa3d562d274 100644
--- a/cmd/beterrabad/main.ha
+++ b/cmd/beterrabad/main.ha
@@ -4,6 +4,7 @@ use fs;
 use io;
 use strings;
 use path;
+use unix::signal;
 use fmt;
 
 // TODO: Log should be store in XDG_DATA_STATE?
@@ -24,6 +25,11 @@
 	const it = os::iter(servdir)!;
 	defer os::finish(it);
 
+	// TODO: Deal with a SIGTERM gracefully and clean up resources
+	//signal::block(signal::SIGTERM, signal::SIGINT);
+	//const sigfd = signal::signalfd(signal::SIGINT, signal::SIGTERM)!;
+	//defer io::close(sigfd)!;
+
 	for (true) {
 		match (fs::next(it)) {
 		case let ent: fs::dirent =>
@@ -47,7 +53,14 @@
 		append(services, beterraba::parse(servfile));
 	};
 
-	fmt::println("Services found:")!;
+	// TODO: We'll prolly need a socket in order to execute commands later
+	// on and add some sort of control binary (as rc-service does). But in
+	// order to do that I need to actually grok how sockets/poll(2) works.
+
+	//const sock = bind(&services, sigfd);
+	//defer shutdown(&sock);
+	//for (dispatch(&sock)) void;
+
 	for (let i = 0z; i < len(services); i += 1) {
 		fmt::printfln("\t {} - Cmd: {}",
 			services[i].name, services[i].cmd)!;