omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / node / release.om
| 1 | note seed/node/release.om -- omnode-release, the Omega Node release lifecycle (DRA-292): |
| 2 | note build, serve, start, health, stop, restore, unserve, snapshot and rollback of one |
| 3 | note coding workflow. OM-2 program; compose after om/tls/sha2.om (SHA-256): |
| 4 | note { printf 'om2\n'; cat om/tls/sha2.om seed/node/release.om; } | seed/out/omc > build/node/release |
| 5 | note Every program it starts is compiled from .om (the six of build, and omc) except the |
| 6 | note own-model server OLLM, which serve starts as given. Children get an empty environment |
| 7 | note (execprog), descriptors 0..2 only, and no PATH search. |
| 8 | note release build OUT |
| 9 | note Compose and compile infer, tool, code-main, code-test, op and fake-serve into OUT with |
| 10 | note seed/out/omc; one BUILD_OK name bytes sha256 (or BUILD_FAIL name message) line each, |
| 11 | note then omc sha256. Run from the checkout root: the units and omc are found there. |
| 12 | note release serve STATE PORT OLLM VERB CK MERGES |
| 13 | note Start OLLM VERB PORT CK MERGES; STATE/serve.pid, serve.log; wait for its PORT line. |
| 14 | note release start STATE BIN OMC PORT VIEW |
| 15 | note Write STATE/release.env and start code-main on STATE (root/, work/, journal/, |
| 16 | note objs.txt: one objective per line); node.pid; append run.out and run.err; wait until |
| 17 | note the view answers. Refuses (exit 3) while node.pid is alive. |
| 18 | note release health STATE the model's GET /health and the view; 0 when both answer |
| 19 | note release stop STATE pause (op 1), wait until nothing runs or is in review (900 s), |
| 20 | note SIGTERM; view-at-stop.json |
| 21 | note release restore STATE start again on the same journal, resume (op 2) when paused |
| 22 | note release unserve STATE SIGTERM the model server |
| 23 | note release snapshot STATE SNAP copy STATE/root, work, journal into SNAP (new) |
| 24 | note release rollback STATE SNAP replace STATE/root, work, journal with SNAP's copies |
| 25 | note Errors: one line "release: MESSAGE" on stderr; exit 2 usage or never 18091, 3 a process |
| 26 | note in the wrong state, 1 any other failure. |
| 27 | |
| 28 | text rlpre "release: " |
| 29 | text rlnl "\n" |
| 30 | text rlsp " " |
| 31 | text rlnull "/dev/null" |
| 32 | text rlenvf "release.env" |
| 33 | text rlnpid "node.pid" |
| 34 | text rlspid "serve.pid" |
| 35 | text rlslog "serve.log" |
| 36 | text rlvtmp "view.tmp" |
| 37 | text rlvjs "view.json" |
| 38 | text rlvst "view-at-stop.json" |
| 39 | text rlack "ack.json" |
| 40 | text rlhj "health.json" |
| 41 | text rlrout "run.out" |
| 42 | text rlrerr "run.err" |
| 43 | text rlobjs "objs.txt" |
| 44 | text rljour "journal" |
| 45 | text rlwork "work" |
| 46 | text rlroot "root" |
| 47 | text rlkbin "BIN" |
| 48 | text rlkomc "OMC" |
| 49 | text rlkport "PORT" |
| 50 | text rlkview "VIEW" |
| 51 | text rlxop "/op" |
| 52 | text rlxcm "/code-main" |
| 53 | text rlxinf "/infer" |
| 54 | text rlxtool "/tool" |
| 55 | text rlxroot "/root" |
| 56 | text rlxwork "/work" |
| 57 | text rlxjour "/journal" |
| 58 | text rlwview "view" |
| 59 | text rlwcmd "cmd" |
| 60 | text rlwhlth "health" |
| 61 | text rlzero "0" |
| 62 | text rlone "1" |
| 63 | text rltwo "2" |
| 64 | text rl18091 "18091" |
| 65 | text rlinv "\"invalid\"" |
| 66 | text rlrunp "RUN " |
| 67 | text rlportp "PORT " |
| 68 | text rlhex "0123456789abcdef" |
| 69 | text rlom2 "om2\n" |
| 70 | text rlomc "seed/out/omc" |
| 71 | text rlxom ".om" |
| 72 | text rlxtmp ".tmp" |
| 73 | text rlxcerr ".cerr" |
| 74 | text rlfinc "incarnation" |
| 75 | text rlfver "version" |
| 76 | text rlfjsq "journal_seq" |
| 77 | text rlfpau "paused" |
| 78 | text rlfrun "running" |
| 79 | text rlfrev "review" |
| 80 | text rlfjf "journal_failed" |
| 81 | text rlfwait "waiting" |
| 82 | text rlfrdy "ready" |
| 83 | text rlusage "usage: release build OUT | serve STATE PORT OLLM VERB CK MERGES | start STATE BIN OMC PORT VIEW | health|stop|restore|unserve STATE | snapshot|rollback STATE SNAP" |
| 84 | text rlusv "usage: serve STATE PORT OLLM VERB CK MERGES" |
| 85 | text rlust "usage: start STATE BIN OMC PORT VIEW" |
| 86 | text rlusr "usage: snapshot|rollback STATE SNAP" |
| 87 | text rlm18 "never 18091" |
| 88 | text rlmlong "an argument is over 4096 bytes" |
| 89 | text rlmpk "the arguments are over 4096 bytes or 64 words" |
| 90 | text rlmno "no " |
| 91 | text rlmnoe "/release.env (start first)" |
| 92 | text rlmnrun "the node is running (node.pid " |
| 93 | text rlmsrun "a server is running (serve.pid " |
| 94 | text rlmcl ")" |
| 95 | text rlmnex "the node exited: " |
| 96 | text rlmv30 "the view did not answer in 30 s" |
| 97 | text rlmv2 "the view did not answer twice" |
| 98 | text rlmsex "server exited: " |
| 99 | text rlmp300 "no PORT line in 300 s" |
| 100 | text rlmnnr "the node is not running" |
| 101 | text rlmpau "the pause was not committed" |
| 102 | text rlmnxs "the node exited while stopping" |
| 103 | text rlm900 "jobs still running after 900 s; not stopped" |
| 104 | text rlmres "the resume was not committed" |
| 105 | text rlmvno "the view does not answer" |
| 106 | text rlmvlag "the view did not reach the resume's journal_seq in 5 s" |
| 107 | text rlmnos "no server running" |
| 108 | text rlmunk "unknown command " |
| 109 | text rlmdir "cannot create " |
| 110 | text rlmcomp "cannot compose " |
| 111 | text rlmroot "run build from the checkout root (no seed/out/omc)" |
| 112 | text rlmbin "BIN is not a directory: " |
| 113 | text rlmobj "cannot read objs.txt in " |
| 114 | text rlmcp "cannot copy " |
| 115 | text rlmrm "cannot remove " |
| 116 | text rlmerr " (error " |
| 117 | text rlmsnap "no snapshot directory " |
| 118 | text rlmspn "cannot start " |
| 119 | text rlobok "BUILD_OK " |
| 120 | text rlobf "BUILD_FAIL " |
| 121 | text rloomc "omc " |
| 122 | text rlosv1 "serve pid " |
| 123 | text rlosv2 " port " |
| 124 | text rlosv3 " ollm " |
| 125 | text rlosv4 " verb " |
| 126 | text rlond1 "node pid " |
| 127 | text rlond2 " view " |
| 128 | text rlond3 " incarnation " |
| 129 | text rlond4 " version " |
| 130 | text rlohm "model " |
| 131 | text rlohn " node " |
| 132 | text rlohr " running " |
| 133 | text rlohj " journal_failed " |
| 134 | text rlost "stopped pid " |
| 135 | text rlosw " waiting " |
| 136 | text rlosy " ready " |
| 137 | text rlors "restored incarnation " |
| 138 | text rlorp " paused " |
| 139 | text rlous1 "server " |
| 140 | text rlous2 " stopped" |
| 141 | text rlosn "snapshot " |
| 142 | text rlorb "rollback " |
| 143 | text rlocf " files " |
| 144 | text rlocd " dirs " |
| 145 | text rlocl " links " |
| 146 | text rlocb " bytes " |
| 147 | text rlcbld "build" |
| 148 | text rlcsrv "serve" |
| 149 | text rlcsta "start" |
| 150 | text rlchlt "health" |
| 151 | text rlcstp "stop" |
| 152 | text rlcres "restore" |
| 153 | text rlcuns "unserve" |
| 154 | text rlcsnp "snapshot" |
| 155 | text rlcrb "rollback" |
| 156 | text rlbn1 "infer" |
| 157 | text rlbl1 "seed/json/json.om seed/json/jsonw.om seed/net/http.om seed/net/notls.om seed/node/infer.om" |
| 158 | text rlbn2 "tool" |
| 159 | text rlbl2 "seed/agent/path.om seed/node/gram.om seed/node/tool.om" |
| 160 | text rlbn3 "code-main" |
| 161 | text rlbl3 "seed/net/http.om seed/net/notls.om seed/node/transport.om seed/node/pool.om seed/node/super.om seed/node/sched.om seed/authority/action.om seed/node/journal.om seed/node/auth.om seed/node/view.om seed/node/gram.om seed/node/code.om seed/node/code-main.om" |
| 162 | text rlbn4 "code-test" |
| 163 | text rlbl4 "seed/net/http.om seed/net/notls.om seed/node/transport.om seed/node/pool.om seed/node/super.om seed/node/sched.om seed/authority/action.om seed/node/journal.om seed/node/auth.om seed/node/view.om seed/node/gram.om seed/node/code.om seed/node/code-test.om" |
| 164 | text rlbn5 "op" |
| 165 | text rlbl5 "seed/net/http.om seed/net/notls.om seed/node/op.om" |
| 166 | text rlbn6 "fake-serve" |
| 167 | text rlbl6 "seed/net/http.om seed/net/notls.om seed/node/tests/fake-serve.om" |
| 168 | |
| 169 | note The tree copy and removal work on two path stacks: rlsrc[0, sl) the source and |
| 170 | note rldst[0, dl) the destination; a level appends "/name" and passes the longer length. |
| 171 | note rlcn counts files, directories, links and bytes copied. |
| 172 | global rlsrc uchar 4096 |
| 173 | global rldst uchar 4096 |
| 174 | global rlcn ulong 4 |
| 175 | |
| 176 | note ======== bytes |
| 177 | |
| 178 | note Append a to o at p; the new end. |
| 179 | fn rl_cat o edit uchar * p ulong a view uchar * to ulong |
| 180 | n = len a |
| 181 | for i ulong n |
| 182 | put o add p i get a i |
| 183 | end |
| 184 | ret add p n |
| 185 | end |
| 186 | |
| 187 | fn rl_dec o edit uchar * p ulong v ulong to ulong |
| 188 | d = new uchar 20 0 |
| 189 | k = ulong 20 |
| 190 | x = v |
| 191 | for it ulong 20 |
| 192 | k = sub k 1 |
| 193 | put d k uchar add rem x 10 48 |
| 194 | x = div x 10 |
| 195 | if eq x 0 |
| 196 | break |
| 197 | end |
| 198 | end |
| 199 | ret rl_cat o p part d k sub 20 k |
| 200 | end |
| 201 | |
| 202 | note Two decimal digits of v (0..99). |
| 203 | fn rl_d2 o edit uchar * p ulong v ulong to ulong |
| 204 | put o p uchar add div v 10 48 |
| 205 | put o add p 1 uchar add rem v 10 48 |
| 206 | ret add p 2 |
| 207 | end |
| 208 | |
| 209 | fn rl_eq a view uchar * b view uchar * to bool |
| 210 | if ne len a len b |
| 211 | ret false |
| 212 | end |
| 213 | for i ulong len a |
| 214 | if ne get a i get b i |
| 215 | ret false |
| 216 | end |
| 217 | end |
| 218 | ret true |
| 219 | end |
| 220 | |
| 221 | note The first offset of nd in b, or -1. |
| 222 | fn rl_find b view uchar * nd view uchar * to long |
| 223 | n = len b |
| 224 | m = len nd |
| 225 | if gt m n |
| 226 | ret -1 |
| 227 | end |
| 228 | for i ulong add sub n m 1 |
| 229 | k = ulong 0 |
| 230 | while lt k m bound 4096 |
| 231 | if ne get b add i k get nd k |
| 232 | break |
| 233 | end |
| 234 | k = add k 1 |
| 235 | end |
| 236 | if eq k m |
| 237 | ret long i |
| 238 | end |
| 239 | end |
| 240 | ret -1 |
| 241 | end |
| 242 | |
| 243 | note The offset of the first newline in b at or after s, or len b. |
| 244 | fn rl_eol b view uchar * s ulong to ulong |
| 245 | e = s |
| 246 | n = len b |
| 247 | while lt e n bound 16777216 |
| 248 | if eq get b e 10 |
| 249 | ret e |
| 250 | end |
| 251 | e = add e 1 |
| 252 | end |
| 253 | ret n |
| 254 | end |
| 255 | |
| 256 | note b[0, n) without its trailing newlines: the new n. |
| 257 | fn rl_trim b view uchar * n ulong to ulong |
| 258 | m = n |
| 259 | while gt m 0 bound 16777216 |
| 260 | if ne get b sub m 1 10 |
| 261 | ret m |
| 262 | end |
| 263 | m = sub m 1 |
| 264 | end |
| 265 | ret 0 |
| 266 | end |
| 267 | |
| 268 | note ======== output and errors |
| 269 | |
| 270 | fn rl_wall fd int a view uchar * to long |
| 271 | n = len a |
| 272 | p = ulong 0 |
| 273 | while lt p n bound 16777216 |
| 274 | k = write fd a p sub n p |
| 275 | if le k 0 |
| 276 | ret -1 |
| 277 | end |
| 278 | p = add p ulong k |
| 279 | end |
| 280 | ret 0 |
| 281 | end |
| 282 | |
| 283 | fn rl_die m view uchar * c int to void |
| 284 | b = new uchar 16384 0 |
| 285 | p = rl_cat b 0 rlpre |
| 286 | p = rl_cat b p m |
| 287 | p = rl_cat b p rlnl |
| 288 | x = rl_wall 2 part b 0 p |
| 289 | exit c |
| 290 | end |
| 291 | |
| 292 | note die with a message followed by argument i. |
| 293 | fn rl_diea m view uchar * i ulong c int to void |
| 294 | b = new uchar 8192 0 |
| 295 | p = rl_cat b 0 m |
| 296 | q = argread i b p sub 8192 p |
| 297 | if gt q 0 |
| 298 | p = add p ulong q |
| 299 | end |
| 300 | rl_die part b 0 p c |
| 301 | end |
| 302 | |
| 303 | note Argument i into o; its length (over the capacity dies, exit 2). |
| 304 | fn rl_arg i ulong o edit uchar * to ulong |
| 305 | n = argread i o 0 len o |
| 306 | if lt n 0 |
| 307 | rl_die rlmlong 2 |
| 308 | end |
| 309 | ret ulong n |
| 310 | end |
| 311 | |
| 312 | note The path STATE/nm into o; its length. |
| 313 | fn rl_stp o edit uchar * nm view uchar * to ulong |
| 314 | n = rl_arg 2 o |
| 315 | put o n 47 |
| 316 | ret rl_cat o add n 1 nm |
| 317 | end |
| 318 | |
| 319 | note ======== files |
| 320 | |
| 321 | fn rl_close fd long to void |
| 322 | if ge fd 0 |
| 323 | x = fclose int fd |
| 324 | end |
| 325 | end |
| 326 | |
| 327 | fn rl_open pa view uchar * fl int md int to long |
| 328 | ret fopen pa 0 len pa fl md |
| 329 | end |
| 330 | |
| 331 | fn rl_stopen nm view uchar * fl int md int to long |
| 332 | pa = new uchar 4096 0 |
| 333 | n = rl_stp pa nm |
| 334 | ret fopen pa 0 n fl md |
| 335 | end |
| 336 | |
| 337 | note Read pa into b (at most len b bytes); the length or a negative error. |
| 338 | fn rl_slurp pa view uchar * b edit uchar * to long |
| 339 | fd = fopen pa 0 len pa 524288 0 |
| 340 | if lt fd 0 |
| 341 | ret fd |
| 342 | end |
| 343 | n = ulong 0 |
| 344 | c = len b |
| 345 | while lt n c bound 16777216 |
| 346 | k = read int fd b n sub c n |
| 347 | if le k 0 |
| 348 | break |
| 349 | end |
| 350 | n = add n ulong k |
| 351 | end |
| 352 | rl_close fd |
| 353 | ret long n |
| 354 | end |
| 355 | |
| 356 | fn rl_stsl nm view uchar * b edit uchar * to long |
| 357 | pa = new uchar 4096 0 |
| 358 | n = rl_stp pa nm |
| 359 | ret rl_slurp part pa 0 n b |
| 360 | end |
| 361 | |
| 362 | note Append the content of pa without its trailing newlines (as sh $(cat pa)) to o at p, |
| 363 | note at most up to 1024 bytes before the end of o. |
| 364 | fn rl_fcat pa view uchar * o edit uchar * p ulong to ulong |
| 365 | b = new uchar 65536 0 |
| 366 | n = rl_slurp pa b |
| 367 | if le n 0 |
| 368 | ret p |
| 369 | end |
| 370 | m = rl_trim part b 0 ulong n ulong n |
| 371 | r = sub sub len o p 1024 |
| 372 | if gt m r |
| 373 | m = r |
| 374 | end |
| 375 | ret rl_cat o p part b 0 m |
| 376 | end |
| 377 | |
| 378 | fn rl_stfcat nm view uchar * o edit uchar * p ulong to ulong |
| 379 | pa = new uchar 4096 0 |
| 380 | n = rl_stp pa nm |
| 381 | ret rl_fcat part pa 0 n o p |
| 382 | end |
| 383 | |
| 384 | note Copy the whole file pa to descriptor fd; 0 or a negative error. |
| 385 | fn rl_fout pa view uchar * fd int to long |
| 386 | b = new uchar 65536 0 |
| 387 | fi = fopen pa 0 len pa 524288 0 |
| 388 | if lt fi 0 |
| 389 | ret fi |
| 390 | end |
| 391 | r = long 0 |
| 392 | for it ulong 16777216 |
| 393 | k = read int fi b 0 65536 |
| 394 | if le k 0 |
| 395 | r = k |
| 396 | break |
| 397 | end |
| 398 | x = rl_wall fd part b 0 ulong k |
| 399 | end |
| 400 | rl_close fi |
| 401 | ret r |
| 402 | end |
| 403 | |
| 404 | fn rl_stout nm view uchar * to void |
| 405 | pa = new uchar 4096 0 |
| 406 | n = rl_stp pa nm |
| 407 | r = rl_fout part pa 0 n 1 |
| 408 | end |
| 409 | |
| 410 | note true when STATE/nm holds nd. |
| 411 | fn rl_sthas nm view uchar * nd view uchar * to bool |
| 412 | b = new uchar 262144 0 |
| 413 | n = rl_stsl nm b |
| 414 | if le n 0 |
| 415 | ret false |
| 416 | end |
| 417 | ret ge rl_find part b 0 ulong n nd 0 |
| 418 | end |
| 419 | |
| 420 | note Lines of pa that begin with px (grep -c '^px'). |
| 421 | fn rl_cntpre pa view uchar * px view uchar * to ulong |
| 422 | b = new uchar 65536 0 |
| 423 | fd = fopen pa 0 len pa 524288 0 |
| 424 | if lt fd 0 |
| 425 | ret 0 |
| 426 | end |
| 427 | c = ulong 0 |
| 428 | s = ulong 0 |
| 429 | m = len px |
| 430 | for it ulong 16777216 |
| 431 | k = read int fd b 0 65536 |
| 432 | if le k 0 |
| 433 | break |
| 434 | end |
| 435 | for i ulong ulong k |
| 436 | h = get b i |
| 437 | if eq h 10 |
| 438 | s = 0 |
| 439 | else |
| 440 | if lt s m |
| 441 | if eq h get px s |
| 442 | s = add s 1 |
| 443 | if eq s m |
| 444 | c = add c 1 |
| 445 | s = add m 1 |
| 446 | end |
| 447 | else |
| 448 | s = add m 1 |
| 449 | end |
| 450 | end |
| 451 | end |
| 452 | end |
| 453 | end |
| 454 | rl_close fd |
| 455 | ret c |
| 456 | end |
| 457 | |
| 458 | note The last three lines of pa (tail -3, read from its last 4000 bytes) without trailing |
| 459 | note newlines, appended to o at p. |
| 460 | fn rl_tail3 pa view uchar * o edit uchar * p ulong to ulong |
| 461 | b = new uchar 4096 0 |
| 462 | fd = fopen pa 0 len pa 524288 0 |
| 463 | if lt fd 0 |
| 464 | ret p |
| 465 | end |
| 466 | z = fseek int fd 0 2 |
| 467 | if gt z 4000 |
| 468 | z = fseek int fd sub z 4000 0 |
| 469 | else |
| 470 | z = fseek int fd 0 0 |
| 471 | end |
| 472 | n = ulong 0 |
| 473 | while lt n 4000 bound 4001 |
| 474 | k = read int fd b n sub 4000 n |
| 475 | if le k 0 |
| 476 | break |
| 477 | end |
| 478 | n = add n ulong k |
| 479 | end |
| 480 | rl_close fd |
| 481 | e = rl_trim part b 0 n n |
| 482 | s = rl_l3 part b 0 e e |
| 483 | ret rl_cat o p part b s sub e s |
| 484 | end |
| 485 | |
| 486 | note The start of the last three lines of b[0, e). |
| 487 | fn rl_l3 b view uchar * e ulong to ulong |
| 488 | k = ulong 0 |
| 489 | i = e |
| 490 | while gt i 0 bound 4097 |
| 491 | i = sub i 1 |
| 492 | if eq get b i 10 |
| 493 | k = add k 1 |
| 494 | if eq k 3 |
| 495 | ret add i 1 |
| 496 | end |
| 497 | end |
| 498 | end |
| 499 | ret 0 |
| 500 | end |
| 501 | |
| 502 | fn rl_isdir pa view uchar * to bool |
| 503 | st = new uchar 128 0 |
| 504 | r = stat pa 0 len pa st 0 128 |
| 505 | if lt r 0 |
| 506 | ret false |
| 507 | end |
| 508 | ret eq and or ulong get st 16 shl ulong get st 17 8 61440 16384 |
| 509 | end |
| 510 | |
| 511 | fn rl_size pa view uchar * to ulong |
| 512 | st = new uchar 128 0 |
| 513 | r = stat pa 0 len pa st 0 128 |
| 514 | if lt r 0 |
| 515 | ret 0 |
| 516 | end |
| 517 | v = ulong 0 |
| 518 | for i ulong 8 |
| 519 | v = or v shl ulong get st add 48 i mul 8 i |
| 520 | end |
| 521 | ret v |
| 522 | end |
| 523 | |
| 524 | note mkdir -p pa: 0 when pa is a directory afterwards. |
| 525 | fn rl_mkp pa view uchar * to long |
| 526 | b = new uchar 4096 0 |
| 527 | n = len pa |
| 528 | for i ulong n |
| 529 | c = get pa i |
| 530 | if eq c 47 |
| 531 | if gt i 0 |
| 532 | r = makedir b 0 i 511 |
| 533 | end |
| 534 | end |
| 535 | put b i c |
| 536 | end |
| 537 | if eq n 0 |
| 538 | ret -2 |
| 539 | end |
| 540 | r = makedir b 0 n 511 |
| 541 | if rl_isdir pa |
| 542 | ret 0 |
| 543 | end |
| 544 | ret -20 |
| 545 | end |
| 546 | |
| 547 | fn rl_stmkp nm view uchar * to void |
| 548 | pa = new uchar 4096 0 |
| 549 | n = rl_stp pa nm |
| 550 | r = rl_mkp part pa 0 n |
| 551 | if lt r 0 |
| 552 | rl_die rlmdir 1 |
| 553 | end |
| 554 | end |
| 555 | |
| 556 | note Rename STATE/a over STATE/b. |
| 557 | fn rl_stmv a view uchar * b view uchar * to long |
| 558 | pk = new uchar 4096 0 |
| 559 | pa = new uchar 4096 0 |
| 560 | put pk 0 2 |
| 561 | n = rl_stp pa a |
| 562 | p = rl_pk pk 2 part pa 0 n |
| 563 | n = rl_stp pa b |
| 564 | p = rl_pk pk p part pa 0 n |
| 565 | ret renames pk 0 p 0 |
| 566 | end |
| 567 | |
| 568 | note Write the decimal v and a newline to STATE/nm (echo v > nm). |
| 569 | fn rl_wpid nm view uchar * v long to void |
| 570 | o = new uchar 32 0 |
| 571 | fd = rl_stopen nm 524865 438 |
| 572 | if lt fd 0 |
| 573 | ret |
| 574 | end |
| 575 | p = rl_dec o 0 ulong v |
| 576 | p = rl_cat o p rlnl |
| 577 | x = rl_wall int fd part o 0 p |
| 578 | rl_close fd |
| 579 | end |
| 580 | |
| 581 | note ======== SHA-256 (om/tls/sha2.om) |
| 582 | |
| 583 | note The lowercase hex SHA-256 of the file pa appended to o at p; nothing when it cannot |
| 584 | note be opened. |
| 585 | fn rl_sha pa view uchar * o edit uchar * p ulong to ulong |
| 586 | c = new ulong 40 0 |
| 587 | b = new uchar 65536 0 |
| 588 | d = new uchar 32 0 |
| 589 | fd = fopen pa 0 len pa 524288 0 |
| 590 | if lt fd 0 |
| 591 | ret p |
| 592 | end |
| 593 | sha256_init c |
| 594 | for it ulong 16777216 |
| 595 | k = read int fd b 0 65536 |
| 596 | if le k 0 |
| 597 | break |
| 598 | end |
| 599 | sha256_update c part b 0 ulong k |
| 600 | end |
| 601 | rl_close fd |
| 602 | sha256_final c d |
| 603 | ret rl_hexd d o p |
| 604 | end |
| 605 | |
| 606 | note The 32 bytes of d as lowercase hex appended to o at p. |
| 607 | fn rl_hexd d view uchar 32 o edit uchar * p ulong to ulong |
| 608 | for i ulong 32 |
| 609 | q = add p mul i 2 |
| 610 | v = ulong get d i |
| 611 | put o q get rlhex shr v 4 |
| 612 | put o add q 1 get rlhex and v 15 |
| 613 | end |
| 614 | ret add p 64 |
| 615 | end |
| 616 | |
| 617 | note ======== processes |
| 618 | |
| 619 | note Append the packed record a to pk at p; the new end (over 4096 bytes dies). |
| 620 | fn rl_pk pk edit uchar 4096 p ulong a view uchar * to ulong |
| 621 | n = len a |
| 622 | if gt add add p 2 n 4096 |
| 623 | rl_die rlmpk 2 |
| 624 | end |
| 625 | put pk p uchar and n 255 |
| 626 | put pk add p 1 uchar shr n 8 |
| 627 | for i ulong n |
| 628 | put pk add add p 2 i get a i |
| 629 | end |
| 630 | ret add add p 2 n |
| 631 | end |
| 632 | |
| 633 | fn rl_pkc pk edit uchar 4096 c ulong to void |
| 634 | if gt c 64 |
| 635 | rl_die rlmpk 2 |
| 636 | end |
| 637 | put pk 0 uchar c |
| 638 | put pk 1 0 |
| 639 | end |
| 640 | |
| 641 | note Append argument i as a record. |
| 642 | fn rl_pka pk edit uchar 4096 p ulong i ulong to ulong |
| 643 | b = new uchar 4096 0 |
| 644 | n = rl_arg i b |
| 645 | ret rl_pk pk p part b 0 n |
| 646 | end |
| 647 | |
| 648 | note Append the release.env value of key followed by suffix sf as one record. |
| 649 | fn rl_pke pk edit uchar 4096 p ulong key view uchar * sf view uchar * to ulong |
| 650 | b = new uchar 8192 0 |
| 651 | n = rl_env key b 0 |
| 652 | n = rl_cat b n sf |
| 653 | ret rl_pk pk p part b 0 n |
| 654 | end |
| 655 | |
| 656 | note Append the release.env value of key as a record. |
| 657 | fn rl_pkv pk edit uchar 4096 p ulong key view uchar * to ulong |
| 658 | b = new uchar 8192 0 |
| 659 | n = rl_env key b 0 |
| 660 | ret rl_pk pk p part b 0 n |
| 661 | end |
| 662 | |
| 663 | note Append STATE followed by sf as a record. |
| 664 | fn rl_pks pk edit uchar 4096 p ulong sf view uchar * to ulong |
| 665 | b = new uchar 8192 0 |
| 666 | n = rl_arg 2 b |
| 667 | n = rl_cat b n sf |
| 668 | ret rl_pk pk p part b 0 n |
| 669 | end |
| 670 | |
| 671 | note Start pk with descriptors fi, fo, fe as 0, 1, 2 (negative: keep ours); the PID. |
| 672 | fn rl_spawn pk view uchar * fi long fo long fe long to long |
| 673 | pid = fork |
| 674 | if eq pid 0 |
| 675 | r = long 0 |
| 676 | if ge fi 0 |
| 677 | r = dupfd int fi 0 0 |
| 678 | end |
| 679 | if ge fo 0 |
| 680 | r = dupfd int fo 1 0 |
| 681 | end |
| 682 | if ge fe 0 |
| 683 | r = dupfd int fe 2 0 |
| 684 | end |
| 685 | r = execprog pk 0 len pk |
| 686 | exit 127 |
| 687 | end |
| 688 | ret pid |
| 689 | end |
| 690 | |
| 691 | note Wait for pid: its exit status, 128 + the signal, or 127 when the wait failed. |
| 692 | fn rl_wait pid long to int |
| 693 | ws = new uchar 4 0 |
| 694 | g = waitpid int pid ws 0 4 0 |
| 695 | if lt g 0 |
| 696 | ret 127 |
| 697 | end |
| 698 | s = or ulong get ws 0 shl ulong get ws 1 8 |
| 699 | if ne and s 127 0 |
| 700 | ret int add 128 and s 127 |
| 701 | end |
| 702 | ret int and shr s 8 255 |
| 703 | end |
| 704 | |
| 705 | fn rl_run pk view uchar * fi long fo long fe long to int |
| 706 | pid = rl_spawn pk fi fo fe |
| 707 | if lt pid 0 |
| 708 | ret 127 |
| 709 | end |
| 710 | ret rl_wait pid |
| 711 | end |
| 712 | |
| 713 | note A process with this PID exists (a child of ours that ended is reaped first). |
| 714 | fn rl_alivp pid long to bool |
| 715 | ws = new uchar 4 0 |
| 716 | if le pid 0 |
| 717 | ret false |
| 718 | end |
| 719 | g = waitpid int pid ws 0 4 1 |
| 720 | if eq g pid |
| 721 | ret false |
| 722 | end |
| 723 | ret ge killpid int pid 0 0 |
| 724 | end |
| 725 | |
| 726 | note The PID in STATE/nm, or -1. |
| 727 | fn rl_pidf nm view uchar * to long |
| 728 | b = new uchar 64 0 |
| 729 | n = rl_stsl nm b |
| 730 | if le n 0 |
| 731 | ret -1 |
| 732 | end |
| 733 | m = rl_trim part b 0 ulong n ulong n |
| 734 | if eq m 0 |
| 735 | ret -1 |
| 736 | end |
| 737 | v = long 0 |
| 738 | for i ulong m |
| 739 | c = get b i |
| 740 | if or lt c 48 gt c 57 |
| 741 | ret -1 |
| 742 | end |
| 743 | if gt v 100000000000 |
| 744 | ret -1 |
| 745 | end |
| 746 | v = add mul v 10 long sub c 48 |
| 747 | end |
| 748 | ret v |
| 749 | end |
| 750 | |
| 751 | fn rl_alive nm view uchar * to bool |
| 752 | ret rl_alivp rl_pidf nm |
| 753 | end |
| 754 | |
| 755 | note Wait until pid is gone, polling every 0.1 s. |
| 756 | fn rl_gone pid long to void |
| 757 | while rl_alivp pid bound 9223372036854775807 |
| 758 | x = sleepns 100000000 |
| 759 | end |
| 760 | end |
| 761 | |
| 762 | note ======== release.env and the view |
| 763 | |
| 764 | note The value of key in STATE/release.env appended to o at p. |
| 765 | fn rl_env key view uchar * o edit uchar * p ulong to ulong |
| 766 | b = new uchar 16384 0 |
| 767 | n = rl_stsl rlenvf b |
| 768 | if le n 0 |
| 769 | ret p |
| 770 | end |
| 771 | m = len key |
| 772 | s = ulong 0 |
| 773 | while lt s ulong n bound 16384 |
| 774 | e = rl_eol part b 0 ulong n s |
| 775 | if gt sub e s m |
| 776 | if eq get b add s m 61 |
| 777 | if rl_eq part b s m key |
| 778 | q = add add s m 1 |
| 779 | ret rl_cat o p part b q sub e q |
| 780 | end |
| 781 | end |
| 782 | end |
| 783 | s = add e 1 |
| 784 | end |
| 785 | ret p |
| 786 | end |
| 787 | |
| 788 | fn rl_envck to void |
| 789 | b = new uchar 4096 0 |
| 790 | pa = new uchar 4096 0 |
| 791 | n = rl_stp pa rlenvf |
| 792 | fd = fopen pa 0 n 524288 0 |
| 793 | if lt fd 0 |
| 794 | p = rl_cat b 0 rlmno |
| 795 | q = rl_arg 2 part b p sub 4096 p |
| 796 | p = add p q |
| 797 | p = rl_cat b p rlmnoe |
| 798 | rl_die part b 0 p 2 |
| 799 | end |
| 800 | rl_close fd |
| 801 | end |
| 802 | |
| 803 | note The digits after the first "nm": in STATE/fl appended to o at p (grep -o, head -1). |
| 804 | fn rl_vf fl view uchar * nm view uchar * o edit uchar 8192 p ulong to ulong |
| 805 | b = new uchar 262144 0 |
| 806 | n = rl_stsl fl b |
| 807 | if le n 0 |
| 808 | ret p |
| 809 | end |
| 810 | ret rl_vfb part b 0 ulong n nm o p |
| 811 | end |
| 812 | |
| 813 | note The digits after the first "nm": in b appended to o at p. |
| 814 | fn rl_vfb b view uchar * nm view uchar * o edit uchar 8192 p ulong to ulong |
| 815 | k = new uchar 80 0 |
| 816 | put k 0 34 |
| 817 | q = rl_cat k 1 nm |
| 818 | put k q 34 |
| 819 | put k add q 1 58 |
| 820 | q = add q 2 |
| 821 | i = rl_find b part k 0 q |
| 822 | if lt i 0 |
| 823 | ret p |
| 824 | end |
| 825 | j = add ulong i q |
| 826 | e = rl_digs b j |
| 827 | ret rl_cat o p part b j sub e j |
| 828 | end |
| 829 | |
| 830 | note The end of the decimal digits of b from j. |
| 831 | fn rl_digs b view uchar * j ulong to ulong |
| 832 | e = j |
| 833 | n = len b |
| 834 | while lt e n bound 16777216 |
| 835 | c = get b e |
| 836 | if or lt c 48 gt c 57 |
| 837 | ret e |
| 838 | end |
| 839 | e = add e 1 |
| 840 | end |
| 841 | ret n |
| 842 | end |
| 843 | |
| 844 | fn rl_vis fl view uchar * nm view uchar * v view uchar * to bool |
| 845 | o = new uchar 8192 0 |
| 846 | n = rl_vf fl nm o 0 |
| 847 | ret rl_eq part o 0 n v |
| 848 | end |
| 849 | |
| 850 | note The decimal after the first "nm": in STATE/fl; 0 when absent or longer than 19 digits. |
| 851 | fn rl_vnum fl view uchar * nm view uchar * to ulong |
| 852 | o = new uchar 8192 0 |
| 853 | n = rl_vf fl nm o 0 |
| 854 | if gt n 19 |
| 855 | ret 0 |
| 856 | end |
| 857 | v = ulong 0 |
| 858 | for i ulong n bound 19 |
| 859 | v = add mul v 10 ulong sub get o i 48 |
| 860 | end |
| 861 | ret v |
| 862 | end |
| 863 | |
| 864 | note pk = BIN/op and the release.env value of key; the end. |
| 865 | fn rl_opk pk edit uchar 4096 key view uchar * to ulong |
| 866 | p = rl_pke pk 2 rlkbin rlxop |
| 867 | ret rl_pkv pk p key |
| 868 | end |
| 869 | |
| 870 | note op VIEW view > ou, stderr to /dev/null when en is 1; op's exit status. |
| 871 | fn rl_opv ou view uchar * en ulong to int |
| 872 | pk = new uchar 4096 0 |
| 873 | p = rl_opk pk rlkview |
| 874 | p = rl_pk pk p rlwview |
| 875 | rl_pkc pk 3 |
| 876 | fo = rl_open ou 524865 438 |
| 877 | if lt fo 0 |
| 878 | ret 2 |
| 879 | end |
| 880 | fe = long -1 |
| 881 | if eq en 1 |
| 882 | fe = rl_open rlnull 524289 0 |
| 883 | end |
| 884 | r = rl_run part pk 0 p -1 fo fe |
| 885 | rl_close fo |
| 886 | rl_close fe |
| 887 | ret r |
| 888 | end |
| 889 | |
| 890 | note op VIEW view into STATE/view.tmp, up to 50 times 0.1 s apart, then renamed to view.json; |
| 891 | note 0, or 1 when it never answered. |
| 892 | fn rl_view to int |
| 893 | a = new uchar 4096 0 |
| 894 | na = rl_stp a rlvtmp |
| 895 | for i ulong 50 |
| 896 | r = rl_opv part a 0 na 1 |
| 897 | if eq r 0 |
| 898 | x = rl_stmv rlvtmp rlvjs |
| 899 | ret 0 |
| 900 | end |
| 901 | if ge i 49 |
| 902 | ret 1 |
| 903 | end |
| 904 | x = sleepns 100000000 |
| 905 | end |
| 906 | ret 1 |
| 907 | end |
| 908 | |
| 909 | note The command id: digits 4..16 of the realtime nanoseconds (date +%s%N | cut -c4-16). |
| 910 | fn rl_cid o edit uchar * p ulong to ulong |
| 911 | d = new uchar 32 0 |
| 912 | n = rl_dec d 0 ulong realns |
| 913 | ret rl_cat o p part d 3 13 |
| 914 | end |
| 915 | |
| 916 | note op VIEW cmd ID op 0 INC VER > STATE/ack.json; op's exit status. |
| 917 | fn rl_opcmd op view uchar * to int |
| 918 | pk = new uchar 4096 0 |
| 919 | b = new uchar 8192 0 |
| 920 | p = rl_opk pk rlkview |
| 921 | p = rl_pk pk p rlwcmd |
| 922 | n = rl_cid b 0 |
| 923 | p = rl_pk pk p part b 0 n |
| 924 | p = rl_pk pk p op |
| 925 | p = rl_pk pk p rlzero |
| 926 | n = rl_vf rlvjs rlfinc b 0 |
| 927 | p = rl_pk pk p part b 0 n |
| 928 | n = rl_vf rlvjs rlfver b 0 |
| 929 | p = rl_pk pk p part b 0 n |
| 930 | rl_pkc pk 8 |
| 931 | fo = rl_stopen rlack 524865 438 |
| 932 | if lt fo 0 |
| 933 | ret 2 |
| 934 | end |
| 935 | r = rl_run part pk 0 p -1 fo -1 |
| 936 | rl_close fo |
| 937 | ret r |
| 938 | end |
| 939 | |
| 940 | note Post operator op (1 pause, 2 resume) from a fresh view until committed: 0, or 1. An |
| 941 | note "invalid" acknowledgement is the node already in that state. |
| 942 | fn rl_post op view uchar * to int |
| 943 | for i ulong 50 |
| 944 | if ne rl_view 0 |
| 945 | ret 1 |
| 946 | end |
| 947 | r = rl_opcmd op |
| 948 | rl_stout rlack |
| 949 | if eq r 0 |
| 950 | ret 0 |
| 951 | end |
| 952 | if rl_sthas rlack rlinv |
| 953 | ret 0 |
| 954 | end |
| 955 | if ge i 49 |
| 956 | ret 1 |
| 957 | end |
| 958 | x = sleepns 100000000 |
| 959 | end |
| 960 | ret 1 |
| 961 | end |
| 962 | |
| 963 | note Append lb and the view.json field nm to o at p. |
| 964 | fn rl_ofj o edit uchar 8192 p ulong lb view uchar * nm view uchar * to ulong |
| 965 | q = rl_cat o p lb |
| 966 | ret rl_vf rlvjs nm o q |
| 967 | end |
| 968 | |
| 969 | note Append lb and the view-at-stop.json field nm to o at p. |
| 970 | fn rl_ofs o edit uchar 8192 p ulong lb view uchar * nm view uchar * to ulong |
| 971 | q = rl_cat o p lb |
| 972 | ret rl_vf rlvst nm o q |
| 973 | end |
| 974 | |
| 975 | note ======== build |
| 976 | |
| 977 | note Write om2 and the units of the space-separated list ls to pa; 0 or -1. |
| 978 | fn rl_comp pa view uchar * ls view uchar * to long |
| 979 | fd = rl_open pa 524865 438 |
| 980 | if lt fd 0 |
| 981 | ret -1 |
| 982 | end |
| 983 | r = rl_wall int fd rlom2 |
| 984 | s = ulong 0 |
| 985 | n = len ls |
| 986 | while lt s n bound 64 |
| 987 | e = s |
| 988 | while lt e n bound 4096 |
| 989 | if eq get ls e 32 |
| 990 | break |
| 991 | end |
| 992 | e = add e 1 |
| 993 | end |
| 994 | r = rl_fout part ls s sub e s int fd |
| 995 | if lt r 0 |
| 996 | rl_close fd |
| 997 | ret -1 |
| 998 | end |
| 999 | s = add e 1 |
| 1000 | end |
| 1001 | rl_close fd |
| 1002 | ret 0 |
| 1003 | end |
| 1004 | |
| 1005 | note seed/out/omc < pa.om > pa.tmp 2> pa.cerr; omc's exit status. |
| 1006 | fn rl_omc pa view uchar * to int |
| 1007 | pk = new uchar 4096 0 |
| 1008 | b = new uchar 4096 0 |
| 1009 | put pk 0 1 |
| 1010 | p = rl_pk pk 2 rlomc |
| 1011 | n = rl_cat b 0 pa |
| 1012 | n = rl_cat b n rlxom |
| 1013 | fi = fopen b 0 n 524288 0 |
| 1014 | n = rl_cat b len pa rlxtmp |
| 1015 | x = unlink b 0 n |
| 1016 | fo = fopen b 0 n 524993 511 |
| 1017 | n = rl_cat b len pa rlxcerr |
| 1018 | fe = fopen b 0 n 524865 438 |
| 1019 | r = int 2 |
| 1020 | if and and ge fi 0 ge fo 0 ge fe 0 |
| 1021 | r = rl_run part pk 0 p fi fo fe |
| 1022 | end |
| 1023 | rl_close fi |
| 1024 | rl_close fo |
| 1025 | rl_close fe |
| 1026 | ret r |
| 1027 | end |
| 1028 | |
| 1029 | note Rename pa.tmp over pa. |
| 1030 | fn rl_bmv pa view uchar * to long |
| 1031 | pk = new uchar 4096 0 |
| 1032 | b = new uchar 4096 0 |
| 1033 | put pk 0 2 |
| 1034 | n = rl_cat b 0 pa |
| 1035 | n = rl_cat b n rlxtmp |
| 1036 | p = rl_pk pk 2 part b 0 n |
| 1037 | p = rl_pk pk p pa |
| 1038 | ret renames pk 0 p 0 |
| 1039 | end |
| 1040 | |
| 1041 | note Remove pa.tmp. |
| 1042 | fn rl_brm pa view uchar * to void |
| 1043 | b = new uchar 4096 0 |
| 1044 | n = rl_cat b 0 pa |
| 1045 | n = rl_cat b n rlxtmp |
| 1046 | x = unlink b 0 n |
| 1047 | end |
| 1048 | |
| 1049 | note Build program nm from the units ls into OUT/nm; 0, or 1 when omc refused it. |
| 1050 | fn rl_b1 nm view uchar * ls view uchar * to int |
| 1051 | pa = new uchar 4096 0 |
| 1052 | b = new uchar 4096 0 |
| 1053 | o = new uchar 8192 0 |
| 1054 | n = rl_arg 2 pa |
| 1055 | put pa n 47 |
| 1056 | n = rl_cat pa add n 1 nm |
| 1057 | q = rl_cat b 0 part pa 0 n |
| 1058 | q = rl_cat b q rlxom |
| 1059 | r = rl_comp part b 0 q ls |
| 1060 | if lt r 0 |
| 1061 | p = rl_cat o 0 rlmcomp |
| 1062 | p = rl_cat o p part b 0 q |
| 1063 | rl_die part o 0 p 1 |
| 1064 | end |
| 1065 | if eq rl_omc part pa 0 n 0 |
| 1066 | x = rl_bmv part pa 0 n |
| 1067 | p = rl_cat o 0 rlobok |
| 1068 | p = rl_cat o p nm |
| 1069 | p = rl_cat o p rlsp |
| 1070 | p = rl_dec o p rl_size part pa 0 n |
| 1071 | p = rl_cat o p rlsp |
| 1072 | p = rl_sha part pa 0 n o p |
| 1073 | p = rl_cat o p rlnl |
| 1074 | x = rl_wall 1 part o 0 p |
| 1075 | ret 0 |
| 1076 | end |
| 1077 | p = rl_cat o 0 rlobf |
| 1078 | p = rl_cat o p nm |
| 1079 | p = rl_cat o p rlsp |
| 1080 | q = rl_cat b 0 part pa 0 n |
| 1081 | q = rl_cat b q rlxcerr |
| 1082 | p = rl_fcat part b 0 q o p |
| 1083 | p = rl_cat o p rlnl |
| 1084 | x = rl_wall 1 part o 0 p |
| 1085 | rl_brm part pa 0 n |
| 1086 | ret 1 |
| 1087 | end |
| 1088 | |
| 1089 | fn rl_build to int |
| 1090 | b = new uchar 4096 0 |
| 1091 | o = new uchar 8192 0 |
| 1092 | n = rl_arg 2 b |
| 1093 | r = rl_mkp part b 0 n |
| 1094 | if lt r 0 |
| 1095 | rl_diea rlmdir 2 1 |
| 1096 | end |
| 1097 | if eq rl_size rlomc 0 |
| 1098 | rl_die rlmroot 2 |
| 1099 | end |
| 1100 | c = rl_b1 rlbn1 rlbl1 |
| 1101 | c = or c rl_b1 rlbn2 rlbl2 |
| 1102 | c = or c rl_b1 rlbn3 rlbl3 |
| 1103 | c = or c rl_b1 rlbn4 rlbl4 |
| 1104 | c = or c rl_b1 rlbn5 rlbl5 |
| 1105 | c = or c rl_b1 rlbn6 rlbl6 |
| 1106 | p = rl_cat o 0 rloomc |
| 1107 | p = rl_sha rlomc o p |
| 1108 | p = rl_cat o p rlnl |
| 1109 | x = rl_wall 1 part o 0 p |
| 1110 | ret c |
| 1111 | end |
| 1112 | |
| 1113 | note ======== serve and unserve |
| 1114 | |
| 1115 | note Die "MSG(content of STATE/nm))", exit c. |
| 1116 | fn rl_diep m view uchar * nm view uchar * c int to void |
| 1117 | o = new uchar 8192 0 |
| 1118 | p = rl_cat o 0 m |
| 1119 | p = rl_stfcat nm o p |
| 1120 | p = rl_cat o p rlmcl |
| 1121 | rl_die part o 0 p c |
| 1122 | end |
| 1123 | |
| 1124 | note Die "MSG<tail -3 STATE/nm>", exit 1. |
| 1125 | fn rl_diet m view uchar * nm view uchar * to void |
| 1126 | o = new uchar 8192 0 |
| 1127 | pa = new uchar 4096 0 |
| 1128 | p = rl_cat o 0 m |
| 1129 | n = rl_stp pa nm |
| 1130 | p = rl_tail3 part pa 0 n o p |
| 1131 | rl_die part o 0 p 1 |
| 1132 | end |
| 1133 | |
| 1134 | note Die when argument i is 18091. |
| 1135 | fn rl_no18 i ulong to void |
| 1136 | b = new uchar 4096 0 |
| 1137 | n = rl_arg i b |
| 1138 | if rl_eq part b 0 n rl18091 |
| 1139 | rl_die rlm18 2 |
| 1140 | end |
| 1141 | end |
| 1142 | |
| 1143 | note OLLM VERB PORT CK MERGES >> STATE/serve.log 2>&1 < /dev/null; the PID. |
| 1144 | fn rl_svgo to long |
| 1145 | pk = new uchar 4096 0 |
| 1146 | p = rl_pka pk 2 4 |
| 1147 | p = rl_pka pk p 5 |
| 1148 | p = rl_pka pk p 3 |
| 1149 | p = rl_pka pk p 6 |
| 1150 | p = rl_pka pk p 7 |
| 1151 | rl_pkc pk 5 |
| 1152 | fi = rl_open rlnull 524288 0 |
| 1153 | fo = rl_stopen rlslog 525377 438 |
| 1154 | if or lt fi 0 lt fo 0 |
| 1155 | rl_die rlmspn 1 |
| 1156 | end |
| 1157 | pid = rl_spawn part pk 0 p fi fo fo |
| 1158 | rl_close fi |
| 1159 | rl_close fo |
| 1160 | if lt pid 0 |
| 1161 | rl_die rlmspn 1 |
| 1162 | end |
| 1163 | ret pid |
| 1164 | end |
| 1165 | |
| 1166 | fn rl_serve to int |
| 1167 | o = new uchar 8192 0 |
| 1168 | b = new uchar 4096 0 |
| 1169 | pa = new uchar 4096 0 |
| 1170 | if ne argcnt 8 |
| 1171 | rl_die rlusv 2 |
| 1172 | end |
| 1173 | rl_no18 3 |
| 1174 | if rl_alive rlspid |
| 1175 | rl_diep rlmsrun rlspid 3 |
| 1176 | end |
| 1177 | n = rl_arg 2 b |
| 1178 | r = rl_mkp part b 0 n |
| 1179 | if lt r 0 |
| 1180 | rl_diea rlmdir 2 1 |
| 1181 | end |
| 1182 | fd = rl_stopen rlslog 524865 438 |
| 1183 | rl_close fd |
| 1184 | pid = rl_svgo |
| 1185 | rl_wpid rlspid pid |
| 1186 | n = rl_cat b 0 rlportp |
| 1187 | q = rl_arg 3 part b n sub 4096 n |
| 1188 | n = add n q |
| 1189 | na = rl_stp pa rlslog |
| 1190 | for i ulong 3000 |
| 1191 | if gt rl_cntpre part pa 0 na part b 0 n 0 |
| 1192 | break |
| 1193 | end |
| 1194 | if rl_alive rlspid |
| 1195 | else |
| 1196 | rl_diet rlmsex rlslog |
| 1197 | end |
| 1198 | if ge i 2999 |
| 1199 | rl_die rlmp300 1 |
| 1200 | end |
| 1201 | x = sleepns 100000000 |
| 1202 | end |
| 1203 | p = rl_cat o 0 rlosv1 |
| 1204 | p = rl_stfcat rlspid o p |
| 1205 | p = rl_cat o p rlosv2 |
| 1206 | q = rl_arg 3 part b 0 4096 |
| 1207 | p = rl_cat o p part b 0 q |
| 1208 | p = rl_cat o p rlosv3 |
| 1209 | q = rl_arg 4 part b 0 4096 |
| 1210 | p = rl_sha part b 0 q o p |
| 1211 | p = rl_cat o p rlosv4 |
| 1212 | q = rl_arg 5 part b 0 4096 |
| 1213 | p = rl_cat o p part b 0 q |
| 1214 | p = rl_cat o p rlnl |
| 1215 | x = rl_wall 1 part o 0 p |
| 1216 | ret 0 |
| 1217 | end |
| 1218 | |
| 1219 | fn rl_unsrv to int |
| 1220 | o = new uchar 8192 0 |
| 1221 | if rl_alive rlspid |
| 1222 | else |
| 1223 | rl_die rlmnos 3 |
| 1224 | end |
| 1225 | pid = rl_pidf rlspid |
| 1226 | x = killpid int pid 15 |
| 1227 | rl_gone pid |
| 1228 | p = rl_cat o 0 rlous1 |
| 1229 | p = rl_dec o p ulong pid |
| 1230 | p = rl_cat o p rlous2 |
| 1231 | p = rl_cat o p rlnl |
| 1232 | x = rl_wall 1 part o 0 p |
| 1233 | ret 0 |
| 1234 | end |
| 1235 | |
| 1236 | note ======== start, run, health, stop, restore |
| 1237 | |
| 1238 | note The date -u +%FT%TZ of the realtime clock appended to o at p. |
| 1239 | fn rl_date o edit uchar * p ulong to ulong |
| 1240 | t = div ulong realns 1000000000 |
| 1241 | q = rl_civil o p div t 86400 |
| 1242 | s = rem t 86400 |
| 1243 | put o q 84 |
| 1244 | q = rl_d2 o add q 1 div s 3600 |
| 1245 | put o q 58 |
| 1246 | q = rl_d2 o add q 1 rem div s 60 60 |
| 1247 | put o q 58 |
| 1248 | q = rl_d2 o add q 1 rem s 60 |
| 1249 | put o q 90 |
| 1250 | ret add q 1 |
| 1251 | end |
| 1252 | |
| 1253 | note The civil date YYYY-MM-DD of day dy since 1970-01-01 (proleptic Gregorian, H. Hinnant's |
| 1254 | note days_from_civil inverse) appended to o at p. |
| 1255 | fn rl_civil o edit uchar * p ulong dy ulong to ulong |
| 1256 | era = div add dy 719468 146097 |
| 1257 | doe = sub add dy 719468 mul era 146097 |
| 1258 | y = add rl_yoe doe mul era 400 |
| 1259 | ret rl_ymd o p y rl_doy doe |
| 1260 | end |
| 1261 | |
| 1262 | note The day of year (from March 1) of day of era doe. |
| 1263 | fn rl_doy doe ulong to ulong |
| 1264 | yoe = rl_yoe doe |
| 1265 | ret sub doe add sub mul 365 yoe div yoe 100 div yoe 4 |
| 1266 | end |
| 1267 | |
| 1268 | note YYYY-MM-DD of March-based year y and day of year doy appended to o at p. |
| 1269 | fn rl_ymd o edit uchar * p ulong y ulong doy ulong to ulong |
| 1270 | mp = div add mul 5 doy 2 153 |
| 1271 | d = add sub doy div add mul 153 mp 2 5 1 |
| 1272 | m = add mp 3 |
| 1273 | yr = y |
| 1274 | if ge mp 10 |
| 1275 | m = sub mp 9 |
| 1276 | end |
| 1277 | if le m 2 |
| 1278 | yr = add y 1 |
| 1279 | end |
| 1280 | q = rl_dec o p yr |
| 1281 | put o q 45 |
| 1282 | q = rl_d2 o add q 1 m |
| 1283 | put o q 45 |
| 1284 | ret rl_d2 o add q 1 d |
| 1285 | end |
| 1286 | |
| 1287 | note The year of era of day of era doe: (doe - doe/1460 + doe/36524 - doe/146096) / 365. |
| 1288 | fn rl_yoe doe ulong to ulong |
| 1289 | a = sub doe div doe 1460 |
| 1290 | a = add a div doe 36524 |
| 1291 | a = sub a div doe 146096 |
| 1292 | ret div a 365 |
| 1293 | end |
| 1294 | |
| 1295 | note Append "RUN n DATE" to STATE/run.out, n the lines that already begin with RUN. |
| 1296 | fn rl_runln to void |
| 1297 | o = new uchar 8192 0 |
| 1298 | pa = new uchar 4096 0 |
| 1299 | na = rl_stp pa rlrout |
| 1300 | c = rl_cntpre part pa 0 na rlrunp |
| 1301 | p = rl_cat o 0 rlrunp |
| 1302 | p = rl_dec o p c |
| 1303 | p = rl_cat o p rlsp |
| 1304 | p = rl_date o p |
| 1305 | p = rl_cat o p rlnl |
| 1306 | fd = fopen pa 0 na 525377 438 |
| 1307 | if ge fd 0 |
| 1308 | x = rl_wall int fd part o 0 p |
| 1309 | end |
| 1310 | rl_close fd |
| 1311 | end |
| 1312 | |
| 1313 | note Append one record per newline-terminated line of STATE/objs.txt (while read -r); set the |
| 1314 | note count to 9 plus the objectives; the end. |
| 1315 | fn rl_pkobj pk edit uchar 4096 p ulong to ulong |
| 1316 | b = new uchar 65536 0 |
| 1317 | n = rl_stsl rlobjs b |
| 1318 | if lt n 0 |
| 1319 | rl_diea rlmobj 2 1 |
| 1320 | end |
| 1321 | c = ulong 9 |
| 1322 | s = ulong 0 |
| 1323 | q = p |
| 1324 | while lt s ulong n bound 65536 |
| 1325 | e = rl_eol part b 0 ulong n s |
| 1326 | if ge e ulong n |
| 1327 | break |
| 1328 | end |
| 1329 | q = rl_pk pk q part b s sub e s |
| 1330 | c = add c 1 |
| 1331 | s = add e 1 |
| 1332 | end |
| 1333 | rl_pkc pk c |
| 1334 | ret q |
| 1335 | end |
| 1336 | |
| 1337 | note BIN/code-main BIN/infer BIN/tool OMC STATE/root STATE/work STATE/journal PORT VIEW |
| 1338 | note objectives..., stdin /dev/null, stdout >> run.out, stderr >> run.err; the PID. |
| 1339 | fn rl_node to long |
| 1340 | pk = new uchar 4096 0 |
| 1341 | p = rl_pke pk 2 rlkbin rlxcm |
| 1342 | p = rl_pke pk p rlkbin rlxinf |
| 1343 | p = rl_pke pk p rlkbin rlxtool |
| 1344 | p = rl_pkv pk p rlkomc |
| 1345 | p = rl_pks pk p rlxroot |
| 1346 | p = rl_pks pk p rlxwork |
| 1347 | p = rl_pks pk p rlxjour |
| 1348 | p = rl_pkv pk p rlkport |
| 1349 | p = rl_pkv pk p rlkview |
| 1350 | p = rl_pkobj pk p |
| 1351 | fi = rl_open rlnull 524288 0 |
| 1352 | fo = rl_stopen rlrout 525377 438 |
| 1353 | fe = rl_stopen rlrerr 525377 438 |
| 1354 | if or or lt fi 0 lt fo 0 lt fe 0 |
| 1355 | rl_die rlmspn 1 |
| 1356 | end |
| 1357 | pid = rl_spawn part pk 0 p fi fo fe |
| 1358 | rl_close fi |
| 1359 | rl_close fo |
| 1360 | rl_close fe |
| 1361 | if lt pid 0 |
| 1362 | rl_die rlmspn 1 |
| 1363 | end |
| 1364 | ret pid |
| 1365 | end |
| 1366 | |
| 1367 | note Wait until the view answers (300 times 0.1 s) while the node lives. |
| 1368 | fn rl_nwait to void |
| 1369 | for i ulong 300 |
| 1370 | if eq rl_opv rlnull 1 0 |
| 1371 | ret |
| 1372 | end |
| 1373 | if rl_alive rlnpid |
| 1374 | else |
| 1375 | rl_diet rlmnex rlrout |
| 1376 | end |
| 1377 | if ge i 299 |
| 1378 | rl_die rlmv30 1 |
| 1379 | end |
| 1380 | x = sleepns 100000000 |
| 1381 | end |
| 1382 | end |
| 1383 | |
| 1384 | note Start the node on STATE with release.env (start and restore). |
| 1385 | fn rl_runn to int |
| 1386 | o = new uchar 8192 0 |
| 1387 | if rl_alive rlnpid |
| 1388 | rl_diep rlmnrun rlnpid 3 |
| 1389 | end |
| 1390 | rl_stmkp rljour |
| 1391 | rl_stmkp rlwork |
| 1392 | rl_runln |
| 1393 | pid = rl_node |
| 1394 | rl_wpid rlnpid pid |
| 1395 | rl_nwait |
| 1396 | if ne rl_view 0 |
| 1397 | rl_die rlmv2 1 |
| 1398 | end |
| 1399 | p = rl_cat o 0 rlond1 |
| 1400 | p = rl_stfcat rlnpid o p |
| 1401 | p = rl_cat o p rlond2 |
| 1402 | p = rl_env rlkview o p |
| 1403 | p = rl_ofj o p rlond3 rlfinc |
| 1404 | p = rl_ofj o p rlond4 rlfver |
| 1405 | p = rl_cat o p rlnl |
| 1406 | x = rl_wall 1 part o 0 p |
| 1407 | ret 0 |
| 1408 | end |
| 1409 | |
| 1410 | note The logical absolute form of directory argument i (as cd DIR && pwd) into o; its length. |
| 1411 | fn rl_absd i ulong o edit uchar * to ulong |
| 1412 | t = new uchar 8192 0 |
| 1413 | n = ulong 0 |
| 1414 | a = rl_arg i part t 4096 4096 |
| 1415 | if eq a 0 |
| 1416 | rl_diea rlmbin i 2 |
| 1417 | end |
| 1418 | if ne get t 4096 47 |
| 1419 | c = cwd t 0 4096 |
| 1420 | if le c 1 |
| 1421 | rl_diea rlmbin i 2 |
| 1422 | end |
| 1423 | n = sub ulong c 1 |
| 1424 | put t n 47 |
| 1425 | n = add n 1 |
| 1426 | end |
| 1427 | for j ulong a |
| 1428 | put t add n j get t add 4096 j |
| 1429 | end |
| 1430 | q = rl_norm part t 0 add n a o |
| 1431 | if rl_isdir part o 0 q |
| 1432 | ret q |
| 1433 | end |
| 1434 | rl_diea rlmbin i 2 |
| 1435 | ret 0 |
| 1436 | end |
| 1437 | |
| 1438 | note Remove empty, . and .. components of the absolute path t into o; its length. |
| 1439 | fn rl_norm t view uchar * o edit uchar * to ulong |
| 1440 | q = ulong 0 |
| 1441 | s = ulong 0 |
| 1442 | n = len t |
| 1443 | while lt s n bound 8192 |
| 1444 | if eq get t s 47 |
| 1445 | s = add s 1 |
| 1446 | continue |
| 1447 | end |
| 1448 | e = s |
| 1449 | while lt e n bound 8192 |
| 1450 | if eq get t e 47 |
| 1451 | break |
| 1452 | end |
| 1453 | e = add e 1 |
| 1454 | end |
| 1455 | k = sub e s |
| 1456 | if and eq k 1 eq get t s 46 |
| 1457 | s = e |
| 1458 | continue |
| 1459 | end |
| 1460 | if eq k 2 |
| 1461 | if and eq get t s 46 eq get t add s 1 46 |
| 1462 | while gt q 0 bound 8192 |
| 1463 | q = sub q 1 |
| 1464 | if eq get o q 47 |
| 1465 | break |
| 1466 | end |
| 1467 | end |
| 1468 | s = e |
| 1469 | continue |
| 1470 | end |
| 1471 | end |
| 1472 | put o q 47 |
| 1473 | q = rl_cat o add q 1 part t s k |
| 1474 | s = e |
| 1475 | end |
| 1476 | if eq q 0 |
| 1477 | put o 0 47 |
| 1478 | q = 1 |
| 1479 | end |
| 1480 | ret q |
| 1481 | end |
| 1482 | |
| 1483 | fn rl_start to int |
| 1484 | b = new uchar 16384 0 |
| 1485 | pa = new uchar 4096 0 |
| 1486 | if ne argcnt 7 |
| 1487 | rl_die rlust 2 |
| 1488 | end |
| 1489 | rl_no18 5 |
| 1490 | rl_no18 6 |
| 1491 | n = rl_arg 2 pa |
| 1492 | r = rl_mkp part pa 0 n |
| 1493 | if lt r 0 |
| 1494 | rl_diea rlmdir 2 1 |
| 1495 | end |
| 1496 | p = rl_cat b 0 rlkbin |
| 1497 | put b p 61 |
| 1498 | q = rl_absd 3 part b add p 1 4096 |
| 1499 | p = add add p 1 q |
| 1500 | p = rl_envl b p rlkomc 4 |
| 1501 | p = rl_envl b p rlkport 5 |
| 1502 | p = rl_envl b p rlkview 6 |
| 1503 | put b p 10 |
| 1504 | n = rl_stp pa rlenvf |
| 1505 | fd = fopen pa 0 n 524865 438 |
| 1506 | if ge fd 0 |
| 1507 | x = rl_wall int fd part b 0 add p 1 |
| 1508 | end |
| 1509 | rl_close fd |
| 1510 | rl_envck |
| 1511 | ret rl_runn |
| 1512 | end |
| 1513 | |
| 1514 | note Append "\nkey=argument i" to b at p. |
| 1515 | fn rl_envl b edit uchar 16384 p ulong key view uchar * i ulong to ulong |
| 1516 | put b p 10 |
| 1517 | q = rl_cat b add p 1 key |
| 1518 | put b q 61 |
| 1519 | n = rl_arg i part b add q 1 4096 |
| 1520 | ret add add q 1 n |
| 1521 | end |
| 1522 | |
| 1523 | fn rl_health to int |
| 1524 | o = new uchar 8192 0 |
| 1525 | pk = new uchar 4096 0 |
| 1526 | rl_envck |
| 1527 | p = rl_opk pk rlkport |
| 1528 | p = rl_pk pk p rlwhlth |
| 1529 | rl_pkc pk 3 |
| 1530 | fo = rl_stopen rlhj 524865 438 |
| 1531 | m = int 2 |
| 1532 | if ge fo 0 |
| 1533 | m = rl_run part pk 0 p -1 fo -1 |
| 1534 | end |
| 1535 | rl_close fo |
| 1536 | v = rl_view |
| 1537 | q = rl_cat o 0 rlohm |
| 1538 | q = rl_dec o q ulong m |
| 1539 | q = rl_cat o q rlsp |
| 1540 | q = rl_stfcat rlhj o q |
| 1541 | q = rl_cat o q rlohn |
| 1542 | q = rl_dec o q ulong v |
| 1543 | q = rl_ofj o q rlond3 rlfinc |
| 1544 | q = rl_ofj o q rlohr rlfrun |
| 1545 | q = rl_ofj o q rlohj rlfjf |
| 1546 | q = rl_cat o q rlnl |
| 1547 | x = rl_wall 1 part o 0 q |
| 1548 | if and eq m 0 eq v 0 |
| 1549 | ret 0 |
| 1550 | end |
| 1551 | ret 1 |
| 1552 | end |
| 1553 | |
| 1554 | note Wait until nothing runs or is in review (9000 times 0.1 s). |
| 1555 | fn rl_drain to void |
| 1556 | for i ulong 9000 |
| 1557 | if eq rl_view 0 |
| 1558 | if and rl_vis rlvjs rlfrun rlzero rl_vis rlvjs rlfrev rlzero |
| 1559 | ret |
| 1560 | end |
| 1561 | else |
| 1562 | if rl_alive rlnpid |
| 1563 | else |
| 1564 | rl_die rlmnxs 1 |
| 1565 | end |
| 1566 | end |
| 1567 | if ge i 8999 |
| 1568 | rl_die rlm900 1 |
| 1569 | end |
| 1570 | x = sleepns 100000000 |
| 1571 | end |
| 1572 | end |
| 1573 | |
| 1574 | note cp STATE/view.json STATE/view-at-stop.json |
| 1575 | fn rl_vcopy to void |
| 1576 | pa = new uchar 4096 0 |
| 1577 | n = rl_stp pa rlvjs |
| 1578 | fd = rl_stopen rlvst 524865 438 |
| 1579 | if ge fd 0 |
| 1580 | r = rl_fout part pa 0 n int fd |
| 1581 | end |
| 1582 | rl_close fd |
| 1583 | end |
| 1584 | |
| 1585 | fn rl_stop to int |
| 1586 | o = new uchar 8192 0 |
| 1587 | rl_envck |
| 1588 | if rl_alive rlnpid |
| 1589 | else |
| 1590 | rl_die rlmnnr 3 |
| 1591 | end |
| 1592 | if ne rl_post rlone 0 |
| 1593 | rl_die rlmpau 1 |
| 1594 | end |
| 1595 | rl_drain |
| 1596 | rl_vcopy |
| 1597 | pid = rl_pidf rlnpid |
| 1598 | x = killpid int pid 15 |
| 1599 | rl_gone pid |
| 1600 | p = rl_cat o 0 rlost |
| 1601 | p = rl_dec o p ulong pid |
| 1602 | p = rl_ofs o p rlohr rlfrun |
| 1603 | p = rl_ofs o p rlosw rlfwait |
| 1604 | p = rl_ofs o p rlosy rlfrdy |
| 1605 | p = rl_cat o p rlnl |
| 1606 | x = rl_wall 1 part o 0 p |
| 1607 | ret 0 |
| 1608 | end |
| 1609 | |
| 1610 | note The creator publishes its view snapshot after it commits a command, so a view read right |
| 1611 | note after the resume's committed ack can predate it (observed: ack journal_seq 24, view 22 with |
| 1612 | note paused 1). Report only a view at or past the ack's journal_seq: up to 50 reads 0.1 s apart, |
| 1613 | note else exit 1. Every ack carries journal_seq (the creator's, or 0 for the view's own verdict). |
| 1614 | fn rl_rest to int |
| 1615 | o = new uchar 8192 0 |
| 1616 | rl_envck |
| 1617 | r = rl_runn |
| 1618 | w = ulong 0 |
| 1619 | if rl_vis rlvjs rlfpau rlone |
| 1620 | if ne rl_post rltwo 0 |
| 1621 | rl_die rlmres 1 |
| 1622 | end |
| 1623 | w = rl_vnum rlack rlfjsq |
| 1624 | x = rl_wall 1 rlnl |
| 1625 | end |
| 1626 | for i ulong 50 |
| 1627 | if ne rl_view 0 |
| 1628 | rl_die rlmvno 1 |
| 1629 | end |
| 1630 | if ge rl_vnum rlvjs rlfjsq w |
| 1631 | break |
| 1632 | end |
| 1633 | if ge i 49 |
| 1634 | rl_die rlmvlag 1 |
| 1635 | end |
| 1636 | x = sleepns 100000000 |
| 1637 | end |
| 1638 | p = rl_cat o 0 rlors |
| 1639 | p = rl_vf rlvjs rlfinc o p |
| 1640 | p = rl_ofj o p rlorp rlfpau |
| 1641 | p = rl_cat o p rlnl |
| 1642 | x = rl_wall 1 part o 0 p |
| 1643 | ret 0 |
| 1644 | end |
| 1645 | |
| 1646 | note ======== snapshot and rollback |
| 1647 | |
| 1648 | note Copy the tree rlsrc[0, sl) to the new path rldst[0, dl), not following symbolic links: |
| 1649 | note directories, regular files (bytes and permission bits) and symbolic links. 0 or a |
| 1650 | note negative error (-22 another file type, -40 deeper than 64). |
| 1651 | fn rl_cpt sl ulong dl ulong dp ulong to long |
| 1652 | st = new uchar 128 0 |
| 1653 | r = lstat rlsrc 0 sl st 0 128 |
| 1654 | if lt r 0 |
| 1655 | ret r |
| 1656 | end |
| 1657 | md = or ulong get st 16 shl ulong get st 17 8 |
| 1658 | ty = and md 61440 |
| 1659 | if eq ty 16384 |
| 1660 | if gt dp 64 |
| 1661 | ret -40 |
| 1662 | end |
| 1663 | r = makedir rldst 0 dl 448 |
| 1664 | if lt r 0 |
| 1665 | ret r |
| 1666 | end |
| 1667 | r = rl_cpdl sl dl dp |
| 1668 | if lt r 0 |
| 1669 | ret r |
| 1670 | end |
| 1671 | put rlcn 1 add get rlcn 1 1 |
| 1672 | ret chmod rldst 0 dl int and md 4095 |
| 1673 | end |
| 1674 | if eq ty 32768 |
| 1675 | ret rl_cpf sl dl and md 4095 |
| 1676 | end |
| 1677 | if eq ty 40960 |
| 1678 | ret rl_cpl sl dl |
| 1679 | end |
| 1680 | ret -22 |
| 1681 | end |
| 1682 | |
| 1683 | note Copy every entry of the directory rlsrc[0, sl) into rldst[0, dl). |
| 1684 | fn rl_cpdl sl ulong dl ulong dp ulong to long |
| 1685 | bf = new uchar 8192 0 |
| 1686 | fd = fopen rlsrc 0 sl 573440 0 |
| 1687 | if lt fd 0 |
| 1688 | ret fd |
| 1689 | end |
| 1690 | r = long 0 |
| 1691 | for it ulong 16777216 |
| 1692 | k = getdnts int fd bf 0 8192 |
| 1693 | if le k 0 |
| 1694 | r = k |
| 1695 | break |
| 1696 | end |
| 1697 | off = ulong 0 |
| 1698 | while lt off ulong k bound 8192 |
| 1699 | r = rl_cpe bf off sl dl dp |
| 1700 | if lt r 0 |
| 1701 | rl_close fd |
| 1702 | ret r |
| 1703 | end |
| 1704 | off = add off rl_rec bf off |
| 1705 | end |
| 1706 | end |
| 1707 | rl_close fd |
| 1708 | ret r |
| 1709 | end |
| 1710 | |
| 1711 | note The record length of the getdnts entry at bf[off) (at least 1). |
| 1712 | fn rl_rec bf view uchar 8192 off ulong to ulong |
| 1713 | v = or ulong get bf add off 16 shl ulong get bf add off 17 8 |
| 1714 | if eq v 0 |
| 1715 | ret 8192 |
| 1716 | end |
| 1717 | ret v |
| 1718 | end |
| 1719 | |
| 1720 | note The entry name at bf[off + 19..) (zero-terminated) appended after "/" to both stacks |
| 1721 | note and copied; . and .. skipped. |
| 1722 | fn rl_cpe bf view uchar 8192 off ulong sl ulong dl ulong dp ulong to long |
| 1723 | s = add off 19 |
| 1724 | e = s |
| 1725 | while ne get bf e 0 bound 8192 |
| 1726 | e = add e 1 |
| 1727 | end |
| 1728 | k = sub e s |
| 1729 | if le k 2 |
| 1730 | if eq get bf s 46 |
| 1731 | if eq k 1 |
| 1732 | ret 0 |
| 1733 | end |
| 1734 | if eq get bf add s 1 46 |
| 1735 | ret 0 |
| 1736 | end |
| 1737 | end |
| 1738 | end |
| 1739 | if or gt add add sl k 1 4095 gt add add dl k 1 4095 |
| 1740 | ret -36 |
| 1741 | end |
| 1742 | put rlsrc sl 47 |
| 1743 | put rldst dl 47 |
| 1744 | sl = add sl 1 |
| 1745 | dl = add dl 1 |
| 1746 | for i ulong k |
| 1747 | c = get bf add s i |
| 1748 | put rlsrc add sl i c |
| 1749 | put rldst add dl i c |
| 1750 | end |
| 1751 | ret rl_cpt add sl k add dl k add dp 1 |
| 1752 | end |
| 1753 | |
| 1754 | note Copy the regular file rlsrc[0, sl) to the new file rldst[0, dl) with mode pm, synced. |
| 1755 | fn rl_cpf sl ulong dl ulong pm ulong to long |
| 1756 | b = new uchar 65536 0 |
| 1757 | fi = fopen rlsrc 0 sl 557056 0 |
| 1758 | if lt fi 0 |
| 1759 | ret fi |
| 1760 | end |
| 1761 | fo = fopen rldst 0 dl 524481 384 |
| 1762 | if lt fo 0 |
| 1763 | rl_close fi |
| 1764 | ret fo |
| 1765 | end |
| 1766 | r = long 0 |
| 1767 | for it ulong 16777216 |
| 1768 | k = read int fi b 0 65536 |
| 1769 | if le k 0 |
| 1770 | r = k |
| 1771 | break |
| 1772 | end |
| 1773 | r = rl_wall int fo part b 0 ulong k |
| 1774 | if lt r 0 |
| 1775 | break |
| 1776 | end |
| 1777 | put rlcn 3 add get rlcn 3 ulong k |
| 1778 | end |
| 1779 | if ge r 0 |
| 1780 | r = fchmod int fo int pm |
| 1781 | end |
| 1782 | if ge r 0 |
| 1783 | r = fsync int fo |
| 1784 | end |
| 1785 | rl_close fi |
| 1786 | rl_close fo |
| 1787 | put rlcn 0 add get rlcn 0 1 |
| 1788 | ret r |
| 1789 | end |
| 1790 | |
| 1791 | note Recreate the symbolic link rlsrc[0, sl) at rldst[0, dl). |
| 1792 | fn rl_cpl sl ulong dl ulong to long |
| 1793 | t = new uchar 4096 0 |
| 1794 | pk = new uchar 4096 0 |
| 1795 | k = readlnk rlsrc 0 sl t 0 4096 |
| 1796 | if le k 0 |
| 1797 | ret -36 |
| 1798 | end |
| 1799 | put pk 0 2 |
| 1800 | p = rl_pk pk 2 part t 0 ulong k |
| 1801 | if gt add add p 2 dl 4096 |
| 1802 | ret -36 |
| 1803 | end |
| 1804 | put pk p uchar and dl 255 |
| 1805 | put pk add p 1 uchar shr dl 8 |
| 1806 | for i ulong dl |
| 1807 | put pk add add p 2 i get rldst i |
| 1808 | end |
| 1809 | put rlcn 2 add get rlcn 2 1 |
| 1810 | ret symlnk pk 0 add add p 2 dl |
| 1811 | end |
| 1812 | |
| 1813 | note Remove the tree rlsrc[0, sl) without following symbolic links; a missing path is 0. |
| 1814 | fn rl_rmt sl ulong dp ulong to long |
| 1815 | st = new uchar 128 0 |
| 1816 | r = lstat rlsrc 0 sl st 0 128 |
| 1817 | if eq r -2 |
| 1818 | ret 0 |
| 1819 | end |
| 1820 | if lt r 0 |
| 1821 | ret r |
| 1822 | end |
| 1823 | if eq and or ulong get st 16 shl ulong get st 17 8 61440 16384 |
| 1824 | if gt dp 64 |
| 1825 | ret -40 |
| 1826 | end |
| 1827 | r = rl_rmdl sl dp |
| 1828 | if lt r 0 |
| 1829 | ret r |
| 1830 | end |
| 1831 | ret rmdir rlsrc 0 sl |
| 1832 | end |
| 1833 | ret unlink rlsrc 0 sl |
| 1834 | end |
| 1835 | |
| 1836 | note Empty the directory rlsrc[0, sl): read one batch, remove it, again until a batch |
| 1837 | note holds only . and .. |
| 1838 | fn rl_rmdl sl ulong dp ulong to long |
| 1839 | bf = new uchar 8192 0 |
| 1840 | for it ulong 1000000 |
| 1841 | fd = fopen rlsrc 0 sl 573440 0 |
| 1842 | if lt fd 0 |
| 1843 | ret fd |
| 1844 | end |
| 1845 | k = getdnts int fd bf 0 8192 |
| 1846 | rl_close fd |
| 1847 | if lt k 0 |
| 1848 | ret k |
| 1849 | end |
| 1850 | c = ulong 0 |
| 1851 | off = ulong 0 |
| 1852 | while lt off ulong k bound 8192 |
| 1853 | r = rl_rme bf off sl dp |
| 1854 | if lt r 0 |
| 1855 | ret r |
| 1856 | end |
| 1857 | c = add c ulong r |
| 1858 | off = add off rl_rec bf off |
| 1859 | end |
| 1860 | if eq c 0 |
| 1861 | ret 0 |
| 1862 | end |
| 1863 | end |
| 1864 | ret -11 |
| 1865 | end |
| 1866 | |
| 1867 | note Remove the entry at bf[off + 19..) of rlsrc[0, sl): 1 removed, 0 . or .., or an error. |
| 1868 | fn rl_rme bf view uchar 8192 off ulong sl ulong dp ulong to long |
| 1869 | s = add off 19 |
| 1870 | e = s |
| 1871 | while ne get bf e 0 bound 8192 |
| 1872 | e = add e 1 |
| 1873 | end |
| 1874 | k = sub e s |
| 1875 | if le k 2 |
| 1876 | if eq get bf s 46 |
| 1877 | if eq k 1 |
| 1878 | ret 0 |
| 1879 | end |
| 1880 | if eq get bf add s 1 46 |
| 1881 | ret 0 |
| 1882 | end |
| 1883 | end |
| 1884 | end |
| 1885 | if gt add add sl k 1 4095 |
| 1886 | ret -36 |
| 1887 | end |
| 1888 | put rlsrc sl 47 |
| 1889 | for i ulong k |
| 1890 | put rlsrc add add sl 1 i get bf add s i |
| 1891 | end |
| 1892 | r = rl_rmt add add sl k 1 add dp 1 |
| 1893 | if lt r 0 |
| 1894 | ret r |
| 1895 | end |
| 1896 | ret 1 |
| 1897 | end |
| 1898 | |
| 1899 | note rlsrc = argument i "/" nm, or rldst when ds; the length. |
| 1900 | fn rl_setp i ulong nm view uchar * ds bool to ulong |
| 1901 | b = new uchar 4096 0 |
| 1902 | n = rl_arg i b |
| 1903 | put b n 47 |
| 1904 | n = rl_cat b add n 1 nm |
| 1905 | if gt n 4095 |
| 1906 | rl_die rlmlong 2 |
| 1907 | end |
| 1908 | for j ulong n |
| 1909 | if ds |
| 1910 | put rldst j get b j |
| 1911 | else |
| 1912 | put rlsrc j get b j |
| 1913 | end |
| 1914 | end |
| 1915 | ret n |
| 1916 | end |
| 1917 | |
| 1918 | note Die "MSG<argument i>/nm (error r)". |
| 1919 | fn rl_dief m view uchar * i ulong nm view uchar * r long to void |
| 1920 | o = new uchar 8192 0 |
| 1921 | p = rl_cat o 0 m |
| 1922 | q = rl_arg i part o p 4096 |
| 1923 | p = add p q |
| 1924 | put o p 47 |
| 1925 | p = rl_cat o add p 1 nm |
| 1926 | p = rl_cat o p rlmerr |
| 1927 | p = rl_dec o p ulong neg r |
| 1928 | p = rl_cat o p rlmcl |
| 1929 | rl_die part o 0 p 1 |
| 1930 | end |
| 1931 | |
| 1932 | note Copy argument si "/" nm to argument di "/" nm. |
| 1933 | fn rl_cp1 si ulong di ulong nm view uchar * to void |
| 1934 | sl = rl_setp si nm false |
| 1935 | dl = rl_setp di nm true |
| 1936 | r = rl_cpt sl dl 0 |
| 1937 | if lt r 0 |
| 1938 | rl_dief rlmcp si nm r |
| 1939 | end |
| 1940 | end |
| 1941 | |
| 1942 | note Remove argument i "/" nm. |
| 1943 | fn rl_rm1 i ulong nm view uchar * to void |
| 1944 | sl = rl_setp i nm false |
| 1945 | r = rl_rmt sl 0 |
| 1946 | if lt r 0 |
| 1947 | rl_dief rlmrm i nm r |
| 1948 | end |
| 1949 | end |
| 1950 | |
| 1951 | note Die unless argument i "/" nm is a directory. |
| 1952 | fn rl_isd1 i ulong nm view uchar * to void |
| 1953 | b = new uchar 4096 0 |
| 1954 | n = rl_arg i b |
| 1955 | put b n 47 |
| 1956 | n = rl_cat b add n 1 nm |
| 1957 | if rl_isdir part b 0 n |
| 1958 | ret |
| 1959 | end |
| 1960 | o = new uchar 8192 0 |
| 1961 | p = rl_cat o 0 rlmsnap |
| 1962 | p = rl_cat o p part b 0 n |
| 1963 | rl_die part o 0 p 1 |
| 1964 | end |
| 1965 | |
| 1966 | note "snapshot SNAP files F dirs D links L bytes B" (or rollback STATE ...). |
| 1967 | fn rl_copied lb view uchar * i ulong to void |
| 1968 | o = new uchar 8192 0 |
| 1969 | p = rl_cat o 0 lb |
| 1970 | q = rl_arg i part o p 4096 |
| 1971 | p = add p q |
| 1972 | p = rl_cat o p rlocf |
| 1973 | p = rl_dec o p get rlcn 0 |
| 1974 | p = rl_cat o p rlocd |
| 1975 | p = rl_dec o p get rlcn 1 |
| 1976 | p = rl_cat o p rlocl |
| 1977 | p = rl_dec o p get rlcn 2 |
| 1978 | p = rl_cat o p rlocb |
| 1979 | p = rl_dec o p get rlcn 3 |
| 1980 | p = rl_cat o p rlnl |
| 1981 | x = rl_wall 1 part o 0 p |
| 1982 | end |
| 1983 | |
| 1984 | fn rl_snap to int |
| 1985 | b = new uchar 4096 0 |
| 1986 | if ne argcnt 4 |
| 1987 | rl_die rlusr 2 |
| 1988 | end |
| 1989 | if rl_alive rlnpid |
| 1990 | rl_diep rlmnrun rlnpid 3 |
| 1991 | end |
| 1992 | n = rl_arg 3 b |
| 1993 | r = rl_mkp part b 0 n |
| 1994 | if lt r 0 |
| 1995 | rl_diea rlmdir 3 1 |
| 1996 | end |
| 1997 | rl_cp1 2 3 rlroot |
| 1998 | rl_cp1 2 3 rlwork |
| 1999 | rl_cp1 2 3 rljour |
| 2000 | rl_copied rlosn 3 |
| 2001 | ret 0 |
| 2002 | end |
| 2003 | |
| 2004 | fn rl_rollb to int |
| 2005 | if ne argcnt 4 |
| 2006 | rl_die rlusr 2 |
| 2007 | end |
| 2008 | if rl_alive rlnpid |
| 2009 | rl_diep rlmnrun rlnpid 3 |
| 2010 | end |
| 2011 | rl_isd1 3 rlroot |
| 2012 | rl_isd1 3 rlwork |
| 2013 | rl_isd1 3 rljour |
| 2014 | rl_rm1 2 rlroot |
| 2015 | rl_cp1 3 2 rlroot |
| 2016 | rl_rm1 2 rlwork |
| 2017 | rl_cp1 3 2 rlwork |
| 2018 | rl_rm1 2 rljour |
| 2019 | rl_cp1 3 2 rljour |
| 2020 | rl_copied rlorb 2 |
| 2021 | ret 0 |
| 2022 | end |
| 2023 | |
| 2024 | note ======== main |
| 2025 | |
| 2026 | fn main to int |
| 2027 | c = new uchar 4096 0 |
| 2028 | if lt argcnt 3 |
| 2029 | rl_die rlusage 2 |
| 2030 | end |
| 2031 | n = rl_arg 1 c |
| 2032 | if rl_eq part c 0 n rlcbld |
| 2033 | ret rl_build |
| 2034 | end |
| 2035 | if rl_eq part c 0 n rlcsrv |
| 2036 | ret rl_serve |
| 2037 | end |
| 2038 | if rl_eq part c 0 n rlcsta |
| 2039 | ret rl_start |
| 2040 | end |
| 2041 | if rl_eq part c 0 n rlchlt |
| 2042 | ret rl_health |
| 2043 | end |
| 2044 | if rl_eq part c 0 n rlcstp |
| 2045 | ret rl_stop |
| 2046 | end |
| 2047 | if rl_eq part c 0 n rlcres |
| 2048 | ret rl_rest |
| 2049 | end |
| 2050 | if rl_eq part c 0 n rlcuns |
| 2051 | ret rl_unsrv |
| 2052 | end |
| 2053 | if rl_eq part c 0 n rlcsnp |
| 2054 | ret rl_snap |
| 2055 | end |
| 2056 | if rl_eq part c 0 n rlcrb |
| 2057 | ret rl_rollb |
| 2058 | end |
| 2059 | rl_diea rlmunk 1 2 |
| 2060 | ret 2 |
| 2061 | end |