From c8f0c7e9ede1cfef49ea9d4b71b6b56b4ae87141 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 6 Feb 2014 22:19:59 +0100 Subject: */smbclient: protect all libsmbclient calls with a mutex libsmbclient is not thread-safe nor reentrant. We must protect all function calls with a global mutex, unfortunately. --- src/input/plugins/SmbclientInputPlugin.cxx | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/input/plugins/SmbclientInputPlugin.cxx') diff --git a/src/input/plugins/SmbclientInputPlugin.cxx b/src/input/plugins/SmbclientInputPlugin.cxx index 561e6f8fd..6f2c191b0 100644 --- a/src/input/plugins/SmbclientInputPlugin.cxx +++ b/src/input/plugins/SmbclientInputPlugin.cxx @@ -20,6 +20,7 @@ #include "config.h" #include "SmbclientInputPlugin.hxx" #include "lib/smbclient/Init.hxx" +#include "lib/smbclient/Mutex.hxx" #include "../InputStream.hxx" #include "../InputPlugin.hxx" #include "util/StringUtil.hxx" @@ -45,8 +46,10 @@ public: } ~SmbclientInputStream() { + smbclient_mutex.lock(); smbc_close(fd); smbc_free_context(ctx, 1); + smbclient_mutex.unlock(); } InputStream *GetBase() { @@ -58,7 +61,9 @@ public: } size_t Read(void *ptr, size_t size, Error &error) { + smbclient_mutex.lock(); ssize_t nbytes = smbc_read(fd, ptr, size); + smbclient_mutex.unlock(); if (nbytes < 0) { error.SetErrno("smbc_read() failed"); nbytes = 0; @@ -68,7 +73,9 @@ public: } bool Seek(InputStream::offset_type offset, int whence, Error &error) { + smbclient_mutex.lock(); off_t result = smbc_lseek(fd, offset, whence); + smbclient_mutex.unlock(); if (result < 0) { error.SetErrno("smbc_lseek() failed"); return false; @@ -105,6 +112,8 @@ input_smbclient_open(const char *uri, if (!StringStartsWith(uri, "smb://")) return nullptr; + const ScopeLock protect(smbclient_mutex); + SMBCCTX *ctx = smbc_new_context(); if (ctx == nullptr) { error.SetErrno("smbc_new_context() failed"); -- cgit v1.2.3