Skip to content

Commit

Permalink
Fork and execv instead of using subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
Kidev committed Jan 7, 2025
1 parent 1fe3990 commit 3169929
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions aqt/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1593,20 +1593,25 @@ def _get_install_command(self, installer_path: Path) -> list[str]:

def _exec_qt_installer(self, arguments: list[str], working_dir: str) -> None:
"""Execute Qt installer with validated arguments."""
if self.os_name == "windows":
command = [self.ALLOWED_INSTALLERS["windows"]]
command.extend(arguments)
subprocess.run(command, shell=False, check=True, cwd=working_dir)
elif self.os_name == "mac":
command = [self.ALLOWED_INSTALLERS["mac"]]
command.extend(arguments)
subprocess.run(command, shell=False, check=True, cwd=working_dir)
elif self.os_name == "linux":
command = [self.ALLOWED_INSTALLERS["linux"]]
command.extend(arguments)
subprocess.run(command, shell=False, check=True, cwd=working_dir)
else:
raise RuntimeError(f"Unsupported operating system: {self.os_name}")
original_cwd = os.getcwd()
os.chdir(working_dir)
try:
if sys.platform == "win32":
os.spawnv(os.P_WAIT, "qt-unified-windows-x64-online.exe", ["qt-unified-windows-x64-online.exe"] + arguments)

Check failure on line 1600 in aqt/installer.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

aqt/installer.py#L1600

Found dynamic content when spawning a process.

Check warning on line 1600 in aqt/installer.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

aqt/installer.py#L1600

Starting a process without a shell.
else:
pid = os.fork()
if pid == 0: # Child process
if self.os_name == "mac":
os.execv("qt-unified-macOS-x64-online.dmg", ["qt-unified-macOS-x64-online.dmg"] + arguments)

Check warning on line 1605 in aqt/installer.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

aqt/installer.py#L1605

Starting a process without a shell.
elif self.os_name == "linux":
os.execv("qt-unified-linux-x64-online.run", ["qt-unified-linux-x64-online.run"] + arguments)

Check warning on line 1607 in aqt/installer.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

aqt/installer.py#L1607

Starting a process without a shell.
sys.exit(1)
else: # Parent process
_, status = os.waitpid(pid, 0)
if status != 0:
raise RuntimeError(f"Qt installation failed with status {status}")
finally:
os.chdir(original_cwd) # Restore original working directory

def install(self) -> None:
if (
Expand Down

0 comments on commit 3169929

Please sign in to comment.