diff options
author | Max Kellermann <max@duempel.org> | 2014-02-06 22:19:59 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-06 22:19:59 +0100 |
commit | c8f0c7e9ede1cfef49ea9d4b71b6b56b4ae87141 (patch) | |
tree | 85adef73380393703c71202f20601d99df135b00 /src/input | |
parent | a7989077abe2b862b131b7573380a82f889bad95 (diff) | |
download | mpd-c8f0c7e9ede1cfef49ea9d4b71b6b56b4ae87141.tar.gz mpd-c8f0c7e9ede1cfef49ea9d4b71b6b56b4ae87141.tar.xz mpd-c8f0c7e9ede1cfef49ea9d4b71b6b56b4ae87141.zip |
*/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.
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/plugins/SmbclientInputPlugin.cxx | 9 |
1 files changed, 9 insertions, 0 deletions
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"); |