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/omega-mv/blob/main/seed/authority/lock-test.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / authority / lock-test.om` 138 lines ยท 2398 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note Lock checks: exclusive acquire, busy refusal, release, a forked waiter, stale-pid reclaim, failed release, 3 note an owner pid equal to an old lread error code (32), and the lacq retry cap. 4 text passm "lock checks=10 fails=0\n" 5 global checks ulong 1 6 global fails ulong 1 7 global lbuf uchar 8 8 global rb uchar 8 9 text childf "build/authority-store/lock.child" 10 text bd "build" 11 text ad "build/authority-store" 12 fn check got ulong want ulong to void 13 put checks 0 add get checks 0 1 14 if ne got want 15 put fails 0 add get fails 0 1 16 end 17 end 18 fn cbyte c uchar to void 19 r = fopen childf 0 len childf 0 0 20 if lt r 0 21 put rb 0 255 22 ret 23 end 24 n = read int r rb 0 1 25 if ne fclose int r 0 26 ret 27 end 28 end 29 fn main to int 30 r = makedir bd 0 len bd 448 31 if or eq r 0 eq r -17 32 else 33 ret 90 34 end 35 r = makedir ad 0 len ad 448 36 if or eq r 0 eq r -17 37 else 38 ret 91 39 end 40 u = lrel 41 u = ltry ulong getpid 42 check u 0 43 u = ltry ulong getpid 44 check u 20 45 u = lrel 46 if ne u 0 47 ret 92 48 end 49 u = ltry ulong getpid 50 check u 0 51 pid = fork 52 if lt pid 0 53 ret 93 54 end 55 if eq pid 0 56 u = lacq ulong getpid 1000 57 put lbuf 0 uchar u 58 fd = fopen childf 0 len childf 577 384 59 if lt fd 0 60 exit 94 61 end 62 n = write int fd lbuf 0 1 63 if ne n 1 64 exit 95 65 end 66 exit 0 67 end 68 if ne sleepns `50000000` 0 69 ret 96 70 end 71 u = lrel 72 if ne u 0 73 ret 97 74 end 75 wr = waitpid int pid lbuf 0 8 0 76 if ne wr long pid 77 ret 98 78 end 79 cbyte 0 80 check ulong get rb 0 0 81 note Owner pid 32 was once read back as lread error 32 and refused with 40; it is a real pid now. 82 lpid 32 83 fd = fopen lpath 0 len lpath 577 384 84 if lt fd 0 85 ret 103 86 end 87 n = write int fd lb 0 8 88 if ne n 8 89 ret 104 90 end 91 if ne fclose int fd 0 92 ret 105 93 end 94 want = ulong 20 95 if eq killpid 32 0 -3 96 want = ulong 0 97 end 98 u = ltry ulong getpid 99 check u want 100 u = lacq ulong getpid 1001 101 check u 43 102 lpid 999999 103 fd = fopen lpath 0 len lpath 577 384 104 if lt fd 0 105 ret 99 106 end 107 n = write int fd lb 0 8 108 if ne n 8 109 ret 100 110 end 111 u = ltry ulong getpid 112 check u 0 113 u = lrel 114 check u 0 115 note A directory cannot be unlinked as a regular file, even when run as root. 116 note Refuse a pre-existing fixture rather than replacing anything at this path. 117 r = makedir lpath 0 len lpath 448 118 if ne r 0 119 ret 101 120 end 121 u = lrel 122 check u 41 123 r = rmdir lpath 0 len lpath 124 if ne r 0 125 ret 102 126 end 127 note Missing-path removal is also a failure, not an idempotent success. 128 u = lrel 129 check u 41 130 if ne get fails 0 0 131 ret 1 132 end 133 nw = write 1 passm 0 len passm 134 if ne nw long len passm 135 ret 2 136 end 137 ret 0 138 end