diff options
author | Alex Musolino <alex@musolino.id.au> | 2020-12-15 20:55:41 +1030 |
---|---|---|
committer | Alex Musolino <alex@musolino.id.au> | 2020-12-15 20:55:41 +1030 |
commit | 3749e92cdb88a157f99c0709a264bd508603be9b (patch) | |
tree | 49ce703965ba4114490729c5aeabd9ba120d9b78 /sys/src/libthread/kill.c | |
parent | 404c901f299c4d93cb159a3c44c2977a25408319 (diff) | |
parent | 32291b52bcbd6976051acff1692b571e321ac859 (diff) |
merge
Diffstat (limited to 'sys/src/libthread/kill.c')
-rw-r--r-- | sys/src/libthread/kill.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/sys/src/libthread/kill.c b/sys/src/libthread/kill.c index 9160df016..e7292437c 100644 --- a/sys/src/libthread/kill.c +++ b/sys/src/libthread/kill.c @@ -76,24 +76,31 @@ threadint(int id) threadxxx(id, 0); } -static void -tinterrupt(Proc *p, Thread *t) +static int +writeprocctl(int pid, char *ctl) { - char buf[64]; + char buf[32]; int fd; + snprint(buf, sizeof(buf), "/proc/%lud/ctl", (ulong)pid); + fd = open(buf, OWRITE|OCEXEC); + if(fd < 0) + return -1; + if(write(fd, ctl, strlen(ctl)) < 0){ + close(fd); + return -1; + } + close(fd); + return 0; +} + +static void +tinterrupt(Proc *p, Thread *t) +{ switch(t->state){ case Running: - snprint(buf, sizeof(buf), "/proc/%d/ctl", p->pid); - fd = open(buf, OWRITE|OCEXEC); - if(fd >= 0){ - if(write(fd, "interrupt", 9) == 9){ - close(fd); - break; - } - close(fd); - } - postnote(PNPROC, p->pid, "threadint"); + if(writeprocctl(p->pid, "interrupt") < 0) + postnote(PNPROC, p->pid, "threadint"); break; case Rendezvous: _threadflagrendez(t); |