Skip to content

Commit e0c7740

Browse files
committed
remove the run_command
1 parent 40102b4 commit e0c7740

2 files changed

Lines changed: 0 additions & 110 deletions

File tree

fuzz/build_fuzz.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,46 +36,6 @@
3636
from errors import BuildError, CommandError, PathError, ConfigError
3737
from command_util import run_command_build_fuzz as run_command
3838

39-
40-
41-
# ========================================================================================
42-
# Helper Functions
43-
# ========================================================================================
44-
def run_command(
45-
cmd: str,
46-
oss_fuzz_dir: Path,
47-
project: str = "",
48-
allowed_exit_codes: Maybe[list[int]] = Maybe.empty,
49-
skip_yes: bool = False
50-
) -> int:
51-
"""Execute a command and return the exit code (no stdout/stderr capture)"""
52-
allowed_codes = allowed_exit_codes.value_or([0])
53-
cmd_str = f"yes | {cmd}" if not skip_yes else cmd
54-
logging.debug(f"Executing command [{project}]: {cmd_str}")
55-
56-
try:
57-
process = subprocess.Popen(
58-
cmd_str,
59-
shell=True,
60-
cwd=str(oss_fuzz_dir)
61-
)
62-
exit_code = process.wait()
63-
64-
if exit_code in allowed_codes:
65-
return exit_code
66-
67-
error_msg = f"Command failed (exit code: {exit_code})"
68-
if project:
69-
error_msg += f" for project: {project}"
70-
raise CommandError(error_msg, project=project, exit_code=exit_code)
71-
72-
except FileNotFoundError as e:
73-
raise CommandError(f"Command not found: {cmd.split()[0]}", project=project) from e
74-
except OSError as e:
75-
raise CommandError(f"System error: {e}", project=project) from e
76-
except subprocess.SubprocessError as e:
77-
raise CommandError(f"Subprocess error: {e}", project=project) from e
78-
7939
# ========================================================================================
8040
# Build Functions
8141
# ========================================================================================

fuzz/run_fuzz_all_targets_print1.py

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -29,76 +29,6 @@
2929

3030

3131

32-
33-
def run_command(
34-
cmd: str,
35-
log_msg: str,
36-
logger: logging.Logger,
37-
allowed_exit_codes: Maybe[list[int]] = Nothing,
38-
timeout: int = 3600 # Default 1-hour timeout
39-
) -> bool:
40-
"""Execute commands with real-time logging and precise error handling"""
41-
allowed_codes = allowed_exit_codes.value_or([])
42-
logger.info(f"▶️ {log_msg}...")
43-
logger.debug(f" $ {cmd}")
44-
45-
process = None
46-
try:
47-
process = subprocess.Popen(
48-
cmd,
49-
shell=True,
50-
stdout=subprocess.PIPE,
51-
stderr=subprocess.STDOUT,
52-
text=True,
53-
encoding="utf-8",
54-
errors="replace"
55-
)
56-
57-
start_time = time.time()
58-
while process.poll() is None:
59-
if time.time() - start_time > timeout:
60-
logger.error(f"⌛ Command timed out after {timeout} seconds")
61-
process.terminate()
62-
try:
63-
process.wait(timeout=5)
64-
except subprocess.TimeoutExpired:
65-
process.kill()
66-
return False
67-
68-
if process.stdout:
69-
line = process.stdout.readline()
70-
if line:
71-
logger.debug(line.strip())
72-
else:
73-
time.sleep(0.1)
74-
75-
exit_code = process.returncode
76-
if exit_code not in [0, *allowed_codes]:
77-
logger.error(f"❌ Command execution failed, exit code: {exit_code}")
78-
return False
79-
return True
80-
81-
except FileNotFoundError:
82-
logger.error(f"🔍 Command not found: {cmd.split()[0]}")
83-
return False
84-
except PermissionError:
85-
logger.error(f"🔒 Insufficient permissions to execute command: {cmd}")
86-
return False
87-
except subprocess.SubprocessError as e:
88-
logger.exception(f"💥 Subprocess error: {e}")
89-
return False
90-
except OSError as e:
91-
logger.exception(f"💥 Operating system error during command execution: {e}")
92-
return False
93-
finally:
94-
if process and process.poll() is None:
95-
try:
96-
process.terminate()
97-
process.wait(timeout=5)
98-
except Exception:
99-
pass
100-
101-
10232
def discover_targets(project_name: str, oss_fuzz_dir: Path, logger: logging.Logger) -> list[str]:
10333
"""Discover fuzz targets for a project (starting with 'fuzz_', ending with 'print1', no extension, and executable)"""
10434
out_dir = oss_fuzz_dir / "build" / "out" / project_name

0 commit comments

Comments
 (0)