summaryrefslogtreecommitdiffstats
path: root/glances/secure.py
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2021-04-25 09:42:23 +0200
committernicolargo <nicolas@nicolargo.com>2021-04-25 09:42:23 +0200
commita2c0357898c24518867efd37adfc1e7bbed83b81 (patch)
tree69cd6ca479cb695ec15512cd8285a9ccd83be5af /glances/secure.py
parent29d4662fd274ebcb54d08845daab946533f523ba (diff)
Manage multiple commands (&&) in the secure popen
Diffstat (limited to 'glances/secure.py')
-rw-r--r--glances/secure.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/glances/secure.py b/glances/secure.py
index 7a2f8d7b..36af5e16 100644
--- a/glances/secure.py
+++ b/glances/secure.py
@@ -24,11 +24,25 @@ from subprocess import Popen, PIPE
def secure_popen(cmd):
- """A more or less secure way to execute system command
+ """A more or less secure way to execute system commands
+ Multiple command should be seprated with a &&
+
+ Return: the result of the commands
+ """
+ ret = ''
+
+ # Split by multiple commands '&&'
+ for c in cmd.split('&&'):
+ ret += __secure_popen(c)
- Return: the result of the command OR an error message
+ return ret
+
+
+def __secure_popen(cmd):
+ """A more or less secure way to execute system command
+ Manage redirection (>) and pipes (|)
"""
- ret = None
+ ret = ''
# Split by redirection '>'
cmd_split_redirect = cmd.split('>')