Fabian Deutsch has uploaded a new change for review. Change subject: process: Raise an error for a known problem ......................................................................
process: Raise an error for a known problem It is known that combining shell=True with an argumentlist doesn't work. Thsi check is now added to call subprocess calls. Change-Id: Ic0208de30aa5b8312384c0736f6f7ad38624ec89 Signed-off-by: Fabian Deutsch <[email protected]> --- M src/ovirt/node/utils/process.py 1 file changed, 12 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/25/19225/1 diff --git a/src/ovirt/node/utils/process.py b/src/ovirt/node/utils/process.py index b442eb2..b6e0cbd 100644 --- a/src/ovirt/node/utils/process.py +++ b/src/ovirt/node/utils/process.py @@ -43,11 +43,19 @@ return new_kwargs +def __check_for_problems(args, kwargs): + if ("shell" in kwargs) and (args and type(args[0]) is list): + raise RuntimeError("Combining shell=True and a command list does " + + "not work. With shell=True the first argument" + + "must be a string. A list otherwise.") + + def popen(*args, **kwargs): """subprocess.Popen wrapper to not leak file descriptors """ kwargs = __update_kwargs(kwargs) LOGGER.debug("Popen with: %s %s" % (args, kwargs)) + # Intentionally no check for common problems return subprocess.Popen(*args, **kwargs) @@ -56,6 +64,7 @@ """ kwargs = __update_kwargs(kwargs) LOGGER.debug("Calling with: %s %s" % (args, kwargs)) + __check_for_problems(args, kwargs) return int(subprocess.call(*args, **kwargs)) @@ -64,6 +73,7 @@ """ kwargs = __update_kwargs(kwargs) LOGGER.debug("Checking call with: %s %s" % (args, kwargs)) + __check_for_problems(args, kwargs) return int(subprocess.check_call(*args, **kwargs)) @@ -72,6 +82,7 @@ """ kwargs = __update_kwargs(kwargs) LOGGER.debug("Checking output with: %s %s" % (args, kwargs)) + __check_for_problems(args, kwargs) try: return unicode(subprocess.check_output(*args, **kwargs), encoding=sys.stdin.encoding or "utf-8") @@ -96,4 +107,5 @@ kwargs.update({"stdin": PIPE, "stdout": PIPE, "stderr": STDOUT}) + __check_for_problems(cmd, kwargs) return unicode(popen(cmd, **kwargs).communicate(stdin)[0]) -- To view, visit http://gerrit.ovirt.org/19225 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic0208de30aa5b8312384c0736f6f7ad38624ec89 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-node Gerrit-Branch: master Gerrit-Owner: Fabian Deutsch <[email protected]> _______________________________________________ node-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/node-patches
