From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26243 invoked from network); 28 Jun 2022 18:29:09 -0000 Received: from tb-ob0.topicbox.com (64.147.108.117) by inbox.vuxu.org with ESMTPUTF8; 28 Jun 2022 18:29:09 -0000 Received: from tb-mx0.topicbox.com (tb-mx0.nyi.icgroup.com [10.90.30.73]) by tb-ob0.topicbox.com (Postfix) with ESMTP id E00922CD92 for ; Tue, 28 Jun 2022 14:29:08 -0400 (EDT) (envelope-from bounce.mMc1bc6e87aa53de84e2f20729.r522be890-2105-11eb-b15e-8d699134e1fa@9fans.bounce.topicbox.com) Received: by tb-mx0.topicbox.com (Postfix, from userid 1132) id DC66D2A63374; Tue, 28 Jun 2022 14:29:08 -0400 (EDT) ARC-Authentication-Results: i=2; topicbox.com; arc=pass; dkim=none (no signatures found); dmarc=pass policy.published-domain-policy=none policy.published-subdomain-policy=none policy.applied-disposition=none policy.evaluated-disposition=none (p=none,sp=none,d=none,d.eval=none) policy.policy-from=p header.from=sdf.org; spf=pass smtp.mailfrom=adr@SDF.ORG smtp.helo=mx.sdf.org; x-internal-arc=fail (as.1.topicbox.com=pass, ams.1.topicbox.com=fail (message has been altered)) (Message modified while forwarding at Topicbox) ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d= topicbox.com; h=date:from:to:subject:in-reply-to:message-id :references:mime-version:content-type:list-help:list-id :list-post:list-subscribe:reply-to:content-transfer-encoding :list-unsubscribe; s=sysmsg-1; t=1656440948; bh=TXkTBnUQQ7TmGe4E ByqFsJ4hqFkjedaN4yZOBSU43KY=; b=LamVMn5u2Jw0Hh6Vve2c9skG7EhyDVSr rub5rzyYNypFdEgYTOBlOLI83WMsZcJi2mMbIO8YEaWdFGZcgV7ZiNF459YgcLzT b6VkGbWbgfngOZFZJm+qLZS0aHumUK6B3ClphLoWSQxntX3bsiDkhy21C0ghijk7 aGBEjUQr7Po= ARC-Seal: i=2; a=rsa-sha256; cv=pass; d=topicbox.com; s=sysmsg-1; t= 1656440948; b=mGErfqHyhiEdeZYdbSvbPcbcG4rAahsk7RccJOebHY9fLoGHh4 Qok44NEARE9COeOgXSk2syYQSOOB+Ve8g1WODPtm4vGfzDeWMJKgEZDOPtQb0Dap eGGaAtBjq6VmRKqrKh++qwuqGqRflDCgIgD6uUqqUFHf7SUpRuLwHyXO8= Authentication-Results: topicbox.com; arc=pass; dkim=none (no signatures found); dmarc=pass policy.published-domain-policy=none policy.published-subdomain-policy=none policy.applied-disposition=none policy.evaluated-disposition=none (p=none,sp=none,d=none,d.eval=none) policy.policy-from=p header.from=sdf.org; spf=pass smtp.mailfrom=adr@SDF.ORG smtp.helo=mx.sdf.org; x-internal-arc=fail (as.1.topicbox.com=pass, ams.1.topicbox.com=fail (message has been altered)) (Message modified while forwarding at Topicbox) X-Received-Authentication-Results: tb-mx1.topicbox.com; arc=none (no signatures found); bimi=skipped (DMARC Policy is not at enforcement); dkim=none (no signatures found); dmarc=pass policy.published-domain-policy=none policy.published-subdomain-policy=none policy.applied-disposition=none policy.evaluated-disposition=none (p=none,sp=none,d=none,d.eval=none) policy.policy-from=p header.from=sdf.org; iprev=pass smtp.remote-ip=205.166.94.24 (mx.sdf.org); spf=pass smtp.mailfrom=adr@SDF.ORG smtp.helo=mx.sdf.org; x-aligned-from=pass (Address match); x-me-sender=none; x-ptr=pass smtp.helo=mx.sdf.org policy.ptr=mx.sdf.org; x-return-mx=pass header.domain=sdf.org policy.is_org=yes (MX Records found: mx.sdf.org); x-return-mx=pass smtp.domain=sdf.org policy.is_org=yes (MX Records found: mx.sdf.org); x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES256-GCM-SHA384 smtp.bits=256/256; x-vs=clean score=0 state=0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=9fans.net; h=date:from :to:subject:in-reply-to:message-id:references:mime-version :content-type:list-help:list-id:list-post:list-subscribe :reply-to:content-transfer-encoding:list-unsubscribe; s=dkim-1; t=1656440948; x=1656527348; bh=ldCtgKl6GGPrDEIZXHJIo5jyde+jr5Xi 0VsAf1AcfyU=; b=UmuLXvdnODb9IXVQucuwTjjJNLdXZs9ivHQbDDph8u0KW0mE uGHgqrciwzoygqmSKlhlJhj047m1UKzRaKQuV9TmrgRCSqAX2t4Vhvidn9/ACeef yXo5v0IPcSKg8bNMwf1oNY/QwgyJO1UDVwphdVgCJUaBnN5L8qsrfXp6WG4= Received: from tb-mx1.topicbox.com (localhost.local [127.0.0.1]) by tb-mx1.topicbox.com (Postfix) with ESMTP id 9D1CE15C089A for <9fans@9fans.net>; Tue, 28 Jun 2022 14:28:54 -0400 (EDT) (envelope-from adr@SDF.ORG) Received: from tb-mx1.topicbox.com (localhost [127.0.0.1]) by tb-mx1.topicbox.com (Authentication Milter) with ESMTP id A02F0EA1C05; Tue, 28 Jun 2022 14:28:54 -0400 ARC-Seal: i=1; a=rsa-sha256; cv=none; d=topicbox.com; s=arcseal; t= 1656440934; b=xLTUjps6cKt0MhisagJIBP9IpKcqySxe8avEs5yzUmzcVmFyuy Lghd7QuQBB8UwDsS+94V63WqSdAmQd7lE72MRCLTrbg7qal25BbcMfDStn+NuQRO HNhsYJMuMYby4XfC+fj6fCT+pxRh7Sm1IicKvYxkzzB6Z/t2RCucshKYgEQSakdL hZZu0+mcb4nLbwoE1229JN9LytE0X5E5HCu0GAtKo8XDePB9Z1WktxuWQ18kxN54 pxLZMc4X3ZlGM2AsWdS+/TTAzre7/VEemFULD7r1VR8s9ndSN6RAQhP++zTQG1EU V9io6mGAqnJhAEUrjEyL8QonyHXsJc5Z598w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= topicbox.com; h=date:from:to:subject:in-reply-to:message-id :references:mime-version:content-type; s=arcseal; t=1656440934; bh=yaCgM7N9Zc6zEy0N+AGDiApge8sVQtNAgMZ4+e5/hts=; b=Puvpt5vWUHOj d3pndZUi9drR+BMyYCcTEYGVz17VaNPGgDQodkavyz4qSRi2O6Of2TN9Ip+X99L8 4Etsepun0fFiL6Snnp7IPYPmeqIi4KS45Y/vdYhJ6lOFP+oDxNS4AAV0VwZRRtKv At+Iy0NCW0T2nDTvruIXaeJXwEmyksqDwLeeYRRtOO6xnnMtDQNBIAV7GZbUV2IJ OI7pI6ggrFm9SdCOuDJH7MZxI1ats+RRwaUUUsqvZ4qqx60EkIlPj5Twvg4k5wDC PWNgbof9pXm1GIETqcF4068CZfAF7Iz4F3aG96DxSJkpL0OzxiNhRVsEo9+KETzc FaRJ7sCX2w== ARC-Authentication-Results: i=1; tb-mx1.topicbox.com; arc=none (no signatures found); bimi=skipped (DMARC Policy is not at enforcement); dkim=none (no signatures found); dmarc=pass policy.published-domain-policy=none policy.published-subdomain-policy=none policy.applied-disposition=none policy.evaluated-disposition=none (p=none,sp=none,d=none,d.eval=none) policy.policy-from=p header.from=sdf.org; iprev=pass smtp.remote-ip=205.166.94.24 (mx.sdf.org); spf=pass smtp.mailfrom=adr@SDF.ORG smtp.helo=mx.sdf.org; x-aligned-from=pass (Address match); x-me-sender=none; x-ptr=pass smtp.helo=mx.sdf.org policy.ptr=mx.sdf.org; x-return-mx=pass header.domain=sdf.org policy.is_org=yes (MX Records found: mx.sdf.org); x-return-mx=pass smtp.domain=sdf.org policy.is_org=yes (MX Records found: mx.sdf.org); x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES256-GCM-SHA384 smtp.bits=256/256; x-vs=clean score=0 state=0 X-ME-VSCause: gggruggvucftvghtrhhoucdtuddrgedvfedrudegjedguddvhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fujgfkfhggtgesthdtredttddtvdenucfhrhhomheprggurhcuoegrughrsefufffhrdfq tffiqeenucggtffrrghtthgvrhhnpeekhedtveffheevhfdtgefhhefgveelvedujeetje dtheduvdefvdekgedtfffhffenucfkphepvddthedrudeiiedrleegrddvgedpvddthedr udeiiedrleegrdduieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvg htpedvtdehrdduieeirdelgedrvdegpdhhvghlohepmhigrdhsughfrdhorhhgpdhmrghi lhhfrhhomhepoegrughrsefufffhrdfqtffiqe X-ME-VSScore: 0 X-ME-VSCategory: clean Received-SPF: pass (sdf.org: 205.166.94.24 is authorized to use 'adr@SDF.ORG' in 'mfrom' identity (mechanism 'ip4:205.166.94.0/24' matched)) receiver=tb-mx1.topicbox.com; identity=mailfrom; envelope-from="adr@SDF.ORG"; helo=mx.sdf.org; client-ip=205.166.94.24 Received: from mx.sdf.org (mx.sdf.org [205.166.94.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by tb-mx1.topicbox.com (Postfix) with ESMTPS for <9fans@9fans.net>; Tue, 28 Jun 2022 14:28:53 -0400 (EDT) (envelope-from adr@SDF.ORG) Received: from sdf.org (IDENT:adr@sdf.org [205.166.94.16]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 25SISqIu002439 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO) for <9fans@9fans.net>; Tue, 28 Jun 2022 18:28:53 GMT Received: from localhost (adr@localhost) by sdf.org (8.15.2/8.12.8/Submit) with ESMTP id 25SISqKN027131 for <9fans@9fans.net>; Tue, 28 Jun 2022 18:28:52 GMT Date: Tue, 28 Jun 2022 18:28:52 +0000 (UTC) From: adr To: 9fans <9fans@9fans.net> Subject: Re: [9fans] syscall silently kill processes In-Reply-To: <4cb721cd-616d-8f86-e499-ad9da41c40a2@SDF.ORG> Message-ID: <54f93087-4342-a54c-7635-1fd134755f7f@SDF.ORG> References: <2b857fe-c6df-a6b8-40ec-566c85b7377d@SDF.ORG> <770c427561d318ba28f7f4fb820577398f49fef8.camel@gmail.com> <7d9742ec-51f0-34d1-714-6f308975da34@SDF.ORG> <9307b24-ba87-e7b0-342e-71bf83835ed@SDF.ORG> <87cff69b-4b82-8466-a34f-13c7eda24fc9@SDF.ORG> <4cb721cd-616d-8f86-e499-ad9da41c40a2@SDF.ORG> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Topicbox-Policy-Reasoning: allow: sender is a member Topicbox-Message-UUID: 2d28fb4a-f710-11ec-a3b9-a5c5687d6590 Archived-At: =?UTF-8?B?PGh0dHBzOi8vOWZhbnMudG9waWNib3guY29tL2dyb3Vwcy85?= =?UTF-8?B?ZmFucy9UZmE2ODIzMDQ4YWQ5MGEyMS1NYzFiYzZlODdhYTUzZGU4NGUyZjIw?= =?UTF-8?B?NzI5Pg==?= List-Help: List-Id: "9fans" <9fans.9fans.net> List-Post: List-Software: Topicbox v0 List-Subscribe: Precedence: list Reply-To: 9fans <9fans@9fans.net> Content-Transfer-Encoding: quoted-printable List-Unsubscribe: , Topicbox-Delivery-ID: 2:9fans:437d30aa-c441-11e9-8a57-d036212d11b0:522be890-2105-11eb-b15e-8d699134e1fa:Mc1bc6e87aa53de84e2f20729:1:ixqV67xGcJ-Rd4pYmvA4jqCQL8qCx0AI63WyzxepOFY On Tue, 28 Jun 2022, adr wrote: > This just evade going through the arrays twice. For the current > value of NFN it doesn't make too much a difference, note that this > structures are locked. It just was hurting my eyes. Sorry for the noise, bad patch. --- /tmp/main.c +++ /sys/src/libthread/main.c @@ -28,6 +28,10 @@ _qlockinit(_threadrendezvous); _sysfatal =3D _threadsysfatal; __assert =3D _threadassert; + onnote =3D mallocz(PPCHUNK*sizeof(uintptr), 1); + if(!onnote) + sysfatal("Malloc of size %d failed: %r", PPCHUNK*sizeof(uin= tptr)); + onnotesize =3D PPCHUNK; notify(_threadnote); if(mainstacksize =3D=3D 0) mainstacksize =3D 8*1024; --- /tmp/note.c +++ /sys/src/libthread/note.c @@ -5,7 +5,6 @@ int _threadnopasser; -#define NFN 33 #define ERRLEN 48 typedef struct Note Note; struct Note @@ -17,62 +16,161 @@ static Note notes[128]; static Note *enotes =3D notes+nelem(notes); -static int (*onnote[NFN])(void*, char*); -static int onnotepid[NFN]; +Onnote **onnote; +int onnotesize; +static int (*onnoteall[NFN])(void*, char*); static Lock onnotelock; int threadnotify(int (*f)(void*, char*), int in) { - int i, topid; - int (*from)(void*, char*), (*to)(void*, char*); + int i, j, n; - if(in){ - from =3D nil; - to =3D f; - topid =3D _threadgetproc()->pid; - }else{ - from =3D f; - to =3D nil; - topid =3D 0; - } lock(&onnotelock); - for(i=3D0; i -1) + onnoteall[n] =3D f; + unlock(&onnotelock); + return n>-1; + } + + /* remove note for all processes */ + if(in =3D=3D -1){ + for(i=3D0; ipid=3D=3D_threadg= etproc()->pid){ + for(j=3D0; jfn[j] =3D=3D f){ + onnote[i]->fn[j] =3D 0; + break; + } + } + unlock(&onnotelock); + return jpid=3D=3D_threadgetproc()->pid) + break; + + /* process has already a slot */ + if(i < onnotesize){ + n =3D -1; + for(j=3D0; jfn[j] =3D=3D f){ + unlock(&onnotelock); + return 1; + } + if(onnote[i]->fn[j]=3D=3Dnil && n=3D=3D-1) + n =3D j; + } + if(n > -1) + onnote[i]->fn[n] =3D f; + unlock(&onnotelock); + return n>-1; +=20 + } + + for(i=3D0; ipid =3D _threadgetproc()->pid; + onnote[i]->fn[0] =3D f; + unlock(&onnotelock); + return 1; +} + +void +threadcancelnotes(int pid) +{ + int i; + + lock(&onnotelock); + for(i=3D0; ipid=3D=3Dpid){ + free(onnote[i]); + onnote[i] =3D nil; break; } unlock(&onnotelock); - return ipending) return; p->pending =3D 0; + all =3D j =3D 0; for(n=3Dnotes; nproc =3D=3D p){ - strcpy(s, n->s); - n->proc =3D nil; - unlock(&n->inuse); - - for(i=3D0; ipid || (fn =3D onnote= [i])=3D=3Dnil) - continue; - if((*fn)(v, s)) - break; + for(i=3D0; is)){ + all =3D 1; + break; + } + if(!all){ + for(i=3D0; ipid=3D= =3Dp->pid){ + for(j=3D0; jf= n[j]) + if((*f)(v, = n->s)) + bre= ak; + break; + } } - if(i=3D=3DNFN){ - _threaddebug(DBGNOTE, "Unhandled note %s, p= roc %p", n->s, p); + if(!all && (i=3D=3Donnotesize || j=3D=3DNFN)){ + _threaddebug(DBGNOTE, "Unhandled note %s, p= roc %p\n", n->s, p); if(v !=3D nil) noted(NDFLT); else if(strncmp(n->s, "sys:", 4)=3D=3D0) @@ -79,6 +177,8 @@ abort(); threadexitsall(n->s); } + n->proc =3D nil; + unlock(&n->inuse); } } } @@ -94,7 +194,7 @@ noted(NDFLT); if(_threadexitsallstatus){ - _threaddebug(DBGNOTE, "Threadexitsallstatus =3D '%s'", _thr= eadexitsallstatus); + _threaddebug(DBGNOTE, "Threadexitsallstatus =3D '%s'\n", _t= hreadexitsallstatus); _exits(_threadexitsallstatus); } --- /tmp/sched.c +++ /sys/src/libthread/sched.c @@ -157,6 +157,7 @@ t =3D runthread(p); if(t =3D=3D nil){ _threaddebug(DBGSCHED, "all threads gone; exiting"); + threadcancelnotes(p->pid); unlinkproc(p); _schedexit(p); /* frees proc */ } --- /tmp/thread.h +++ /sys/include/thread.h @@ -97,6 +97,7 @@ void threadkillgrp(int); /* kill threads in group */ void threadmain(int argc, char *argv[]); int threadnotify(int (*f)(void*, char*), int in); +void threadcancelnotes(int pid); int threadid(void); int threadpid(int); int threadsetgrp(int); /* set thread group, return old */ --- /tmp/threadimpl.h +++ /sys/src/libthread/threadimpl.h @@ -192,3 +192,15 @@ #define _threaddebug(flag, ...) if((_threaddebuglevel&(flag))=3D=3D= 0){}else _threadprint(__VA_ARGS__) #define ioproc_arg(io, type) (va_arg((io)->arg, type)) + +#define PPCHUNK 100 +#define NFN 33 +typedef struct Onnote Onnote; +struct Onnote +{ + int pid; + int (*fn[NFN])(void*, char*); +}; +extern Onnote **onnote; +extern int onnotesize; +void _threadnote(void*, char*); ------------------------------------------ 9fans: 9fans Permalink: https://9fans.topicbox.com/groups/9fans/Tfa6823048ad90a21-Mc1bc6= e87aa53de84e2f20729 Delivery options: https://9fans.topicbox.com/groups/9fans/subscription