Improve secure.py

This commit is contained in:
nicolargo committed 2023-06-17 16:28:27 +02:00
1 parent 21d18c39e8
commit aeb6891c85
2 files changed
+5 -3

No files matched your search

+5 -2
View File
@@ -9,10 +9,11 @@
"""Secures functions for Glances"""
from glances.globals import nativestr
from subprocess import Popen, PIPE
import re
from glances.globals import nativestr
def secure_popen(cmd):
"""A more or less secure way to execute system commands
@@ -54,8 +55,10 @@ def __secure_popen(cmd):
sub_cmd_split = [_[1:-1] if (_[0] == _[-1] == '"') or (_[0] == _[-1] == '\'') else _ for _ in tmp_split]
p = Popen(sub_cmd_split, shell=False, stdin=sub_cmd_stdin, stdout=PIPE, stderr=PIPE)
if p_last is not None:
p_last.wait()
# Allow p_last to receive a SIGPIPE if p exits.
p_last.stdout.close()
p_last.kill()
p_last.wait()
p_last = p
sub_cmd_stdin = p.stdout
-1
View File
@@ -33,7 +33,6 @@ from glances.plugins.plugin.model import GlancesPluginModel
from glances.programs import processes_to_programs
from glances.secure import secure_popen
# Global variables
# =================