~sircmpwn/himitsu-ssh

668b5fce8ae853140da4340a5b9b271355c2501d — Hugo Osvaldo Barrera a month ago 324897f master 0.4
agent: allow specifying a custom path

Allow specifying a custom address for the socket. I chose the `-a` flag
simply because it matches with ssh-agent.

The default path remains the same.

I also removed some TODOs for hissh-agent to fork itself. Daemons
shouldn't fork themselves; this breaks service supervision. For
scenarios where this is necessary, there exist plenty of methods
to force a process into background without every daemon implementing
this itself.
1 files changed, 26 insertions(+), 5 deletions(-)

M cmd/hissh-agent/main.ha
M cmd/hissh-agent/main.ha => cmd/hissh-agent/main.ha +26 -5
@@ 8,6 8,7 @@ use errors;
use fmt;
use format::ssh;
use fs;
use getopt;
use himitsu::client;
use himitsu::query;
use himitsu::remember;


@@ 30,12 31,32 @@ type server = struct {
};

export fn main() void = {
	// TODO: Parse options (foreground/background, socket path)
	// TODO: Fork to background
	const path = path::init()!;
	path::set(&path, dirs::runtime()!, "hissh-agent")!;
	const cmd = getopt::parse(os::args,
		"hissh import",
		('a', "address", "bind to the unix-domain socket address"),
	);
	defer getopt::finish(&cmd);

	let address: (str | void) = void;
	for (let i = 0z; i < len(cmd.opts); i += 1) {
		const opt = cmd.opts[i];
		switch (opt.0) {
		case 'a' =>
			address = strings::dup(opt.1);
		case =>
			fmt::fatalf("unknown option");
		};
	};

	const sockpath = match (address) {
	case let s: str =>
		yield s;
	case void =>
		const path = path::init()!;
		path::set(&path, dirs::runtime()!, "hissh-agent")!;
		yield path::string(&path);
	};

	const sockpath = path::string(&path);
	const socket = match (unix::listen(sockpath)) {
	case let sock: net::socket =>
		yield sock;