aboutsummaryrefslogtreecommitdiff
path: root/elymas/lib
diff options
context:
space:
mode:
Diffstat (limited to 'elymas/lib')
-rw-r--r--elymas/lib/sys.ey91
-rw-r--r--elymas/lib/sys/linux.ey2
2 files changed, 72 insertions, 21 deletions
diff --git a/elymas/lib/sys.ey b/elymas/lib/sys.ey
index 85d5c5f..a373475 100644
--- a/elymas/lib/sys.ey
+++ b/elymas/lib/sys.ey
@@ -1,23 +1,72 @@
-# abstract system io layer
-
-{ # ==directory
- "\0" cat 511 sys .linux .mkdir 0 neq { ??io.dir.mk } rep
-} /mkdir sys .deff
-
-{ # ==directory
- "\0" cat sys .linux .ORDONLY sys .linux .ODIRECTORY bor 0 sys .linux .open ==fd
- fd 0 lt { ??io.dir.ls.open } {
- [ [ { fd sys .linux .getdents64 _ 0 lt { ??io.dir.ls.getdents } rep } { _ len dearray } loop ] { .dname } each ]
- fd sys .linux .close 0 lt { ??io.dir.ls.close } rep
- } ? *
-} /readdir sys .deff
-
-{ # ==directory
- sys .readdir { 0 -01 * 0 "." * neq } grep
-} /ls sys .deff
-
-{
- "\0" cat -01 "\0" cat -01 sys .linux .rename 0 neq { ??io.rename } rep
-} /rename sys .deff
+# abstract system layer
+
+<
+ sys .linux "+" via
+
+ { # ==directory
+ "\0" cat 511 +mkdir 0 neq { ??io.dir.mk } rep
+ } /mkdir sys .deff
+
+ { # ==directory
+ "\0" cat +ORDONLY +ODIRECTORY bor 0 +open ==fd
+ fd 0 lt { ??io.dir.ls.open } {
+ [ [ { fd +getdents64 _ 0 lt { ??io.dir.ls.getdents } rep } { _ len dearray } loop ] { .dname } each ]
+ fd +close 0 lt { ??io.dir.ls.close } rep
+ } ? *
+ } /readdir sys .deff
+
+ { # ==directory
+ sys .readdir { 0 -01 * 0 "." * neq } grep
+ } /ls sys .deff
+
+ {
+ "\0" cat -01 "\0" cat -01 +rename 0 neq { ??io.rename } rep
+ } /rename sys .deff
+
+ # 0 -> an array of strings determining argv
+ # 1 -> path to executable
+ {
+ -01 "\0" cat -01 [ ] +execve ??proc.exec
+ } /exec sys .deff
+
+ # 0 -> a shell command
+ { ==cmd
+ "/bin/sh" [ "sh" "-c" cmd "\0" cat ] [ ] +execve ??proc.exec
+ } /shell sys .deff
+
+ # 0 -> function to execute in the child
+ # 0 <- scope describing child, available members:
+ # .pid
+ # .wait (will return some status code) # TODO decompose this according to man 2 waitpid
+ # <SIG> .kill
+ # .in - child stdin
+ # .out - child stdout
+ # .err - child stderr (maybe inject some polling on this one per default)
+ #
+ # Example:
+ # { "wget 'http://drahflow.name/' -O -" sys .shell } sys .spawn _ |dump -01 .out .eachLine .wait --
+ { =*f
+ +pipe 0 neq { ??proc.spawn.pipe } rep ==readA ==writeA
+ +pipe 0 neq { ??proc.spawn.pipe } rep ==readB ==writeB
+ +pipe 0 neq { ??proc.spawn.pipe } rep ==readC ==writeC
+ +fork _ ==child not {
+ [ writeA readB readC 0 1 2 ] { +close } '*0.0 --
+ [ readA writeB writeC ] [ 0 1 2 ] { +dup2 } '*00.0 --
+ f 0 sys .exit
+ } rep
+ child 1 neg eq { ??proc.spawn.fork } {
+ readA +close { ??proc.spawn.close } rep
+ writeB +close { ??proc.spawn.close } rep
+ writeC +close { ??proc.spawn.close } rep
+ child < ==pid
+ { pid 0 +waitpid -- } =*wait
+ { pid -01 +kill -- } =*kill
+ writeA sys .fdToFile _ .writeonly ==in
+ readB sys .fdToFile _ .readonly ==out
+ readC sys .fdToFile _ .readonly ==err
+ >
+ } ? *
+ } /spawn sys .deff
+> --
# vim: syn=elymas
diff --git a/elymas/lib/sys/linux.ey b/elymas/lib/sys/linux.ey
index 682dc61..b683afd 100644
--- a/elymas/lib/sys/linux.ey
+++ b/elymas/lib/sys/linux.ey
@@ -685,6 +685,8 @@
} /reuseAddr deffd
> /setsockopt defvd
+ # 0 -> options
+ # 1 -> pid to wait for
# 0 <- raw return value
# 1 <- returned status
{ ==options ==pid