You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.6KB

  1. diff --git a/modules/juce_core/native/juce_linux_Files.cpp b/modules/juce_core/native/juce_linux_Files.cpp
  2. index d2a302e3e..3dc4602ce 100644
  3. --- a/modules/juce_core/native/juce_linux_Files.cpp
  4. +++ b/modules/juce_core/native/juce_linux_Files.cpp
  5. @@ -211,15 +211,21 @@ bool Process::openDocument (const String& fileName, const String& parameters)
  6. const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), nullptr };
  7. - auto cpid = fork();
  8. +#if JUCE_USE_VFORK
  9. + const auto cpid = vfork();
  10. +#else
  11. + const auto cpid = fork();
  12. +#endif
  13. if (cpid == 0)
  14. {
  15. +#if ! JUCE_USE_VFORK
  16. setsid();
  17. +#endif
  18. // Child process
  19. - execve (argv[0], (char**) argv, environ);
  20. - exit (0);
  21. + if (execvp (argv[0], (char**) argv) < 0)
  22. + _exit (0);
  23. }
  24. return cpid >= 0;
  25. diff --git a/modules/juce_core/native/juce_mac_Files.mm b/modules/juce_core/native/juce_mac_Files.mm
  26. index 1a4d07516..f385a089f 100644
  27. --- a/modules/juce_core/native/juce_mac_Files.mm
  28. +++ b/modules/juce_core/native/juce_mac_Files.mm
  29. @@ -92,23 +92,22 @@ namespace MacFileHelpers
  30. #else
  31. static bool launchExecutable (const String& pathAndArguments)
  32. {
  33. + const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), nullptr };
  34. +
  35. +#if JUCE_USE_VFORK
  36. + const auto cpid = vfork();
  37. +#else
  38. auto cpid = fork();
  39. +#endif
  40. if (cpid == 0)
  41. {
  42. - const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), nullptr };
  43. -
  44. // Child process
  45. - if (execve (argv[0], (char**) argv, nullptr) < 0)
  46. - exit (0);
  47. - }
  48. - else
  49. - {
  50. - if (cpid < 0)
  51. - return false;
  52. + if (execvp (argv[0], (char**) argv) < 0)
  53. + _exit (0);
  54. }
  55. - return true;
  56. + return cpid >= 0;
  57. }
  58. #endif
  59. }
  60. diff --git a/modules/juce_core/native/juce_posix_SharedCode.h b/modules/juce_core/native/juce_posix_SharedCode.h
  61. index c79ca18ea..ad46cf390 100644
  62. --- a/modules/juce_core/native/juce_posix_SharedCode.h
  63. +++ b/modules/juce_core/native/juce_posix_SharedCode.h
  64. @@ -1104,7 +1104,18 @@ public:
  65. if (pipe (pipeHandles) == 0)
  66. {
  67. - auto result = fork();
  68. + Array<char*> argv;
  69. + for (auto& arg : arguments)
  70. + if (arg.isNotEmpty())
  71. + argv.add (const_cast<char*> (arg.toRawUTF8()));
  72. +
  73. + argv.add (nullptr);
  74. +
  75. +#if JUCE_USE_VFORK
  76. + const pid_t result = vfork();
  77. +#else
  78. + const pid_t result = fork();
  79. +#endif
  80. if (result < 0)
  81. {
  82. @@ -1113,6 +1124,7 @@ public:
  83. }
  84. else if (result == 0)
  85. {
  86. +#if ! JUCE_USE_VFORK
  87. // we're the child process..
  88. close (pipeHandles[0]); // close the read handle
  89. @@ -1127,17 +1139,10 @@ public:
  90. dup2 (open ("/dev/null", O_WRONLY), STDERR_FILENO);
  91. close (pipeHandles[1]);
  92. +#endif
  93. - Array<char*> argv;
  94. -
  95. - for (auto& arg : arguments)
  96. - if (arg.isNotEmpty())
  97. - argv.add (const_cast<char*> (arg.toRawUTF8()));
  98. -
  99. - argv.add (nullptr);
  100. -
  101. - execvp (exe.toRawUTF8(), argv.getRawDataPointer());
  102. - _exit (-1);
  103. + if (execvp (exe.toRawUTF8(), argv.getRawDataPointer()) < 0)
  104. + _exit (-1);
  105. }
  106. else
  107. {