Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
libc.CLONE_NEWNS
| libc.CLONE_NEWUTS
| libc.CLONE_NEWIPC
| libc.CLONE_NEWUSER
| libc.CLONE_NEWPID
)
if not network_access:
flags |= libc.CLONE_NEWNET
try:
libc.unshare(flags)
except OSError as e:
if (
e.errno == errno.EPERM
and util.try_read_file("/proc/sys/kernel/unprivileged_userns_clone") == "0"
):
raise BenchExecException(
"Unprivileged user namespaces forbidden on this system, please "
"enable them with 'sysctl kernel.unprivileged_userns_clone=1' "
"or disable container mode"
)
else:
raise BenchExecException(
"Creating namespace for container mode failed: " + os.strerror(e.errno)
)
# Container config
container.setup_user_mapping(os.getpid(), uid, gid)
_setup_container_filesystem(temp_dir, dir_modes, container_system_config)
if container_system_config:
libc.sethostname(container.CONTAINER_HOSTNAME)
if not network_access:
container.activate_network_interface("lo")
raise BenchExecException(
"Property pattern '{}' in task-definition file {} does not refer to exactly one file.".format(
prop_dict["property_file"], task_def_file
)
)
# TODO We could reduce I/O by checking absolute paths and using os.path.samestat
# with cached stat calls.
if prop.filename == expanded[0] or os.path.samefile(
prop.filename, expanded[0]
):
expected_result = prop_dict.get("expected_verdict")
if expected_result is not None and not isinstance(
expected_result, bool
):
raise BenchExecException(
"Invalid expected result '{}' for property {} in task-definition file {}.".format(
expected_result, prop_dict["property_file"], task_def_file
)
)
run.expected_results[prop.filename] = result.ExpectedResult(
expected_result, prop_dict.get("subproperty")
)
if not run.expected_results:
logging.debug(
"Ignoring run '%s' because it does not have the property from %s.",
run.identifier,
run.propertyfile,
)
return None
elif len(run.expected_results) > 1:
hardtimelimit,
softtimelimit,
walltimelimit,
memlimit,
cores,
memory_nodes,
cgroupValues,
environments,
workingDir,
maxLogfileSize,
files_count_limit,
files_size_limit,
**kwargs,
)
except BenchExecException as e:
logging.critical(
"Cannot execute '%s': %s.", util.escape_string_shell(args[0]), e
)
return {"terminationreason": "failed"}
except OSError as e:
logging.critical(
"OSError %s while starting '%s' in '%s': %s.",
e.errno,
util.escape_string_shell(args[0]),
workingDir or ".",
e.strerror,
)
return {"terminationreason": "failed"}
task_def_files = self.get_task_def_files_from_xml(sourcefilesTag, base_dir)
# get file-specific options for filenames
fileOptions = util.get_list_from_xml(sourcefilesTag)
local_propertytag = get_propertytag(sourcefilesTag)
# some runs need more than one sourcefile,
# the first sourcefile is a normal 'include'-file, we use its name as identifier
# for logfile and result-category all other files are 'append'ed.
appendFileTags = sourcefilesTag.findall("append")
currentRuns = []
for identifier in task_def_files:
if identifier.endswith(".yml"):
if appendFileTags:
raise BenchExecException(
"Cannot combine and task-definition files in the same tag."
)
run = self.create_run_from_task_definition(
identifier,
fileOptions,
local_propertytag,
required_files_pattern,
)
else:
run = self.create_run_for_input_file(
identifier,
fileOptions,
local_propertytag,
required_files_pattern,
appendFileTags,
)
def expand_patterns_from_tag(tag):
result = []
patterns = task_def.get(tag, [])
if isinstance(patterns, str) or not isinstance(
patterns, collections.Iterable
):
# accept single string in addition to list of strings
patterns = [patterns]
for pattern in patterns:
expanded = util.expand_filename_pattern(
str(pattern), os.path.dirname(task_def_file)
)
if not expanded:
raise BenchExecException(
"Pattern '{}' in task-definition file {} did not match any paths.".format(
pattern, task_def_file
)
)
expanded.sort()
result.extend(expanded)
return result
def _call_tool_func(name, args, kwargs):
"""Call a method on the tool instance.
@param name: The method name to call.
@param args: List of arguments to be passed as positional arguments.
@param kwargs: Dict of arguments to be passed as keyword arguments.
"""
global tool
try:
return getattr(tool, name)(*args, **kwargs)
except SystemExit as e:
# SystemExit would terminate the worker process instead of being propagated.
raise BenchExecException(str(e.code))
if filename_part in filename:
expected_result_class = get_result_classification(expected_result)
assert expected_result_class in {RESULT_CLASS_TRUE, RESULT_CLASS_FALSE}
expected_result = expected_result_class == RESULT_CLASS_TRUE
subproperty = None
if len(for_properties) > 1:
assert for_properties == _MEMSAFETY_SUBPROPERTIES
assert expected_result
prop = _PROP_MEMSAFETY
else:
prop = next(iter(for_properties))
if prop in _MEMSAFETY_SUBPROPERTIES and not expected_result:
subproperty = prop
prop = _PROP_MEMSAFETY
if prop in results:
raise BenchExecException(
"Duplicate property {} in filename {}".format(prop, filename)
)
results[prop] = ExpectedResult(expected_result, subproperty)
return results
if not network_access:
flags |= libc.CLONE_NEWNET
try:
libc.unshare(flags)
except OSError as e:
if (
e.errno == errno.EPERM
and util.try_read_file("/proc/sys/kernel/unprivileged_userns_clone") == "0"
):
raise BenchExecException(
"Unprivileged user namespaces forbidden on this system, please "
"enable them with 'sysctl kernel.unprivileged_userns_clone=1' "
"or disable container mode"
)
else:
raise BenchExecException(
"Creating namespace for container mode failed: " + os.strerror(e.errno)
)
# Container config
container.setup_user_mapping(os.getpid(), uid, gid)
_setup_container_filesystem(temp_dir, dir_modes, container_system_config)
if container_system_config:
libc.sethostname(container.CONTAINER_HOSTNAME)
if not network_access:
container.activate_network_interface("lo")
# Because this process is not actually in the new PID namespace, we fork.
# The child will be in the new PID namespace and will assume the role of the acting
# multiprocessing worker (which it can do because it inherits the file descriptors
# that multiprocessing uses for communication).
# The original multiprocessing worker (the parent of the fork) must do nothing in
launcher_jar = self._get_current_launcher_jar(executable)
cmds = [
# 2
["java", "-Xss4m", "-jar", launcher_jar, "-data", "@noDefault", "-ultimatedata", data_dir, "--version"],
# 1
["java", "-Xss4m", "-jar", launcher_jar, "-data", data_dir, "--version"],
]
self.api = len(cmds)
for cmd in cmds:
version = self._query_ultimate_version(cmd, self.api)
if version != '':
return version
self.api = self.api - 1
raise BenchExecException("Could not determine Ultimate version")
"Parent: child process of RunExecutor with PID %d"
" terminated with %s.",
child_pid,
child_exitcode,
)
if child_exitcode:
if child_exitcode.value:
if child_exitcode.value == CHILD_OSERROR:
# This was an OSError in the child,
# details were already logged
raise BenchExecException(
"execution in container failed, check log for details"
)
elif child_exitcode.value == CHILD_UNKNOWN_ERROR:
raise BenchExecException("unexpected error in container")
raise OSError(
child_exitcode.value, os.strerror(child_exitcode.value)
)
raise OSError(
0,
"Child process of RunExecutor terminated with "
+ str(child_exitcode),
)