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 22f989acf..e5dc06676 100644
  3. --- a/modules/juce_core/native/juce_linux_Files.cpp
  4. +++ b/modules/juce_core/native/juce_linux_Files.cpp
  5. @@ -223,15 +223,21 @@ bool Process::openDocument (const String& fileName, const String& parameters)
  6. const char* const argv[] = { "/bin/sh", "-c", cmdString.toUTF8(), nullptr };
  7. +#if JUCE_USE_VFORK
  8. + const auto cpid = vfork();
  9. +#else
  10. const auto cpid = fork();
  11. +#endif
  12. if (cpid == 0)
  13. {
  14. +#if ! JUCE_USE_VFORK
  15. setsid();
  16. +#endif
  17. // Child process
  18. - execve (argv[0], (char**) argv, environ);
  19. - exit (0);
  20. + if (execve (argv[0], (char**) argv, environ) < 0)
  21. + _exit (0);
  22. }
  23. return cpid >= 0;
  24. diff --git a/modules/juce_core/native/juce_mac_Files.mm b/modules/juce_core/native/juce_mac_Files.mm
  25. index eff20c841..f67e7871a 100644
  26. --- a/modules/juce_core/native/juce_mac_Files.mm
  27. +++ b/modules/juce_core/native/juce_mac_Files.mm
  28. @@ -92,23 +92,22 @@ namespace MacFileHelpers
  29. #else
  30. static bool launchExecutable (const String& pathAndArguments)
  31. {
  32. - auto cpid = fork();
  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. + const 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 8bdfd4629..2e96f3b04 100644
  62. --- a/modules/juce_core/native/juce_posix_SharedCode.h
  63. +++ b/modules/juce_core/native/juce_posix_SharedCode.h
  64. @@ -1125,7 +1125,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. @@ -1134,6 +1145,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. @@ -1148,17 +1160,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. {