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.
---
cmd/hissh-agent/main.ha | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/cmd/hissh-agent/main.ha b/cmd/hissh-agent/main.ha
index f38d499..6f61c04 100644
--- a/cmd/hissh-agent/main.ha
+++ b/cmd/hissh-agent/main.ha
@@ -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;
--
2.45.2
On Mon Jul 8, 2024 at 7:07 PM CEST, Hugo Osvaldo Barrera wrote:
> Allow specifying a custom address for the socket. I chose the `-a` flag
> simply because it matches with ssh-agent.
>
> ...
Sorry, forgot about format.subjectPrefix. This patch is for `himitsu-ssh`.