"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
Re: move gotd_child_proc struct in gotd.c
To:
Stefan Sperling <stsp@stsp.name>
Cc:
gameoftrees@openbsd.org
Date:
Thu, 22 Jun 2023 15:51:54 +0200

Download raw body.

Thread
On 2023/06/22 13:33:39 +0200, Stefan Sperling <stsp@stsp.name> wrote:
> On Thu, Jun 22, 2023 at 12:03:27PM +0200, Omar Polo wrote:
> > I'm splitting the diff I sent yesterday into more manegeable bits.
> > 
> > This is not strictly needed, but sice the struct gotd_child_proc is
> > not used outside of gotd.c, let's move it there and allocate
> > dynamically listen_proc in gotd.
> > 
> > While here, I'm also dropping the `nhelpers' field which seems
> > currently unused.
> 
> OK, but please free listener proc memory explicitly in gotd_shutdown():

I didn't because I'm going to remove it in a next commit, but added
anyway since it's the right thing.

another minor tweak before the real diff, add a kill_repo_proc() like
the other kill_*_proc().  Since i'm going to change how procs are
killed next, I figured it would be easier if the repo process is
killed like the others.

(we could also do the opposite and inline these function to be honest,
but it'll be easier after the next diff :-)

-----------------------------------------------
commit e2918a2667faf7181d35089d2ae4e3a018d70f99 (main)
from: Omar Polo <op@omarpolo.com>
date: Thu Jun 22 13:47:18 2023 UTC
 
 add kill_repo_proc similar to the other kill_*_proc
 
diff a328bb1b14dfe7d99e5d66c3fab2d5ebe4c4119a e2918a2667faf7181d35089d2ae4e3a018d70f99
commit - a328bb1b14dfe7d99e5d66c3fab2d5ebe4c4119a
commit + e2918a2667faf7181d35089d2ae4e3a018d70f99
blob - 84ef3291493887b755234fd478a3f7a7ca500d19
blob + 39b1d2a54632934de2bfaf127e20f0b0f725f4c8
--- gotd/gotd.c
+++ gotd/gotd.c
@@ -308,6 +308,20 @@ kill_auth_proc(struct gotd_client *client)
 }
 
 static void
+kill_repo_proc(struct gotd_client *client)
+{
+	struct gotd_child_proc *proc;
+
+	if (client->repo == NULL)
+		return;
+
+	proc = client->repo;
+	client->repo = NULL;
+
+	proc_done(proc);
+}
+
+static void
 kill_auth_proc(struct gotd_client *client)
 {
 	struct gotd_child_proc *proc;
@@ -339,7 +353,6 @@ disconnect(struct gotd_client *client)
 disconnect(struct gotd_client *client)
 {
 	struct gotd_imsg_disconnect idisconnect;
-	struct gotd_child_proc *proc = client->repo;
 	struct gotd_child_proc *listen_proc = gotd.listen_proc;
 	uint64_t slot;
 
@@ -347,17 +360,8 @@ disconnect(struct gotd_client *client)
 
 	kill_auth_proc(client);
 	kill_session_proc(client);
+	kill_repo_proc(client);
 
-	if (proc) {
-		event_del(&proc->iev.ev);
-		msgbuf_clear(&proc->iev.ibuf.w);
-		close(proc->iev.ibuf.fd);
-		kill_proc(proc, 0);
-		wait_for_child(proc->pid);
-		free(proc);
-		proc = NULL;
-	}
-
 	idisconnect.client_id = client->id;
 	if (gotd_imsg_compose_event(&listen_proc->iev,
 	    GOTD_IMSG_DISCONNECT, PROC_GOTD, -1,