ref: c8d87b22d50a17b8832019a93b9293fef19fbd02
parent: e2978c785ad240e254849ff944294e62651414e3
author: Jacob Moody <moody@posixcafe.org>
date: Tue Jan 9 14:59:34 EST 2024
ip/torrent: only register note handler in one proc Before the note handler would be set on all procs which would cause all threads to try and kill all other threads on exit. This also adds some procsetname() calls which makes it easier to see exactly what is going on in something like pstree(1).
--- a/sys/src/cmd/ip/torrent.c
+++ b/sys/src/cmd/ip/torrent.c
@@ -391,6 +391,7 @@
int workpiece, workoffset;
int i, o, l, x, n;
+ procsetname("peer %s: %s", addr, incoming ? "incoming" : "outgoing");
if(debug) fprint(2, "peer %s: %s connected\n", addr, incoming ? "incoming" : "outgoing");
for(i=0; i<2; i++){
@@ -617,6 +618,8 @@
}
if(rfork(RFFDG|RFPROC|RFMEM))
return;
+
+ procsetname("server");
for(;;){
if((lfd = listen(adir, ldir)) < 0){
fprint(2, "listen: %r");
@@ -699,6 +702,7 @@
if(d == nil)
exits(0);
addr = d->str;
+ procsetname("client %s", addr);
if(debug) fprint(2, "client %s\n", addr);
if((fd = dial(addr, nil, nil, nil)) >= 0){
peer(fd, 0, addr);
@@ -758,6 +762,7 @@
if(rfork(RFPROC|RFMEM))
return;
w0 = w;
+ procsetname("webseed %s %s", w->str, f->name);
Retry:
if(debug) fprint(2, "webseed %s %s\n", w->str, f->name);
s = strrchr(w->str, '/');
@@ -842,6 +847,7 @@
if(rfork(RFPROC|RFMEM))
return;
+ procsetname("webtracker %s", url);
if(debug) fprint(2, "webtracker %s\n", url);
event = "&event=started";
@@ -925,6 +931,7 @@
return;
if(rfork(RFPROC|RFMEM))
return;
+ procsetname("udptracker %s", addr);
if(debug) fprint(2, "udptracker %s\n", addr);
event = 1;
@@ -1369,7 +1376,6 @@
sysfatal("create: %r");
srand(truerand());
- atnotify(catch, 1);
switch(i = rfork(RFPROC|RFMEM|RFNOTEG)){
case -1:
sysfatal("fork: %r");
@@ -1388,6 +1394,7 @@
break;
default:
killgroup = i;
+ atnotify(catch, 1);
do {
sleep(1000);
if(pflag)