summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appl/tiny/broke.b70
-rw-r--r--appl/tiny/mkfile2
-rw-r--r--dis/tiny/broke.disbin0 -> 1136 bytes
-rw-r--r--man/1/tiny55
4 files changed, 124 insertions, 3 deletions
diff --git a/appl/tiny/broke.b b/appl/tiny/broke.b
new file mode 100644
index 00000000..0ffb0fec
--- /dev/null
+++ b/appl/tiny/broke.b
@@ -0,0 +1,70 @@
+implement Broke;
+
+include "sys.m";
+ sys: Sys;
+include "draw.m";
+
+Broke: module
+{
+ init: fn(nil: ref Draw->Context, args: list of string);
+};
+
+init(nil: ref Draw->Context, nil: list of string)
+{
+ sys = load Sys Sys->PATH;
+ fd := sys->open("/prog", Sys->OREAD);
+ if(fd == nil)
+ err(sys->sprint("can't open /prog: %r"));
+ killed := "";
+ for(;;){
+ (n, dir) := sys->dirread(fd);
+ if(n <= 0){
+ if(n < 0)
+ err(sys->sprint("error reading /prog: %r"));
+ break;
+ }
+ for(i := 0; i < n; i++)
+ if(isbroken(dir[i].name) && kill(dir[i].name))
+ killed += sys->sprint(" %s", dir[i].name);
+ }
+ if(killed != nil)
+ sys->print("%s\n", killed);
+}
+
+isbroken(pid: string): int
+{
+ statf := "/prog/" + pid + "/status";
+ fd := sys->open(statf, Sys->OREAD);
+ if (fd == nil)
+ return 0;
+ buf := array[256] of byte;
+ n := sys->read(fd, buf, len buf);
+ if (n < 0) { # process died or is exiting
+ # sys->fprint(stderr(), "broke: can't read %s: %r\n", statf);
+ return 0;
+ }
+ (nf, l) := sys->tokenize(string buf[0:n], " ");
+ return nf >= 5 && hd tl tl tl tl l == "broken";
+}
+
+kill(pid: string): int
+{
+ ctl := "/prog/" + pid + "/ctl";
+ fd := sys->open(ctl, sys->OWRITE);
+ if(fd == nil || sys->fprint(fd, "kill") < 0){
+ sys->fprint(stderr(), "broke: can't kill %s: %r\n", pid); # but press on
+ return 0;
+ }
+ return 1;
+}
+
+err(s: string)
+{
+ sys->fprint(sys->fildes(2), "broke: %s\n", s);
+ raise "fail:error";
+}
+
+stderr(): ref Sys->FD
+{
+ return sys->fildes(2);
+}
diff --git a/appl/tiny/mkfile b/appl/tiny/mkfile
index 8ffc3d60..023160b6 100644
--- a/appl/tiny/mkfile
+++ b/appl/tiny/mkfile
@@ -1,6 +1,8 @@
<../../mkconfig
TARG=\
+ broke.dis\
+ kill.dis\
rm.dis\
sh.dis\
diff --git a/dis/tiny/broke.dis b/dis/tiny/broke.dis
new file mode 100644
index 00000000..da1689b8
--- /dev/null
+++ b/dis/tiny/broke.dis
Binary files differ
diff --git a/man/1/tiny b/man/1/tiny
index 29072dfd..1afa1131 100644
--- a/man/1/tiny
+++ b/man/1/tiny
@@ -1,6 +1,6 @@
.TH TINY 1
.SH NAME
-tiny: sh, rm \- reduced command line interface to the Inferno system
+tiny: sh, broke, kill, rm \- reduced command line interface to the Inferno system
.SH SYNOPSIS
.B tiny/sh
[
@@ -11,6 +11,19 @@ tiny: sh, rm \- reduced command line interface to the Inferno system
.I file
]
.PP
+.B tiny/broke
+.PP
+.B tiny/kill
+[
+.B -g
+]
+[
+.I pid ...
+]
+[
+.I module ...
+]
+.PP
.B tiny/rm
[
.I file
@@ -24,8 +37,9 @@ They are provided for use on devices where a certain level of functionality
might be useful for configuration or maintenance (or development), but
device constraints are such as to make the use of the normal, fleshier versions
of the commands unattractive.
-For example, the Dis object files are typically 5 times smaller (or better) than the
+For example, the Dis object files can be as much as 5 times smaller (or better) than the
mainstream alternatives.
+They are also useful when initially porting the system.
They live in the directory
.BR /dis/tiny ,
but could be placed in the
@@ -34,6 +48,37 @@ of a small device
(eg, via
.IR root (3))ยท
.PP
+.I Broke
+kills broken processes and prints their process IDs.
+.PP
+.I Kill
+terminates each process (for a numeric
+process ID
+.IR pid )
+or
+process running a given
+.I module
+(for a non-numeric module name),
+by writing a
+.L kill
+message to the corresponding process's control file
+in
+.IR prog (3).
+The
+.B -g
+option causes
+.I kill
+to write a
+.L killgrp
+message instead, killing all processes in the given process's process group
+(see
+.IR sys-pctl (2)).
+Processes running a
+.I module
+are identified by their
+.L status
+file, and the process ID of each such process is printed on standard output.
+.PP
.I Rm
removes files and empty directories, subject to the permission rules given in
.IR rm (1).
@@ -196,9 +241,13 @@ and
.SH FILES
.BI /prog/ n /wait
.SH SOURCE
-.B /appl/tiny/sh.b
+.B /appl/tiny/broke.b
+.br
+.B /appl/tiny/kill.b
.br
.B /appl/tiny/rm.b
+.br
+.B /appl/tiny/sh.b
.SH "SEE ALSO"
.IR bind (1),
.IR sh (1),