| @@ -1127,20 +1127,19 @@ class ChildProcess::ActiveProcess | |||||
| { | { | ||||
| public: | public: | ||||
| ActiveProcess (const StringArray& arguments, int streamFlags) | ActiveProcess (const StringArray& arguments, int streamFlags) | ||||
| : childPID (0), pipeHandle (0), readHandle (0) | |||||
| { | { | ||||
| String exe (arguments[0].unquoted()); | |||||
| auto exe = arguments[0].unquoted(); | |||||
| // Looks like you're trying to launch a non-existent exe or a folder (perhaps on OSX | // Looks like you're trying to launch a non-existent exe or a folder (perhaps on OSX | ||||
| // you're trying to launch the .app folder rather than the actual binary inside it?) | // you're trying to launch the .app folder rather than the actual binary inside it?) | ||||
| jassert (File::getCurrentWorkingDirectory().getChildFile (exe).existsAsFile() | jassert (File::getCurrentWorkingDirectory().getChildFile (exe).existsAsFile() | ||||
| || ! exe.containsChar (File::getSeparatorChar())); | || ! exe.containsChar (File::getSeparatorChar())); | ||||
| int pipeHandles[2] = { 0 }; | |||||
| int pipeHandles[2] = {}; | |||||
| if (pipe (pipeHandles) == 0) | if (pipe (pipeHandles) == 0) | ||||
| { | { | ||||
| const pid_t result = fork(); | |||||
| auto result = fork(); | |||||
| if (result < 0) | if (result < 0) | ||||
| { | { | ||||
| @@ -1165,9 +1164,10 @@ public: | |||||
| close (pipeHandles[1]); | close (pipeHandles[1]); | ||||
| Array<char*> argv; | Array<char*> argv; | ||||
| for (int i = 0; i < arguments.size(); ++i) | |||||
| if (arguments[i].isNotEmpty()) | |||||
| argv.add (const_cast<char*> (arguments[i].toRawUTF8())); | |||||
| for (auto& arg : arguments) | |||||
| if (arg.isNotEmpty()) | |||||
| argv.add (const_cast<char*> (arg.toRawUTF8())); | |||||
| argv.add (nullptr); | argv.add (nullptr); | ||||
| @@ -1186,7 +1186,7 @@ public: | |||||
| ~ActiveProcess() | ~ActiveProcess() | ||||
| { | { | ||||
| if (readHandle != 0) | |||||
| if (readHandle != nullptr) | |||||
| fclose (readHandle); | fclose (readHandle); | ||||
| if (pipeHandle != 0) | if (pipeHandle != 0) | ||||
| @@ -1195,28 +1195,26 @@ public: | |||||
| bool isRunning() const noexcept | bool isRunning() const noexcept | ||||
| { | { | ||||
| if (childPID != 0) | |||||
| { | |||||
| int childState; | |||||
| const int pid = waitpid (childPID, &childState, WNOHANG); | |||||
| return pid == 0 || ! (WIFEXITED (childState) || WIFSIGNALED (childState)); | |||||
| } | |||||
| if (childPID == 0) | |||||
| return false; | |||||
| return false; | |||||
| int childState; | |||||
| auto pid = waitpid (childPID, &childState, WNOHANG); | |||||
| return pid == 0 || ! (WIFEXITED (childState) || WIFSIGNALED (childState)); | |||||
| } | } | ||||
| int read (void* const dest, const int numBytes) noexcept | |||||
| int read (void* dest, int numBytes) noexcept | |||||
| { | { | ||||
| jassert (dest != nullptr); | |||||
| jassert (dest != nullptr && numBytes > 0); | |||||
| #ifdef fdopen | #ifdef fdopen | ||||
| #error // the zlib headers define this function as NULL! | |||||
| #error // some crazy 3rd party headers (e.g. zlib) define this function as NULL! | |||||
| #endif | #endif | ||||
| if (readHandle == 0 && childPID != 0) | |||||
| if (childPID != 0) | |||||
| readHandle = fdopen (pipeHandle, "r"); | readHandle = fdopen (pipeHandle, "r"); | ||||
| if (readHandle != 0) | |||||
| if (readHandle != nullptr) | |||||
| return (int) fread (dest, 1, (size_t) numBytes, readHandle); | return (int) fread (dest, 1, (size_t) numBytes, readHandle); | ||||
| return 0; | return 0; | ||||
| @@ -1232,7 +1230,7 @@ public: | |||||
| if (childPID != 0) | if (childPID != 0) | ||||
| { | { | ||||
| int childState = 0; | int childState = 0; | ||||
| const int pid = waitpid (childPID, &childState, WNOHANG); | |||||
| auto pid = waitpid (childPID, &childState, WNOHANG); | |||||
| if (pid >= 0 && WIFEXITED (childState)) | if (pid >= 0 && WIFEXITED (childState)) | ||||
| return WEXITSTATUS (childState); | return WEXITSTATUS (childState); | ||||
| @@ -1241,11 +1239,9 @@ public: | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| int childPID; | |||||
| private: | |||||
| int pipeHandle; | |||||
| FILE* readHandle; | |||||
| int childPID = 0; | |||||
| int pipeHandle = 0; | |||||
| FILE* readHandle = {}; | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ActiveProcess) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ActiveProcess) | ||||
| }; | }; | ||||