From d2ed3fb624274e824ab5ba892e8898f3d0eb1502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= Date: Thu, 5 Nov 2015 21:23:45 +0200 Subject: [PATCH] directory: ignore non-regular non-directory files by default Playing FIFOs and devices (especially character devices) typically only makes sense if explicitly requested. Playing FIFOs will usually lock up. Playing devices could have any effects. Add an option to restore the old behaviour in case someone wants it. --- NEWS | 2 ++ modules/access/directory.c | 31 +++++++++++++++++++++++++------ modules/access/fs.c | 2 ++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 5a3d43ac89..a5d7ae7593 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,8 @@ Access: * SMB/FTP/SFTP accesses can list directories * Support for SAT>IP server dialect for RTSP (satip://) * New "concat" access module for concatenating byte streams + * Named pipes and device nodes are no longer included in directory listings + by default. Use --list-special-files to include them back. Decoder: * OMX GPU-zerocopy support for decoding and display on Android using OpenMax IL diff --git a/modules/access/directory.c b/modules/access/directory.c index 4ae3e23003..f0e58261dc 100644 --- a/modules/access/directory.c +++ b/modules/access/directory.c @@ -45,6 +45,7 @@ struct access_sys_t { char *base_uri; DIR *dir; + bool special_files; }; /***************************************************************************** @@ -68,6 +69,7 @@ int DirInit (access_t *access, DIR *dir) goto error; sys->dir = dir; + sys->special_files = var_InheritBool(access, "list-special-files"); access->p_sys = sys; access->pf_readdir = DirRead; @@ -126,14 +128,31 @@ input_item_t *DirRead(access_t *access) switch (st.st_mode & S_IFMT) { - case S_IFBLK: type = ITEM_TYPE_DISC; break; - case S_IFCHR: type = ITEM_TYPE_CARD; break; - case S_IFIFO: type = ITEM_TYPE_STREAM; break; - case S_IFREG: type = ITEM_TYPE_FILE; break; - case S_IFDIR: type = ITEM_TYPE_DIRECTORY; break; + case S_IFBLK: + if (!sys->special_files) + continue; + type = ITEM_TYPE_DISC; + break; + case S_IFCHR: + if (!sys->special_files) + continue; + type = ITEM_TYPE_CARD; + break; + case S_IFIFO: + if (!sys->special_files) + continue; + type = ITEM_TYPE_STREAM; + break; + case S_IFREG: + type = ITEM_TYPE_FILE; + break; + case S_IFDIR: + type = ITEM_TYPE_DIRECTORY; + break; /* S_IFLNK cannot occur while following symbolic links */ /* S_IFSOCK cannot be opened with open()/openat() */ - default: continue; /* ignore */ + default: + continue; /* ignore */ } #else type = ITEM_TYPE_FILE; diff --git a/modules/access/fs.c b/modules/access/fs.c index 89a6cb1921..edce520cd7 100644 --- a/modules/access/fs.c +++ b/modules/access/fs.c @@ -50,4 +50,6 @@ vlc_module_begin () #endif set_callbacks( DirOpen, DirClose ) + add_bool("list-special-files", false, N_("List special files"), + N_("Include devices and pipes when listing directories"), true) vlc_module_end ()