diff options
| author | 2019-06-20 14:28:16 -0700 | |
|---|---|---|
| committer | 2019-06-22 13:36:39 -0700 | |
| commit | d6e036a2291e3b403b18ee5b9a6d25ac08fccf6f (patch) | |
| tree | 4503f1c6fb74f30ac0b66e3a8069636676e29eda | |
| parent | Use IDs for user and group for consistency across distros (diff) | |
Capture NsJail logs from stdout if NsJail fails to parse cmd args
Fixes #30
| -rw-r--r-- | snekbox/nsjail.py | 12 | 
1 files changed, 9 insertions, 3 deletions
| diff --git a/snekbox/nsjail.py b/snekbox/nsjail.py index 204b475..3bcc0a1 100644 --- a/snekbox/nsjail.py +++ b/snekbox/nsjail.py @@ -6,6 +6,7 @@ import sys  import textwrap  from pathlib import Path  from tempfile import NamedTemporaryFile +from typing import List  from snekbox import DEBUG @@ -62,9 +63,9 @@ class NsJail:          mem.mkdir(parents=True, exist_ok=True)      @staticmethod -    def _parse_log(log_file): +    def _parse_log(log_lines: List[str]):          """Parse and log NsJail's log messages.""" -        for line in log_file.read().decode("UTF-8").splitlines(): +        for line in log_lines:              match = LOG_PATTERN.fullmatch(line)              if match is None:                  log.warning(f"Failed to parse log line '{line}'") @@ -131,6 +132,11 @@ class NsJail:              except ValueError:                  return subprocess.CompletedProcess(args, None, "ValueError: embedded null byte", "") -            self._parse_log(nsj_log) +            log_lines = nsj_log.read().decode("UTF-8").splitlines() +            if not log_lines and result.returncode == 255: +                # NsJail probably failed to parse arguments so log output will still be in stdout +                log_lines = result.stdout.splitlines() + +            self._parse_log(log_lines)          return result | 
