Skip to content

Commit 2f1912c

Browse files
Switch to posix_spawnp for macOS background launch to enable PATH lookup (AcademySoftwareFoundation#4834)
Switch to posix_spawnp for macOS background launch to enable PATH lookup, this is a fix for: AcademySoftwareFoundation#4640 Description: Previously, the code used posix_spawn with argv[0] as the executable name. This failed when argv[0] was not an absolute or relative path (e.g., just "iv"), because posix_spawn does not perform PATH lookups. Switched to posix_spawnp, which behaves like execvp and searches PATH when argv[0] does not contain a '/' character. This allows the program to re-spawn in the background using the original command name, without requiring _NSGetExecutablePath() to resolve the full path. Signed-off-by: Mikael Sundell <mikael.sundell@gmail.com>
1 parent 09e88ab commit 2f1912c

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/libutil/sysutil.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ Term::ansi_bgcolor(int r, int g, int b)
525525
return ret;
526526
}
527527

528+
529+
528530
bool
529531
Sysutil::put_in_background()
530532
{
@@ -547,7 +549,7 @@ Sysutil::put_in_background()
547549
posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSID);
548550
char** argv = *_NSGetArgv();
549551
char** environ = *_NSGetEnviron();
550-
int status = posix_spawn(&pid, argv[0], nullptr, &attr, argv, environ);
552+
int status = posix_spawnp(&pid, argv[0], nullptr, &attr, argv, environ);
551553
posix_spawnattr_destroy(&attr);
552554
if (status == 0)
553555
exit(0);
@@ -564,6 +566,7 @@ Sysutil::put_in_background()
564566
}
565567

566568

569+
567570
bool
568571
Sysutil::put_in_background(int argc, char* argv[])
569572
{

0 commit comments

Comments
 (0)