operation-codes list:

master only:
0 - spawn new slave executor, and create new fifo for communication, print fifo base name to stdout
0 <name> - optional parameter to define fifo name manually
253 <1\0> - perform slaves shutdown. if param set to 1 - slaves will terminate it's chils with configured signals, sigkill otherwise. do not perform self shutdown when param is 1 - just send termination command to slaves.
250 - return orphaned process count
249 - return slave executors count
240 - source checksum verification

slave only:

command mode:
1 <absolute path inside sandbox to exec> - set binary name to start
2 <param> - append new argument to arguments list
3 <name> <value> - add env variable to set
4 <name> - add env variable name to remove
5 <signal num> - signal to send to the child processes to gracefully terminate (by default - sigterm or sighup(for pty mode) will be used)
6 <workdir> - workdir that will be set when starting user binary
7 <0/1> - set child_only_terminate mode, when gracefully terminating (command 253 with arg 1) by user-defined signal (set by command 5)
8 <0/1> - set or unset orphans terminate mode. if set to 1 - master will terminate all orphans if no slave executors running (after timeout)
253 <1\0> - perform shutdown. if param is 1 - user signal send to child processes (set by command 5), sigkill otherwise
100 - start process in captive mode without new session startup (and pty allocation). detach from sandboxed session on commander-binary termination
101 - same as 100, but start in detached mode instead, commander will exit after successfull start
103 - start process in captive mode, try to terminate sandbox-session on commander-binary termination (via sigterm, sighup, sigint signals).
200 - start process in captive mode, perform pty-device allocation and create new session. useful for shells inside sandbox. detach from sandboxed session on commander-binary termination
201 - same as 200, but start in detached mode instead, commander will exit after successfull start
203 - start process in captive mode, try to terminate sandbox-session on commander-binary termination (via sigterm, sighup, sigint signals).
240 - request source checksum verification (provide commmander's source checksum value to master, and receive verification result)

control mode:
102 - reattach to detached session started with command 101
202 - reattach to detached session started with command 201
253 <1\0> - perform shutdown. if param is 1 - user signal send to child processes (set by command 5), sigkill otherwise
[internal command] 252 - update terminal window size, used only in 200\201 mode. used automatically when needed
[internal command] 251 - commander detach
[internal command] 150 - send captured user input or program output data.




TODO list:

- commander: sandboxed app stdout\stderr logging - add append and overwrite logging modes for commander, add smart interval for fdatasync to avoid spamming filesystem-journal when receiving small chunks of data with high frequency.
- commander: handle ctrl+c, hup and term to perform safe detach from active executor connection (this logic already there, it is now activated by sigusr2 signal).
- executor: check that orphaned processes with valid session id is properly tracked as childs when tracked child process is still running.
- executor: in addition to logfile enable\disable startup parameter, add parameter to enable\disable executor's own stdout\stderr logging (now this behavior controlled by master\slave mode selection paremeter)
- executor: when stdout logging is disabled - redirect standard fds (0,1,2) to /dev/null, so, they do not expose external bwrap output redirection to logfile
- executor: use seccomp to lockdown slave executor after it spawn user binary

Longterm goals:

- more robust communication protocol, add some logic to cleanup "stale" data left inside fifo-buffer when client silently gone offline,
  or some garbage is written (for now - all communication commands signed with hash, all data encoded within "packets" with corresponding headers)
- async\multi-threaded data read\write from\to child process
- proper timings calculation for io-operations, use non-blocking mode for communication pipe, or check available data size before read.
...
- PROFIT!
