diff options
Diffstat (limited to 'stream')
-rw-r--r-- | stream/stream_file.c | 18 | ||||
-rw-r--r-- | stream/stream_libarchive.c | 11 | ||||
-rw-r--r-- | stream/stream_smb.c | 39 |
3 files changed, 48 insertions, 20 deletions
diff --git a/stream/stream_file.c b/stream/stream_file.c index 319a92f08b..dc5a3ed6f7 100644 --- a/stream/stream_file.c +++ b/stream/stream_file.c @@ -123,16 +123,16 @@ static int fill_buffer(stream_t *s, char *buffer, int max_len) static int write_buffer(stream_t *s, char *buffer, int len) { struct priv *p = s->priv; - int r; - int wr = 0; - while (wr < len) { - r = write(p->fd, buffer, len); - if (r <= 0) + int r = len; + int wr; + while (r > 0) { + wr = write(p->fd, buffer, r); + if (wr <= 0) return -1; - wr += r; - buffer += r; + r -= wr; + buffer += wr; } - return len; + return len - r; } static int seek(stream_t *s, int64_t newpos) @@ -196,7 +196,7 @@ static bool check_stream_network(int fd) { struct statfs fs; const char *stypes[] = { "afpfs", "nfs", "smbfs", "webdav", "osxfusefs", - NULL }; + "fuse", "fusefs.sshfs", NULL }; if (fstatfs(fd, &fs) == 0) for (int i=0; stypes[i]; i++) if (strcmp(stypes[i], fs.f_fstypename) == 0) diff --git a/stream/stream_libarchive.c b/stream/stream_libarchive.c index d02cb7e630..e5acad016b 100644 --- a/stream/stream_libarchive.c +++ b/stream/stream_libarchive.c @@ -433,8 +433,15 @@ static int archive_entry_seek(stream_t *s, int64_t newpos) int size = MPMIN(newpos - s->pos, sizeof(buffer)); locale_t oldlocale = uselocale(p->mpa->locale); int r = archive_read_data(p->mpa->arch, buffer, size); - if (r < 0) { - MP_ERR(s, "%s\n", archive_error_string(p->mpa->arch)); + if (r <= 0) { + if (r == 0 && newpos > p->entry_size) { + MP_ERR(s, "demuxer trying to seek beyond end of archive " + "entry\n"); + } else if (r == 0) { + MP_ERR(s, "end of archive entry reached while seeking\n"); + } else { + MP_ERR(s, "%s\n", archive_error_string(p->mpa->arch)); + } uselocale(oldlocale); if (mp_archive_check_fatal(p->mpa, r)) { mp_archive_free(p->mpa); diff --git a/stream/stream_smb.c b/stream/stream_smb.c index 4376f71ee6..bc51796bbc 100644 --- a/stream/stream_smb.c +++ b/stream/stream_smb.c @@ -21,6 +21,7 @@ #include <libsmbclient.h> #include <unistd.h> +#include <pthread.h> #include "common/msg.h" #include "stream.h" @@ -31,6 +32,8 @@ #error GPL only #endif +static pthread_mutex_t smb_lock = PTHREAD_MUTEX_INITIALIZER; + struct priv { int fd; }; @@ -40,14 +43,17 @@ static void smb_auth_fn(const char *server, const char *share, char *password, int pwmaxlen) { strncpy(workgroup, "LAN", wgmaxlen - 1); + workgroup[wgmaxlen - 1] = '\0'; } static int control(stream_t *s, int cmd, void *arg) { struct priv *p = s->priv; switch(cmd) { case STREAM_CTRL_GET_SIZE: { + pthread_mutex_lock(&smb_lock); off_t size = smbc_lseek(p->fd,0,SEEK_END); smbc_lseek(p->fd,s->pos,SEEK_SET); + pthread_mutex_unlock(&smb_lock); if(size != (off_t)-1) { *(int64_t *)arg = size; return 1; @@ -60,7 +66,10 @@ static int control(stream_t *s, int cmd, void *arg) { static int seek(stream_t *s,int64_t newpos) { struct priv *p = s->priv; - if(smbc_lseek(p->fd,newpos,SEEK_SET)<0) { + pthread_mutex_lock(&smb_lock); + off_t size = smbc_lseek(p->fd,newpos,SEEK_SET); + pthread_mutex_unlock(&smb_lock); + if(size<0) { return 0; } return 1; @@ -68,27 +77,33 @@ static int seek(stream_t *s,int64_t newpos) { static int fill_buffer(stream_t *s, char* buffer, int max_len){ struct priv *p = s->priv; + pthread_mutex_lock(&smb_lock); int r = smbc_read(p->fd,buffer,max_len); + pthread_mutex_unlock(&smb_lock); return (r <= 0) ? -1 : r; } static int write_buffer(stream_t *s, char* buffer, int len) { struct priv *p = s->priv; - int r; - int wr = 0; - while (wr < len) { - r = smbc_write(p->fd,buffer,len); - if (r <= 0) + int r = len; + int wr; + while (r > 0) { + pthread_mutex_lock(&smb_lock); + wr = smbc_write(p->fd,buffer,r); + pthread_mutex_unlock(&smb_lock); + if (wr <= 0) return -1; - wr += r; - buffer += r; + r -= wr; + buffer += wr; } - return len; + return len - r; } static void close_f(stream_t *s){ struct priv *p = s->priv; + pthread_mutex_lock(&smb_lock); smbc_close(p->fd); + pthread_mutex_unlock(&smb_lock); } static int open_f (stream_t *stream) @@ -110,13 +125,17 @@ static int open_f (stream_t *stream) return STREAM_ERROR; } + pthread_mutex_lock(&smb_lock); err = smbc_init(smb_auth_fn, 1); + pthread_mutex_unlock(&smb_lock); if (err < 0) { MP_ERR(stream, "Cannot init the libsmbclient library: %d\n",err); return STREAM_ERROR; } + pthread_mutex_lock(&smb_lock); fd = smbc_open(filename, m,0644); + pthread_mutex_unlock(&smb_lock); if (fd < 0) { MP_ERR(stream, "Could not open from LAN: '%s'\n", filename); return STREAM_ERROR; @@ -124,8 +143,10 @@ static int open_f (stream_t *stream) len = 0; if(!write) { + pthread_mutex_lock(&smb_lock); len = smbc_lseek(fd,0,SEEK_END); smbc_lseek (fd, 0, SEEK_SET); + pthread_mutex_unlock(&smb_lock); } if(len > 0 || write) { stream->seekable = true; |