diff options
author | Martijn van Duren <martijn@cvs.openbsd.org> | 2021-04-20 11:19:55 +0000 |
---|---|---|
committer | Martijn van Duren <martijn@cvs.openbsd.org> | 2021-04-20 11:19:55 +0000 |
commit | 8317a1bcf580c0ae5bc6ed844c073717f3f8fb7c (patch) | |
tree | 833a78de99d8b84f5d977ff1d71226f7fe8045a0 /regress/lib | |
parent | 04218780ebac0e3b1919622f7c7c9fb28f136fc2 (diff) |
Properly shutdown on connection loss instead of crashing.
Found by bluhm@ while playing with setting noclose to 1 for daemon(3):
Also included in this commit
OK bluhm@
Diffstat (limited to 'regress/lib')
-rw-r--r-- | regress/lib/libagentx/main.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/regress/lib/libagentx/main.c b/regress/lib/libagentx/main.c index 06bb8c60238..ff006b4270d 100644 --- a/regress/lib/libagentx/main.c +++ b/regress/lib/libagentx/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.5 2021/01/13 17:00:20 martijn Exp $ */ +/* $OpenBSD: main.c,v 1.6 2021/04/20 11:19:54 martijn Exp $ */ /* * Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org> @@ -39,7 +39,6 @@ void regress_fd(struct agentx *, void *, int); void regress_tryconnect(int, short, void *); -void regress_shutdown(void); void regress_read(int, short, void *); void regress_usr1(int, short, void *); void regress_usr2(int, short, void *); @@ -316,7 +315,7 @@ main(int argc, char *argv[]) fatal("agentx_object"); if (!dflag) { - if (daemon(0, 0) == -1) + if (daemon(0, 1) == -1) fatalx("daemon"); } @@ -337,9 +336,12 @@ regress_fd(struct agentx *sa2, void *cookie, int close) struct sockaddr_un sun; /* For ease of cleanup we take the single run approach */ - if (init) - regress_shutdown(); - else { + if (init) { + if (!close) + agentx_free(sa); + else + evtimer_del(&rev); + } else { sun.sun_family = AF_UNIX; strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); @@ -358,13 +360,6 @@ regress_read(int fd, short event, void *cookie) agentx_read(sa); } -void -regress_shutdown(void) -{ - agentx_free(sa); - evtimer_del(&connev); -} - #ifdef notyet void |