Commit c043845
committed
feat(ffi): C ABI for streaming-stdio popen — sandlock_popen + handle_kill
Second piece of the streaming-stdio process API (RFC #67): expose the core
Sandbox::popen over the C ABI so the Python/Go bindings can drive a confined
process's stdio while it runs. The Python/Go wrapper follows as the next PR in
the series; this lands the C surface it builds on.
- sandlock_popen(policy, name, argv, argc, stdin_mode, stdout_mode,
stderr_mode, out_stdin_fd, out_stdout_fd, out_stderr_fd): create+start a
live handle with per-stream StdioMode (0=inherit, 1=piped, 2=null). Each
piped stream's owned fd is returned through its out pointer; inherit/null
yield -1. Uses the multi-threaded live runtime so the supervisor keeps
pumping while the caller blocks on the fds.
- sandlock_handle_kill: SIGKILL the handle's process group without freeing
the handle, so the caller can still collect the exit status via
sandlock_handle_wait.
- Existing sandlock_handle_wait/_pid/_free already cover popen handles; their
safety docs now name sandlock_popen as a second handle source.
Fail-loud / no-leak (the binding boundary): an unknown StdioMode returns a
null handle with every out fd left -1 and logs the rejected discriminant to
stderr (not swallowed into an indistinguishable null); a piped fd whose out
pointer is null is closed rather than leaked. The owned fds are converted to
raw ints only on the infallible side of the result match, so an error return
drops and closes them instead of leaking a dangling fd.
Because the FFI always takes each piped stream, the core wait()-time stdin
EOF safety net cannot fire here, so the deadlock warning (close a piped stdin
and drain piped stdout/stderr before wait) is carried explicitly on the
sandlock_popen and sandlock_handle_wait docs.
Header regenerated with cbindgen (additive only, doc-only delta). Tests drive
the symbols directly: stdout streaming + exit, stdin/stdout roundtrip through
cat, stderr piped, Null yields no fd, unknown mode rejected with out fds reset,
the kill lifecycle (kill->wait->free, kill->free without wait, idempotent kill),
and a destructive fd-leak test (PIPED stream with a null out pointer must close
its fd — verified to fail if the close branch regresses).
Refs #671 parent e7f2993 commit c043845
3 files changed
Lines changed: 624 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
684 | 684 | | |
685 | 685 | | |
686 | 686 | | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
687 | 723 | | |
688 | 724 | | |
689 | 725 | | |
| |||
701 | 737 | | |
702 | 738 | | |
703 | 739 | | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
704 | 751 | | |
705 | 752 | | |
706 | 753 | | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
707 | 758 | | |
708 | | - | |
| 759 | + | |
709 | 760 | | |
710 | 761 | | |
711 | 762 | | |
| |||
733 | 784 | | |
734 | 785 | | |
735 | 786 | | |
736 | | - | |
| 787 | + | |
737 | 788 | | |
738 | 789 | | |
739 | 790 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
1098 | 1098 | | |
1099 | 1099 | | |
1100 | 1100 | | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
1101 | 1236 | | |
1102 | 1237 | | |
1103 | 1238 | | |
| |||
1127 | 1262 | | |
1128 | 1263 | | |
1129 | 1264 | | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
1130 | 1284 | | |
1131 | 1285 | | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
1132 | 1290 | | |
1133 | | - | |
| 1291 | + | |
1134 | 1292 | | |
1135 | 1293 | | |
1136 | 1294 | | |
| |||
1211 | 1369 | | |
1212 | 1370 | | |
1213 | 1371 | | |
1214 | | - | |
| 1372 | + | |
1215 | 1373 | | |
1216 | 1374 | | |
1217 | 1375 | | |
| |||
0 commit comments