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 25106 invoked from network); 28 Jun 2022 18:20:14 -0000 Received: from tb-ob20.topicbox.com (173.228.157.66) by inbox.vuxu.org with ESMTPUTF8; 28 Jun 2022 18:20:14 -0000 Received: from tb-mx0.topicbox.com (tb-mx0.nyi.icgroup.com [10.90.30.73]) by tb-ob20.topicbox.com (Postfix) with ESMTP id 467173568A for ; Tue, 28 Jun 2022 14:20:12 -0400 (EDT) (envelope-from bounce.mMfa798aacff90ff14ee10e8cf.r522be890-2105-11eb-b15e-8d699134e1fa@9fans.bounce.topicbox.com) Received: by tb-mx0.topicbox.com (Postfix, from userid 1132) id EBE102A61483; Tue, 28 Jun 2022 14:20:11 -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=1656440411; bh=ZAPegMMRsP6znkMI pje8y50l9FvGkMDM9govLEUeJ74=; b=hcERpotDn4aUmoGnVcxkPBH047/LLklL g2pHj52cFcgi4peSBMZErxoXbeJq0xj5Ncw55sU0COoCD/WYF+4ULUfje7NQzNF5 b6OzvTuFQhNjZLMs31haJxotLznCaerE1J4Dt38NxryZpSJhXvQM++cJQCprcfEp poDMVr12onE= ARC-Seal: i=2; a=rsa-sha256; cv=pass; d=topicbox.com; s=sysmsg-1; t= 1656440411; b=U2YoJwxJa7YWZMUpOaw1JvhRHfwfJgmuyGf/bPotm1r0wFIwaJ APNIE2JuO7rj4bL8rRB4LIyHHmuOPmg0Q+KJbobeYt+ECOna5BegBWbA4f0LSiId FtznqfeRxM06qsTJbLExOmJHvf1XOl85T6HSYB8tJuw+S3W0AiofX0dMc= 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-mx0.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=1656440411; x=1656526811; bh=LUNiELN7lYsUEE8lerTR/l05a26qS4EU Sjt3YA5wrP4=; b=EEL/tkwAD3SOvyxsbTnLzmzrJNI5cfj0B9eALPGiFHZ2w5U1 wFuYgji0ScbWxJgj0NOEM5Fmmc9g5B7mPm0+tgCZu3gSIEumJ9ZS2ZQFr/rrjNKF FWupDLu9ixzUkLtituiNI5VXRVE/no9rdeQyeG7Dhmt5u5B4Sw3fDvoLFnA= Received: from tb-mx0.topicbox.com (localhost.local [127.0.0.1]) by tb-mx0.topicbox.com (Postfix) with ESMTP id E90692A6106C for <9fans@9fans.net>; Tue, 28 Jun 2022 14:19:55 -0400 (EDT) (envelope-from adr@SDF.ORG) Received: from tb-mx0.topicbox.com (localhost [127.0.0.1]) by tb-mx0.topicbox.com (Authentication Milter) with ESMTP id 8AE6B6DD8D6; Tue, 28 Jun 2022 14:19:55 -0400 ARC-Seal: i=1; a=rsa-sha256; cv=none; d=topicbox.com; s=arcseal; t= 1656440395; b=C9r9E5Efc+SoGTArj6ilKI/nu7rF58zQFI3xoCkTN9aFCgM85W zUwTKTM0ZSbD1cxfSiWhbiPJNzflp9aJKbwZHoBYfVEZeHqzOq4Rp8kSEs9QU/34 no041Wwag6xLjlWVCO4TY4L+f1C/B/eurEL+bLfiuSWy8eNLz3DJl1wL+17QX1aR LovlvFgdTZn3Cs3Yw4q07qzu7EiwhgUnO6D1eqZ3n04GIdhEv9YyeR64Qjbxko9a 9RrAE1yXljmK5RXGL++E2oBqrdgGwz8914dunoBSfWZnXxpMvBwpTQC5lkYKUXvW RMZb836fWOWnL2cAMgUPhGOjWueDU0D7FZ8g== 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=1656440395; bh=g6Jehi/e8G4sObnBWC2gq+catv/IEAA1/Au17uWHJyo=; b=v1uod7B/01st wDV+CZYVF7C7Tknvf3dgm8rvWHESFm2mbUbwb1KQFQP98LKTq7z4hPrazdNFA6vq qSByQVNyTEyuMcmcDyATDoMdndFfb3QpfYVGF927nsydA9ewPqhW3uoZyiyEFMDY 6HObgoJ+0x9nAaUI2ujfWybJmuBDl6S/5HFdkMnfAOhiUDELZ0gDVvuvMCjpeRFq kTbR6vIuFABwN4cEHSRiyRiFh+BQGzgC+FAg58o44WCeiZ3GABmy/Z1Kj7UEb20K onL5nmPILYm145nLyPbSyTghlNert+Uox6s6CdubknXxiMM3QpjeFTtI7ehpyiyr z4P3n8pw2w== ARC-Authentication-Results: i=1; tb-mx0.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: gggruggvucftvghtrhhoucdtuddrgedvfedrudegjedguddvfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fujgfkfhggtgesthdtredttddtvdenucfhrhhomheprggurhcuoegrughrsefufffhrdfq tffiqeenucggtffrrghtthgvrhhnpeduhfejkeevveeltddutdejheefleduvdeuvdelff efueeukefgtdefhfehffelhfenucffohhmrghinhepnhhothgvrdgtrghtnecukfhppedv tdehrdduieeirdelgedrvdegpddvtdehrdduieeirdelgedrudeinecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehinhgvthepvddthedrudeiiedrleegrddvgedphhgv lhhopehmgidrshgufhdrohhrghdpmhgrihhlfhhrohhmpeeorggurhesufffhfdrqfftif eq 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-mx0.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-mx0.topicbox.com (Postfix) with ESMTPS for <9fans@9fans.net>; Tue, 28 Jun 2022 14:19:55 -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 25SIJrwG017735 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO) for <9fans@9fans.net>; Tue, 28 Jun 2022 18:19:54 GMT Received: from localhost (adr@localhost) by sdf.org (8.15.2/8.12.8/Submit) with ESMTP id 25SIJrpu029571 for <9fans@9fans.net>; Tue, 28 Jun 2022 18:19:53 GMT Date: Tue, 28 Jun 2022 18:19:53 +0000 (UTC) From: adr To: 9fans <9fans@9fans.net> Subject: Re: [9fans] syscall silently kill processes In-Reply-To: <87cff69b-4b82-8466-a34f-13c7eda24fc9@SDF.ORG> Message-ID: <4cb721cd-616d-8f86-e499-ad9da41c40a2@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> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Topicbox-Policy-Reasoning: allow: sender is a member Topicbox-Message-UUID: ec3c0358-f70e-11ec-a9d5-bcd26a737682 Archived-At: =?UTF-8?B?PGh0dHBzOi8vOWZhbnMudG9waWNib3guY29tL2dyb3Vwcy85?= =?UTF-8?B?ZmFucy9UZmE2ODIzMDQ4YWQ5MGEyMS1NZmE3OThhYWNmZjkwZmYxNGVlMTBl?= =?UTF-8?B?OGNmPg==?= 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:Mfa798aacff90ff14ee10e8cf:1:3Z5Zin2lDvt9mEk2EPVHs8T1qN-9jL6mZETfDevLQd4 On Tue, 28 Jun 2022, adr wrote: >=20 > Andrey, if you want to use different note handlers per process (with a big > number of processes) using libthread, this may be helpful. > > The idea is this: > > An array of handlers for all processes which can be changed by all proces= ses. > When a note is received by a process, this array takes priority. > > An array of pointers to structures of the type > > struct Onnote > { > int pid; > int (*fn[NFN])(void*, char*); > }; > > initially of size PPCHUNK (I set it to 100, experiment with that), > but it can grow if necessary (but not shrink, I think this would > be overkilling). > > These structures are allocated the first time a process record a > handler and freed when the process exits (or by calling > threadcancelnotes(), note that this function can free other processes' > function handlers, maybe should be better to make some restrictions) > > The use of "in" in threadnotify(int (*f)(void*, char*), int in) is: > > in > 0 : set the handler for the calling process. > in =3D=3D 0 : clear the handler for the calling process. > in =3D=3D -1 : clear the handler for all processes (except those who has > registered it already for themselves). > in < -1 : set the handler for all processes. > > There is no use of threadnotify with "in < 0" in /sys/src, so nothing is= =20 > broken. > > As you are using 9front and they are serving their sources with > 9p, here is a diff to their sources. I haven't compiled it in > 9front, though. Note that if you want to compile the system with > this changes, you have to eliminate the copy of note.c at > /sys/src/cmd/execnet (it seems that note.c was added afterwards as > I thought). > > I haven't test it too much, this has been more like a time-destroyer > pastime. 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. --- /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=3D nil) + 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-Mfa798= aacff90ff14ee10e8cf Delivery options: https://9fans.topicbox.com/groups/9fans/subscription