Skip to content

Commit 197ab2d

Browse files
committed
fix(dispatcher): in swap context, execv directly to swapped Python for python/pip shim calls
1 parent 04c7ff9 commit 197ab2d

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/omnipkg/dispatcher.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,20 @@ int main(int argc, char **argv) {
12551255
/* ── 2. Shim mode? Fall back immediately ──────────────────── */
12561256
if (strncmp(prog, "python", 6) == 0 || strcmp(prog, "pip") == 0) {
12571257
if (debug) fprintf(stderr, "[C-DISPATCH] shim mode → python fallback\n");
1258+
/* In swap context, execv directly to the swapped Python — don't wrap in dispatcher */
1259+
const char *swap_active = getenv("_OMNIPKG_SWAP_ACTIVE");
1260+
const char *swap_ver = getenv("OMNIPKG_PYTHON");
1261+
if (swap_active && swap_ver && venv_root[0]) {
1262+
char swap_py[MAX_PATH] = "";
1263+
registry_lookup(venv_root, swap_ver, swap_py, sizeof(swap_py));
1264+
if (swap_py[0] && file_exists(swap_py)) {
1265+
if (debug) fprintf(stderr, "[C-DISPATCH] swap shim → execv %s\n", swap_py);
1266+
argv[0] = swap_py;
1267+
execv(swap_py, argv);
1268+
perror("omnipkg: execv swap python failed");
1269+
exit(1);
1270+
}
1271+
}
12581272
fallback_to_python(self_dir, argv);
12591273
}
12601274

src/omnipkg/dispatcher.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,6 @@ def _ensure_interpreter_config(interpreter_path: Path, version: str, venv_root:
869869
print(f"[DEBUG-DISPATCH] ⚠️ Could not write config for {version}: {e}", file=sys.stderr)
870870
# Non-fatal — _load_or_create_config will handle it via fallback
871871

872-
873872
def spawn_swap_shell(version: str, python_path: Path, pkg_instance) -> int:
874873
"""
875874
Spawn an interactive sub-shell with the swapped Python context.

0 commit comments

Comments
 (0)