diff --git a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp index 635dbb14a0271692d21b7105152f23f3b965ab85..6554df539ca3aa44ed2ecb5881a86dbe5425ad02 100644 --- a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp +++ b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp @@ -20,6 +20,9 @@ #include #include #include +#ifdef __OHOS_FAMILY__ +#include +#endif #include #include @@ -179,8 +182,21 @@ struct ForkLaunchInfo { // Don't close first three entries since they are stdin, stdout and // stderr. + #ifdef __OHOS_FAMILY__ + //OHOS_LOCAL begin + //Also do not close the directory itself since it would be + // closed after iteration. + //Here iter.get_handler() would return a int_ptr type, + //while dirfd() aacepts DIR* type to return the fd, so we use + //reinterpret_cast to cast the iter.get_handler() to DIR*. + int dir_fd = dirfd(reinterpret_cast(iter.get_handler())); + if (fd > 2 && !info.has_action(fd) && fd != error_fd && dir_fd != fd) + //OHOS_LOCAL end + #else if (fd > 2 && !info.has_action(fd) && fd != error_fd) + #endif files_to_close.push_back(fd); + } for (int file_to_close : files_to_close) close(file_to_close); diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h index 033482977a105cae0af9466a0d42756aec9b1116..55783ac776f9d979dedd897ca782e02771fb26db 100644 --- a/llvm/include/llvm/Support/FileSystem.h +++ b/llvm/include/llvm/Support/FileSystem.h @@ -1451,6 +1451,12 @@ public: return *this; } + // OHOS_LOCAL begin + intptr_t get_handler() { + return State->IterationHandle; + } + // OHOS_LOCAL end + const directory_entry &operator*() const { return State->CurrentEntry; } const directory_entry *operator->() const { return &State->CurrentEntry; }