diff options
Diffstat (limited to 'source/Host/posix')
-rw-r--r-- | source/Host/posix/ConnectionFileDescriptorPosix.cpp | 57 | ||||
-rw-r--r-- | source/Host/posix/DomainSocket.cpp | 2 | ||||
-rw-r--r-- | source/Host/posix/FileSystem.cpp | 46 | ||||
-rw-r--r-- | source/Host/posix/HostInfoPosix.cpp | 11 | ||||
-rw-r--r-- | source/Host/posix/HostProcessPosix.cpp | 4 | ||||
-rw-r--r-- | source/Host/posix/HostThreadPosix.cpp | 20 |
6 files changed, 85 insertions, 55 deletions
diff --git a/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/source/Host/posix/ConnectionFileDescriptorPosix.cpp index dbbd5a1dcc3c..52d65b1e9a97 100644 --- a/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ b/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -79,12 +79,12 @@ GetURLAddress(const char *url, const char *scheme) } ConnectionFileDescriptor::ConnectionFileDescriptor(bool child_processes_inherit) - : Connection() - , m_pipe() - , m_mutex(Mutex::eMutexTypeRecursive) - , m_shutting_down(false) - , m_waiting_for_accept(false) - , m_child_processes_inherit(child_processes_inherit) + : Connection(), + m_pipe(), + m_mutex(), + m_shutting_down(false), + m_waiting_for_accept(false), + m_child_processes_inherit(child_processes_inherit) { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT)); if (log) @@ -92,30 +92,30 @@ ConnectionFileDescriptor::ConnectionFileDescriptor(bool child_processes_inherit) } ConnectionFileDescriptor::ConnectionFileDescriptor(int fd, bool owns_fd) - : Connection() - , m_pipe() - , m_mutex(Mutex::eMutexTypeRecursive) - , m_shutting_down(false) - , m_waiting_for_accept(false) - , m_child_processes_inherit(false) + : Connection(), + m_pipe(), + m_mutex(), + m_shutting_down(false), + m_waiting_for_accept(false), + m_child_processes_inherit(false) { m_write_sp.reset(new File(fd, owns_fd)); m_read_sp.reset(new File(fd, false)); Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT)); if (log) - log->Printf("%p ConnectionFileDescriptor::ConnectionFileDescriptor (fd = %i, owns_fd = %i)", static_cast<void *>(this), fd, - owns_fd); + log->Printf("%p ConnectionFileDescriptor::ConnectionFileDescriptor (fd = %i, owns_fd = %i)", + static_cast<void *>(this), fd, owns_fd); OpenCommandPipe(); } -ConnectionFileDescriptor::ConnectionFileDescriptor(Socket* socket) - : Connection() - , m_pipe() - , m_mutex(Mutex::eMutexTypeRecursive) - , m_shutting_down(false) - , m_waiting_for_accept(false) - , m_child_processes_inherit(false) +ConnectionFileDescriptor::ConnectionFileDescriptor(Socket *socket) + : Connection(), + m_pipe(), + m_mutex(), + m_shutting_down(false), + m_waiting_for_accept(false), + m_child_processes_inherit(false) { InitializeSocket(socket); } @@ -170,7 +170,7 @@ ConnectionFileDescriptor::IsConnected() const ConnectionStatus ConnectionFileDescriptor::Connect(const char *s, Error *error_ptr) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION)); if (log) log->Printf("%p ConnectionFileDescriptor::Connect (url = '%s')", static_cast<void *>(this), s); @@ -374,10 +374,8 @@ ConnectionFileDescriptor::Disconnect(Error *error_ptr) m_shutting_down = true; - Mutex::Locker locker; - bool got_lock = locker.TryLock(m_mutex); - - if (!got_lock) + std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock); + if (!locker.try_lock()) { if (m_pipe.CanWrite()) { @@ -392,7 +390,7 @@ ConnectionFileDescriptor::Disconnect(Error *error_ptr) log->Printf("%p ConnectionFileDescriptor::Disconnect(): Couldn't get the lock, but no command pipe is available.", static_cast<void *>(this)); } - locker.Lock(m_mutex); + locker.lock(); } Error error = m_read_sp->Close(); @@ -415,9 +413,8 @@ ConnectionFileDescriptor::Read(void *dst, size_t dst_len, uint32_t timeout_usec, { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION)); - Mutex::Locker locker; - bool got_lock = locker.TryLock(m_mutex); - if (!got_lock) + std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock); + if (!locker.try_lock()) { if (log) log->Printf("%p ConnectionFileDescriptor::Read () failed to get the connection lock.", static_cast<void *>(this)); diff --git a/source/Host/posix/DomainSocket.cpp b/source/Host/posix/DomainSocket.cpp index b4427e305f3e..9dc147196c08 100644 --- a/source/Host/posix/DomainSocket.cpp +++ b/source/Host/posix/DomainSocket.cpp @@ -21,7 +21,7 @@ using namespace lldb_private; #ifdef __ANDROID__ // Android does not have SUN_LEN #ifndef SUN_LEN -#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) + strlen((ptr)->sun_path)) +#define SUN_LEN(ptr) (offsetof(struct sockaddr_un, sun_path) + strlen((ptr)->sun_path)) #endif #endif // #ifdef __ANDROID__ diff --git a/source/Host/posix/FileSystem.cpp b/source/Host/posix/FileSystem.cpp index 1f2e7db0e1e4..c8fa1bc9cf47 100644 --- a/source/Host/posix/FileSystem.cpp +++ b/source/Host/posix/FileSystem.cpp @@ -54,30 +54,32 @@ FileSystem::MakeDirectory(const FileSpec &file_spec, uint32_t file_permissions) switch (error.GetError()) { case ENOENT: - { - // Parent directory doesn't exist, so lets make it if we can - // Make the parent directory and try again - FileSpec parent_file_spec{file_spec.GetDirectory().GetCString(), false}; - error = MakeDirectory(parent_file_spec, file_permissions); - if (error.Fail()) - return error; - // Try and make the directory again now that the parent directory was made successfully - if (::mkdir(file_spec.GetCString(), file_permissions) == -1) { - error.SetErrorToErrno(); + // Parent directory doesn't exist, so lets make it if we can + // Make the parent directory and try again + FileSpec parent_file_spec{file_spec.GetDirectory().GetCString(), false}; + error = MakeDirectory(parent_file_spec, file_permissions); + if (error.Fail()) + return error; + // Try and make the directory again now that the parent directory was made successfully + if (::mkdir(file_spec.GetCString(), file_permissions) == -1) + { + error.SetErrorToErrno(); + } return error; } - } + break; case EEXIST: - { - if (file_spec.IsDirectory()) - return Error{}; // It is a directory and it already exists - } + { + if (file_spec.IsDirectory()) + return Error(); // It is a directory and it already exists + } + break; } } return error; } - return Error{"empty path"}; + return Error("empty path"); } Error @@ -297,3 +299,15 @@ FileSystem::IsLocal(const FileSpec &spec) return false; } #endif + +FILE * +FileSystem::Fopen(const char *path, const char *mode) +{ + return ::fopen(path, mode); +} + +int +FileSystem::Stat(const char *path, struct stat *stats) +{ + return ::stat(path, stats); +} diff --git a/source/Host/posix/HostInfoPosix.cpp b/source/Host/posix/HostInfoPosix.cpp index cfdbf5635ad1..d0ef2ca37061 100644 --- a/source/Host/posix/HostInfoPosix.cpp +++ b/source/Host/posix/HostInfoPosix.cpp @@ -242,3 +242,14 @@ HostInfoPosix::ComputePythonDirectory(FileSpec &file_spec) return false; #endif } + +bool +HostInfoPosix::GetEnvironmentVar(const std::string &var_name, std::string &var) +{ + if (const char *pvar = ::getenv(var_name.c_str())) + { + var = std::string(pvar); + return true; + } + return false; +} diff --git a/source/Host/posix/HostProcessPosix.cpp b/source/Host/posix/HostProcessPosix.cpp index 5761a79da27f..93844d9b99d3 100644 --- a/source/Host/posix/HostProcessPosix.cpp +++ b/source/Host/posix/HostProcessPosix.cpp @@ -107,7 +107,7 @@ bool HostProcessPosix::IsRunning() const } HostThread -HostProcessPosix::StartMonitoring(HostProcess::MonitorCallback callback, void *callback_baton, bool monitor_signals) +HostProcessPosix::StartMonitoring(const Host::MonitorChildProcessCallback &callback, bool monitor_signals) { - return Host::StartMonitoringChildProcess(callback, callback_baton, m_process, monitor_signals); + return Host::StartMonitoringChildProcess(callback, m_process, monitor_signals); } diff --git a/source/Host/posix/HostThreadPosix.cpp b/source/Host/posix/HostThreadPosix.cpp index 9c4892431938..f1a6d6f83142 100644 --- a/source/Host/posix/HostThreadPosix.cpp +++ b/source/Host/posix/HostThreadPosix.cpp @@ -53,13 +53,18 @@ Error HostThreadPosix::Cancel() { Error error; + if (IsJoinable()) + { #ifndef __ANDROID__ - int err = ::pthread_cancel(m_thread); - error.SetError(err, eErrorTypePOSIX); +#ifndef __FreeBSD__ + assert(false && "someone is calling HostThread::Cancel()"); +#endif + int err = ::pthread_cancel(m_thread); + error.SetError(err, eErrorTypePOSIX); #else - error.SetErrorString("HostThreadPosix::Cancel() not supported on Android"); + error.SetErrorString("HostThreadPosix::Cancel() not supported on Android"); #endif - + } return error; } @@ -67,8 +72,11 @@ Error HostThreadPosix::Detach() { Error error; - int err = ::pthread_detach(m_thread); - error.SetError(err, eErrorTypePOSIX); + if (IsJoinable()) + { + int err = ::pthread_detach(m_thread); + error.SetError(err, eErrorTypePOSIX); + } Reset(); return error; } |