interplane.Get Omega
Read in your language

omega-harness

Agent skills for operating, encoding and communicating in Omega (.om) and the AIEN repositories

Brought by drakestapleton

branch main Branches Tags History

omega-harness / examples / execenv.om

79 lines · 1640 bytes Raw Blame History
1note execenv (keyword 233, omega-mv #1074): execprog with a private environment packet.
2note The parent re-executes /proc/self/exe with argv [/proc/self/exe, "child"] and an environment
3note of exactly one record GREETING=hi, in a forked child. The child prints its whole environment;
4note the parent exits with the child's exit status. A missing program returns -2 (ENOENT).
5om2
6text self "/proc/self/exe"
7text cmode "child"
8text greet "GREETING=hi"
9text missing "/nonexistent/omega-execenv-example"
10global argv uchar 256
11global envp uchar 64
12global buf uchar 256
13global status uchar 4
14
15fn arec pos ulong s view uchar * to ulong
16put argv pos uchar and len s 255
17put argv add pos 1 uchar shr len s 8
18for i ulong len s
19put argv add add pos 2 i get s i
20end
21ret add add pos 2 len s
22end
23
24fn erec pos ulong s view uchar * to ulong
25put envp pos uchar and len s 255
26put envp add pos 1 uchar shr len s 8
27for i ulong len s
28put envp add add pos 2 i get s i
29end
30ret add add pos 2 len s
31end
32
33fn child to int
34c = ulong envcnt
35for i ulong c
36n = envread i buf 0 len buf
37if le n 0
38ret 2
39end
40put buf n 10
41w = write 1 buf 0 add ulong n 1
42end
43if ne c 1
44ret 1
45end
46ret 0
47end
48
49fn main to int
50n = argcnt
51if eq n 2
52ret child
53end
54put argv 0 2
55put argv 1 0
56an = arec 2 self
57an = arec an cmode
58put envp 0 1
59put envp 1 0
60en = erec 2 greet
61pid = fork
62if eq pid 0
63r = execenv argv 0 an envp 0 en
64exit 3
65end
66w = waitpid int pid status 0 len status 0
67if ne w pid
68ret 4
69end
70note A missing program: execenv returns -2 (ENOENT) to the caller.
71put argv 0 1
72put argv 1 0
73mn = arec 2 missing
74r = execenv argv 0 mn envp 0 en
75if ne r neg long 2
76ret 5
77end
78ret int get status 1
79end