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.

119 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 f661e4ab4..dce73fcc2 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 aefa76317..066c12cde 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. + const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), nullptr };
  33. +
  34. +#if JUCE_USE_VFORK
  35. + const auto cpid = vfork();
  36. +#else
  37. auto cpid = fork();
  38. +#endif
  39. if (cpid == 0)
  40. {
  41. - const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), nullptr };
  42. -
  43. // Child process
  44. - if (execve (argv[0], (char**) argv, nullptr) < 0)
  45. - exit (0);
  46. - }
  47. - else
  48. - {
  49. - if (cpid < 0)
  50. - return false;
  51. + if (execvp (argv[0], (char**) argv) < 0)
  52. + _exit (0);
  53. }
  54. - return true;
  55. + return cpid >= 0;
  56. }
  57. #endif
  58. }
  59. diff --git a/modules/juce_core/native/juce_posix_SharedCode.h b/modules/juce_core/native/juce_posix_SharedCode.h
  60. index f3a8f061b..bcd3eab59 100644
  61. --- a/modules/juce_core/native/juce_posix_SharedCode.h
  62. +++ b/modules/juce_core/native/juce_posix_SharedCode.h
  63. @@ -1125,7 +1125,18 @@ public:
  64. if (pipe (pipeHandles) == 0)
  65. {
  66. - auto result = fork();
  67. + Array<char*> argv;
  68. + for (auto& arg : arguments)
  69. + if (arg.isNotEmpty())
  70. + argv.add (const_cast<char*> (arg.toRawUTF8()));
  71. +
  72. + argv.add (nullptr);
  73. +
  74. +#if JUCE_USE_VFORK
  75. + const pid_t result = vfork();
  76. +#else
  77. + const pid_t result = fork();
  78. +#endif
  79. if (result < 0)
  80. {
  81. @@ -1134,6 +1145,7 @@ public:
  82. }
  83. else if (result == 0)
  84. {
  85. +#if ! JUCE_USE_VFORK
  86. // we're the child process..
  87. close (pipeHandles[0]); // close the read handle
  88. @@ -1148,17 +1160,10 @@ public:
  89. dup2 (open ("/dev/null", O_WRONLY), STDERR_FILENO);
  90. close (pipeHandles[1]);
  91. +#endif
  92. - Array<char*> argv;
  93. -
  94. - for (auto& arg : arguments)
  95. - if (arg.isNotEmpty())
  96. - argv.add (const_cast<char*> (arg.toRawUTF8()));
  97. -
  98. - argv.add (nullptr);
  99. -
  100. - execvp (exe.toRawUTF8(), argv.getRawDataPointer());
  101. - _exit (-1);
  102. + if (execvp (exe.toRawUTF8(), argv.getRawDataPointer()) < 0)
  103. + _exit (-1);
  104. }
  105. else
  106. {