Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/spark-connector/blob/main/runner/50cmd.om # spark-connector aien-dev/spark-connector Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `spark-connector / runner / 50cmd.om` 754 lines ยท 14708 bytes Raw Blame History 1 note runner/50cmd.om -- the commands: join, start, stop, status, set rate N, leave, once, selftest. 2 note The background runner is this program: start forks, the child calls setsid and becomes the 3 note supervisor (r_loop). For each cycle the supervisor forks a worker that does one job (r_job) and 4 note exits; a worker that dies takes nothing else with it. There is no systemd unit and no cron: 5 note after the computer restarts, `interplane-runner start` runs it again. 6 7 text rtset "settings" 8 text rtpid "runner.pid" 9 text rtlog "log" 10 text rtlog1 "log.1" 11 text rtsetnew "settings.new" 12 text rtpidnew "runner.pid.new" 13 text rtbinr "bin/interplane-runner" 14 text rtbino "bin/omc" 15 text rtbinrp "bin/interplane-runner.part" 16 text rtbinop "bin/omc.part" 17 text rtbusy "The background runner is working on this computer; stop it first (interplane-runner stop).\n" 18 text rtbin "bin" 19 text rtdefh "https://interplane.io" 20 text rthubk "hub " 21 text rtratek "rate " 22 text rtregn "register" 23 text rtpubn "pub" 24 text rtraten "rate" 25 text rtleave "leave" 26 text rtokreg "ipcc1 ok registered\n" 27 text rtokleft "ipcc1 ok left\n" 28 text rtdevnul "/dev/null" 29 text rtself "/proc/self/exe" 30 text rtproc "/proc/" 31 text rtexe "/exe" 32 text rtselfn "selftest" 33 text rtselfs "text m \"interplane cell ok\\n\"\nfn main to int\nk = write 1 m 0 len m\nret 0\nend\n" 34 text rtselfo "interplane cell ok\n" 35 text rtexit0 "0" 36 37 text rtusage "usage: interplane-runner join [HUB] | start | stop | status | set rate N | leave | once | selftest\n" 38 text rtnohome "interplane-runner: HOME is not set to an absolute path\n" 39 40 text rtj1 "\nInterplane runner: what joining does to this computer\n\nThis computer will check small public programs that people share on Interplane, and tell\nInterplane what it got, so anyone can see whether the result is the same on other machines.\n\n- It asks " 41 text rtj2 " for work. Nothing from outside can connect to this computer.\n- Each check builds one small public Omega program and runs its example in a sealed box:\n no network, none of your files, no environment variables, no GPU, no other programs.\n- Each check takes at most 2 seconds of one CPU core to build and 2 to run, 128 MiB of address space (the most memory it can reserve),\n 1 MiB of output, and 3 seconds of clock time for each of the two steps. These are fixed.\n- Everything it keeps is in " 42 text rtj3 " (under 10 MiB).\n- It makes a key here. The secret part never leaves this computer; Interplane only sees\n the public part, which is how your results are told apart from everyone else's.\n\nYour setting: at most " 43 text rtj4 " checks an hour, so at most " 44 text rtj5 " CPU-seconds an hour. Change it at any time\n(0 pauses): " 45 text rtj6 "/bin/interplane-runner set rate N\n\nStop: " 46 text rtj7 "/bin/interplane-runner stop\nLeave and remove everything: " 47 text rtj8 "/bin/interplane-runner leave\nIt does not start by itself after this computer restarts; to go on, run\n " 48 text rtj9 "/bin/interplane-runner start\n\nType yes and press Enter to join. Anything else cancels and removes what was downloaded.\n> " 49 text rtjcan "Cancelled. Nothing was registered, and " 50 text rtjcan2 " was removed.\n" 51 text rtjok "\nJoined. This computer's key fingerprint (its public name on Interplane):\n " 52 text rtjok2 "\nIts checks will be listed at " 53 text rtjok3 "/community/\nThe runner is working in the background now.\n" 54 text rtjalr "This computer has already joined.\n" 55 text rtjcell "This computer cannot run the sealed box (it needs Linux 6.2 or newer with Landlock, on 64-bit ARM).\nNothing was registered, and the downloaded files were removed.\n" 56 text rtjomc "The downloaded compiler is not the one Interplane pins (omc sha256 `3ad9f10f`...). Nothing was registered.\n" 57 text rtjreg "Interplane did not accept the registration: " 58 text rtjreg2 "Nothing is left on this computer.\n" 59 text rtjkey "Could not make the key. Nothing was registered.\n" 60 text rtjhub "The hub address is not valid.\n" 61 text rtst1 "Interplane runner\nfolder: " 62 text rtst2 "\nkey: " 63 text rtst3 "\nhub: " 64 text rtst4 "\nsetting: at most " 65 text rtst5 " checks an hour (0 = paused)\nrunning: " 66 text rtyes "yes, process " 67 text rtno "no\n" 68 text rtnotj "Interplane runner: this computer has not joined.\n" 69 text rtstop "Stopped. Start again with: " 70 text rtstop2 "/bin/interplane-runner start\n" 71 text rtstrt "Running in the background, process " 72 text rtstrtf "Could not start the background runner.\n" 73 text rtsetok "Setting saved: at most " 74 text rtsetok2 " checks an hour.\n" 75 text rtsetbad "The rate must be a whole number of checks an hour (0 pauses).\n" 76 text rtleft "Left Interplane. Removed " 77 text rtleft2 "\nInterplane could not be told (the result list keeps the key, which can do nothing more without\nthis computer's secret part, now deleted).\n" 78 text rtselok "cell self-test: pass\n" 79 text rtselno "cell self-test: FAIL\n" 80 81 note ---- settings: "hub \nrate \n" 82 fn r_setsave to bool 83 d = new uchar 1024 0 84 u = new uchar 512 0 85 n = get rgv rhubl 86 for i ulong n bound 512 87 put u i get rhub i 88 end 89 k = r_cp d 0 rthubk 90 k = r_cp d k part u 0 n 91 k = r_cp d k rtnl 92 k = r_cp d k rtratek 93 k = r_dec d k get rgv rrate 94 k = r_cp d k rtnl 95 x = r_path rtset 96 ret r_replace part d 0 k 97 end 98 99 fn r_setload to bool 100 d = new uchar 1024 0 101 x = r_path rtset 102 r = r_rd d 103 if lt r 0 104 ret false 105 end 106 n = ulong r 107 e = ulong 0 108 while lt e n bound 1024 109 if eq get d e 10 110 break 111 end 112 e = add e 1 113 end 114 if or ge e n le e len rthubk 115 ret false 116 end 117 if not r_eq part d 0 len rthubk rthubk 118 ret false 119 end 120 if not r_hubset part d len rthubk sub e len rthubk 121 ret false 122 end 123 s = add e 1 124 f = s 125 while lt f n bound 1024 126 if eq get d f 10 127 break 128 end 129 f = add f 1 130 end 131 if or ge f n le sub f s len rtratek 132 ret false 133 end 134 if not r_eq part d s len rtratek rtratek 135 ret false 136 end 137 v = r_undec part d add s len rtratek sub sub f s len rtratek 138 if eq v `18446744073709551615` 139 ret false 140 end 141 put rgv rrate v 142 ret true 143 end 144 145 note ---- processes 146 fn r_say_dir to void 147 w = write 1 rhm 0 get rgv rhml 148 end 149 150 note r_exe: readlink of path p into o; its length or 0 151 fn r_exe p view uchar * o edit uchar * to ulong 152 r = readlnk p 0 len p o 0 len o 153 if or le r 0 ge r long len o 154 ret 0 155 end 156 ret ulong r 157 end 158 159 note r_isours: pid is a running interplane-runner from this same executable 160 fn r_isours pid ulong to bool 161 p = new uchar 64 0 162 a = new uchar 4096 0 163 b = new uchar 4096 0 164 k = r_cp p 0 rtproc 165 k = r_dec p k pid 166 k = r_cp p k rtexe 167 n = r_exe part p 0 k a 168 m = r_exe rtself b 169 if or eq n 0 eq m 0 170 ret false 171 end 172 ret r_eq part a 0 n part b 0 m 173 end 174 175 note r_pidget: the pid in runner.pid, 0 when there is none or it is not a running runner 176 fn r_pidget to ulong 177 b = new uchar 32 0 178 n = r_path rtpid 179 r = r_rd b 180 if le r 0 181 ret 0 182 end 183 v = r_undec part b 0 ulong r 184 if or eq v 0 gt v `4194304` 185 ret 0 186 end 187 if not r_isours v 188 ret 0 189 end 190 ret v 191 end 192 193 fn r_stop to void 194 pid = r_pidget 195 if ne pid 0 196 x = killpid int neg long pid 15 197 for i ulong 100 198 if ne killpid int pid 0 0 199 break 200 end 201 x = sleepns `50000000` 202 end 203 if eq killpid int pid 0 0 204 x = killpid int neg long pid 9 205 x = sleepns `200000000` 206 end 207 end 208 n = r_path rtpid 209 x = unlink rph 0 n 210 end 211 212 note r_bgio: descriptors 0..2 of the background runner: /dev/null, then the log twice 213 fn r_bgio to void 214 fd = fopen rtdevnul 0 len rtdevnul 524290 0 215 if ge fd 0 216 x = dupfd int fd 0 0 217 x = fclose int fd 218 end 219 n = r_path rtlog 220 fd = fopen rph 0 n rfoapp 384 221 if ge fd 0 222 x = dupfd int fd 1 0 223 x = dupfd int fd 2 0 224 x = fclose int fd 225 end 226 end 227 228 note r_logrot: when the log passes 1 MiB, it becomes log.1 (replacing the older one) and a new log 229 note starts; the volunteer was promised a bounded folder 230 fn r_logrot to void 231 sb = new uchar 128 0 232 r = fstat 1 sb 0 128 233 if lt r 0 234 ret 235 end 236 sz = ulong 0 237 for i ulong 8 238 sz = or sz shl ulong get sb add 48 i mul i 8 239 end 240 if le sz `1048576` 241 ret 242 end 243 a = new uchar 4100 0 244 b = new uchar 4100 0 245 p = new uchar 8300 0 246 x = r_path rtlog 247 na = r_phcp a 248 x = r_path rtlog1 249 nb = r_phcp b 250 put p 0 2 251 put p 1 0 252 k = r_pk p 2 part a 0 na 253 k = r_pk p k part b 0 nb 254 r = renames p 0 k 0 255 r_bgio 256 end 257 258 note r_wpid: write this process's id to runner.pid 259 fn r_wpid to bool 260 d = new uchar 24 0 261 k = r_dec d 0 ulong getpid 262 x = r_path rtpid 263 ret r_replace part d 0 k 264 end 265 266 note r_loop: the supervisor. One worker per cycle; the wait after it follows the volunteer's rate: 267 note after a counted result 3600/rate seconds, after "no work" at least 600 s, after an error a 268 note backoff that doubles from 60 s to 3600 s, after a result the cell could not run (code 3) an 269 note hour, with a line in the log. Rate 0 pauses (checked again every 60 s). The work folder is 270 note removed when the supervisor starts and after each worker has exited (never while a worker 271 note runs), so a job a stop or crash interrupted leaves nothing behind for long. 272 fn r_loop to int 273 st = new uchar 4 0 274 back = ulong 60 275 r_rmnm rtwork 276 while true bound `9223372036854775807` 277 r_logrot 278 if not r_setload 279 ret 0 280 end 281 rate = get rgv rrate 282 if eq rate 0 283 x = sleepns `60000000000` 284 continue 285 end 286 pid = fork 287 if eq pid 0 288 c = r_job 289 exit int c 290 end 291 c = ulong 2 292 if gt pid 0 293 w = waitpid int pid st 0 4 0 294 s = r_u32 st 0 295 if eq and s 127 0 296 c = and shr s 8 255 297 end 298 end 299 r_rmnm rtwork 300 if eq c 3 301 r_logt 302 r_say rtlcellp 303 end 304 iv = div 3600 rate 305 wt = iv 306 if eq c 0 307 back = 60 308 end 309 if eq c 1 310 back = 60 311 if lt wt 600 312 wt = 600 313 end 314 end 315 if gt c 1 316 if lt wt back 317 wt = back 318 end 319 back = mul back 2 320 if gt back 3600 321 back = 3600 322 end 323 end 324 if eq c 3 325 wt = 3600 326 end 327 x = sleepns long mul wt `1000000000` 328 end 329 ret 0 330 end 331 332 note r_start: the background runner (needs the key and settings) 333 fn r_start to bool 334 old = r_pidget 335 if ne old 0 336 r_say rtstrt 337 r_num old 338 r_say rtnl 339 ret true 340 end 341 pid = fork 342 if lt pid 0 343 ret false 344 end 345 if eq pid 0 346 x = setsid 347 r_bgio 348 if not r_wpid 349 exit 1 350 end 351 c = r_loop 352 exit c 353 end 354 for i ulong 40 355 x = sleepns `50000000` 356 if eq r_pidget ulong pid 357 r_say rtstrt 358 r_num ulong pid 359 r_say rtnl 360 ret true 361 end 362 end 363 ret false 364 end 365 366 note ---- hub messages 367 fn r_register to long 368 r_mbeg rtregn 369 p = new uchar 130 0 370 for i ulong 130 371 put p i get rpubh i 372 end 373 r_mline rtpubn p 374 r_mtime 375 r_mnum rtraten get rgv rrate 376 if not r_msign 377 ret -1 378 end 379 ret r_post 380 end 381 382 fn r_sayleave to long 383 r_mbeg rtleave 384 r_mkey 385 r_mtime 386 if not r_msign 387 ret -1 388 end 389 ret r_post 390 end 391 392 note ---- the cell self-test: compile and run a two-line program in the cell 393 fn r_selftest to bool 394 h = new uchar 32 0 395 x = new uchar 64 0 396 if not r_jdir rtselfn 397 ret false 398 end 399 n = r_jpath rtsrc 400 ok = r_wr rtselfs rfonew 384 401 n = r_jpath rtsin 402 e = new uchar 1 0 403 ok = and ok r_wr part e 0 0 rfonew 384 404 if ok 405 ok = r_check 406 end 407 if ok 408 r_sha rtselfo h 409 k = r_hex h x 0 410 ok = and r_jfeq rfout x r_jfeq rfexit rtexit0 411 ok = and ok eq get rgv rexl 1 412 end 413 r_jdel 414 ret ok 415 end 416 417 note ---- commands 418 fn r_yes to bool 419 b = new uchar 64 0 420 n = ulong 0 421 while lt n 63 bound 64 422 r = read 0 b n 1 423 if le r 0 424 break 425 end 426 if eq get b n 10 427 break 428 end 429 n = add n 1 430 end 431 if ne n 3 432 ret false 433 end 434 ret and and eq get b 0 121 eq get b 1 101 eq get b 2 115 435 end 436 437 note r_rmall: remove what the runner and the join line put in the state folder, by name, then the 438 note folder itself (only when that leaves it empty: anything else in it stays) 439 fn r_rmall to void 440 r_rmnm rtkey 441 r_rmnm rtset 442 r_rmnm rtpid 443 r_rmnm rtlog 444 r_rmnm rtlog1 445 r_rmbin 446 r_rmnm rtwork 447 r_rmnm rtsetnew 448 r_rmnm rtpidnew 449 n = r_path rtxnone 450 x = rmdir rph 0 n 451 end 452 453 note r_rmbin: the two files join put in bin/ (and the partial downloads of the join line), then bin/ 454 fn r_rmbin to void 455 r_rmnm rtbinr 456 r_rmnm rtbino 457 r_rmnm rtbinrp 458 r_rmnm rtbinop 459 n = r_path rtbin 460 x = rmdir rph 0 n 461 end 462 463 fn r_rmnm nm view uchar * to void 464 p = new uchar 4100 0 465 n = r_path nm 466 k = r_phcp p 467 x = r_rmtree part p 0 k 468 end 469 470 fn c_join to int 471 u = new uchar 512 0 472 if r_kload 473 r_say rtjalr 474 ret c_status 475 end 476 if ge argcnt 3 477 n = argread 2 u 0 400 478 if le n 0 479 r_say rtjhub 480 ret 2 481 end 482 if not r_hubset part u 0 ulong n 483 r_say rtjhub 484 ret 2 485 end 486 else 487 x = r_hubset rtdefh 488 end 489 put rgv rrate 30 490 if not r_omcok 491 r_say rtjomc 492 r_rmall 493 ret 3 494 end 495 if not r_selftest 496 r_say rtjcell 497 r_rmall 498 ret 3 499 end 500 r_say rtj1 501 w = write 1 rhub 0 get rgv rhubl 502 r_say rtj2 503 r_say_dir 504 r_say rtj3 505 r_num get rgv rrate 506 r_say rtj4 507 r_num mul get rgv rrate 4 508 r_say rtj5 509 r_say_dir 510 r_say rtj6 511 r_say_dir 512 r_say rtj7 513 r_say_dir 514 r_say rtj8 515 r_say_dir 516 r_say rtj9 517 if not r_yes 518 r_say rtjcan 519 r_say_dir 520 r_say rtjcan2 521 r_rmall 522 ret 1 523 end 524 if not r_kgen 525 r_say rtjkey 526 r_rmall 527 ret 4 528 end 529 s = r_register 530 if or ne s 200 not r_rspis rtokreg 531 r_say rtjreg 532 if lt s 0 533 r_say rtxneg 534 r_num ulong neg s 535 else 536 r_rspline 537 end 538 r_say rtnl 539 r_say rtjreg2 540 r_rmall 541 ret 4 542 end 543 if not r_setsave 544 r_rmall 545 ret 4 546 end 547 r_say rtjok 548 w = write 1 rkid 0 64 549 r_say rtjok2 550 w = write 1 rhub 0 get rgv rhubl 551 r_say rtjok3 552 if not r_start 553 r_say rtstrtf 554 ret 5 555 end 556 ret 0 557 end 558 559 fn c_status to int 560 if not r_kload 561 r_say rtnotj 562 ret 1 563 end 564 if not r_setload 565 r_say rtnotj 566 ret 1 567 end 568 r_say rtst1 569 r_say_dir 570 r_say rtst2 571 w = write 1 rkid 0 64 572 r_say rtst3 573 w = write 1 rhub 0 get rgv rhubl 574 r_say rtst4 575 r_num get rgv rrate 576 r_say rtst5 577 pid = r_pidget 578 if eq pid 0 579 r_say rtno 580 else 581 r_say rtyes 582 r_num pid 583 r_say rtnl 584 end 585 ret 0 586 end 587 588 fn c_ready to bool 589 if not r_kload 590 r_say rtnotj 591 ret false 592 end 593 if not r_setload 594 r_say rtnotj 595 ret false 596 end 597 ret true 598 end 599 600 fn c_start to int 601 if not c_ready 602 ret 1 603 end 604 if not r_start 605 r_say rtstrtf 606 ret 5 607 end 608 ret 0 609 end 610 611 fn c_stop to int 612 r_stop 613 r_say rtstop 614 r_say_dir 615 r_say rtstop2 616 ret 0 617 end 618 619 fn c_set to int 620 b = new uchar 32 0 621 if ne argcnt 4 622 r_say rtusage 623 ret 2 624 end 625 n = argread 2 b 0 32 626 if not r_eq part b 0 ulong n rtraten 627 r_say rtusage 628 ret 2 629 end 630 n = argread 3 b 0 32 631 if le n 0 632 r_say rtsetbad 633 ret 2 634 end 635 v = r_undec part b 0 ulong n 636 if eq v `18446744073709551615` 637 r_say rtsetbad 638 ret 2 639 end 640 if not c_ready 641 ret 1 642 end 643 put rgv rrate v 644 if not r_setsave 645 ret 4 646 end 647 s = r_register 648 r_say rtsetok 649 r_num v 650 r_say rtsetok2 651 ret 0 652 end 653 654 fn c_leave to int 655 r_stop 656 told = false 657 if r_kload 658 if r_setload 659 s = r_sayleave 660 told = and eq s 200 r_rspis rtokleft 661 end 662 end 663 r_rmall 664 r_say rtleft 665 r_say_dir 666 r_say rtnl 667 if not told 668 r_say rtleft2 669 end 670 ret 0 671 end 672 673 fn c_once to int 674 if not c_ready 675 ret 1 676 end 677 if ne r_pidget 0 678 r_say rtbusy 679 ret 1 680 end 681 ret int r_job 682 end 683 684 fn c_self to int 685 if r_home 686 if ne r_pidget 0 687 r_say rtbusy 688 ret 1 689 end 690 end 691 x = r_hubset rtdefh 692 if not r_omcok 693 r_say rtjomc 694 ret 3 695 end 696 if r_selftest 697 r_say rtselok 698 ret 0 699 end 700 r_say rtselno 701 ret 3 702 end 703 704 text rcjoin "join" 705 text rcstart "start" 706 text rcstop "stop" 707 text rcstat "status" 708 text rcset "set" 709 text rcleave "leave" 710 text rconce "once" 711 712 fn main to int 713 a = new uchar 16 0 714 if lt argcnt 2 715 r_say rtusage 716 ret 2 717 end 718 n = argread 1 a 0 16 719 if le n 0 720 r_say rtusage 721 ret 2 722 end 723 if not r_home 724 r_say rtnohome 725 ret 2 726 end 727 m = ulong n 728 if r_eq part a 0 m rcjoin 729 ret c_join 730 end 731 if r_eq part a 0 m rcstart 732 ret c_start 733 end 734 if r_eq part a 0 m rcstop 735 ret c_stop 736 end 737 if r_eq part a 0 m rcstat 738 ret c_status 739 end 740 if r_eq part a 0 m rcset 741 ret c_set 742 end 743 if r_eq part a 0 m rcleave 744 ret c_leave 745 end 746 if r_eq part a 0 m rconce 747 ret c_once 748 end 749 if r_eq part a 0 m rtselfn 750 ret c_self 751 end 752 r_say rtusage 753 ret 2 754 end