Repository navigation
Commit 083fc76
committed
Preserve caller cwd in macOS shebang launcher (#293)
The macOS polyglot launcher template (SHEBANG_TPL_MACOS) emulated
`readlink -f` with a cd/readlink loop because macOS's /usr/bin/readlink
predates the -f flag. All those cd's happened in the launcher's own
shell, so by the time it `exec`'d Python the caller's working directory
had been replaced with the install dir. Every entry point relenv
produces for macOS (salt, salt-ssh, salt-call, salt-run, ...) inherited
this cwd, which broke anything resolving relative paths against
os.getcwd(): Saltfile auto-discovery from the current directory,
config_dir: ./..., --config-dir=./..., root_dir: ./, ssh_pre_flight:
./..., and so on.
Confine the symlink-resolution loop to a subshell — its cd's no longer
leak into the parent — and emit the resolved physical path on its
stdout so the parent can capture it. Python is exec'd from the
launcher's untouched cwd.
Verified against the original reproducer in the issue on a real macOS
(Sonoma) box: before, the launcher's Python sees the install dir as
cwd; after, it sees the directory the user invoked the command from.
Linux-side template (SHEBANG_TPL_LINUX) is unaffected — it uses
`readlink -f` directly and never cd's.
Adds tests/test_common.py::test_macos_shebang_preserves_caller_cwd, a
sh-driven integration test that reproduces the symlinked Salt-on-macOS
deployment shape (/usr/local/bin/<cmd> -> /opt/<app>/bin/<cmd>) and
asserts the launcher's Python sees the caller's cwd. The test runs on
any POSIX runner — the launcher polyglot is portable, so a Linux
runner catches the regression too. Confirmed the test fails on the
pre-fix template and passes on the new one.1 parent eff2980 commit 083fc76
2 files changed
Lines changed: 69 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
167 | 170 | | |
168 | | - | |
169 | | - | |
170 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
171 | 179 | | |
172 | 180 | | |
173 | 181 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
319 | 369 | | |
320 | 370 | | |
321 | 371 | | |
| |||
0 commit comments