[vlc-devel] [PATCH] cli: lua: Don't always force quit when no command can be read

Hugo Beauzée-Luyssen hugo at beauzee.fr
Tue Jun 2 12:15:39 CEST 2020


In case the lua interface gets restored from the config while the
application is not launched from a console, it would end up quiting
instead of giving up on the CLI interface.

We have to have a specific handling for "*console", as the
cli.lua interface is actually used through other inputs, notably TCP.
---
 share/lua/intf/cli.lua          | 27 ++++++++++++++++++++++-----
 share/lua/intf/modules/host.lua |  6 +-----
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/share/lua/intf/cli.lua b/share/lua/intf/cli.lua
index 084451cd0e..c30690d91b 100644
--- a/share/lua/intf/cli.lua
+++ b/share/lua/intf/cli.lua
@@ -803,13 +803,21 @@ h.status_callbacks[host.status.password] = on_password
 h.status_callbacks[host.status.read] = on_read
 h.status_callbacks[host.status.write] = on_write
 
-h:listen( config.hosts or config.host or "*console" )
+local host_url = config.hosts or config.host or "*console"
+h:listen( host_url )
 password = config.password or "admin"
 
---[[ The main loop ]]
-while running do
-    local write, read = h:accept_and_select()
+local write, read = h:accept_and_select()
+if #read == 0 and host_url == "*console" then
+    -- If we're listening from stdin but cant read anything, just quit the
+    -- interface but don't explicitely quit since it might just be a GUI run
+    -- that tries to restore the previous extraintf
+    vlc.msg.warn("Can't read from stdin, exiting cli interface")
+    return
+end
 
+--[[ The main loop ]]
+repeat
     for _, client in pairs(write) do
         local len = client:send()
         client.buffer = string.sub(client.buffer,len+1)
@@ -864,7 +872,16 @@ while running do
             client.buffer = saved_buffer .. client.buffer
         end
     end
-end
+
+    write, read = h:accept_and_select()
+
+    -- Quit if stdin gets closed
+    if #write == 0 and #read == 0 and host_url == "*console" then
+        h:broadcast("Shutting down.\r\n")
+        vlc.msg.info("Requested shutdown.")
+        vlc.misc.quit()
+    end
+until not running
 
 --[[ Clean up ]]
 vlm = nil
diff --git a/share/lua/intf/modules/host.lua b/share/lua/intf/modules/host.lua
index 6f85cceeba..1f25f5adf0 100644
--- a/share/lua/intf/modules/host.lua
+++ b/share/lua/intf/modules/host.lua
@@ -139,11 +139,7 @@ function host()
             return
         end
 
-        if client.type == client_type.stdio then
-            h:broadcast("Shutting down.\r\n")
-            vlc.msg.info("Requested shutdown.")
-            vlc.misc.quit()
-        elseif client.type == client_type.net
+        if client.type == client_type.net
         or client.type == client_type.telnet then
             if client.wfd ~= client.rfd then
                 vlc.net.close( client.rfd )
-- 
2.20.1



More information about the vlc-devel mailing list