refactor(simulator): --log output path respects --segregate

This commit is contained in:
tadeubas 2025-12-31 12:54:56 -03:00 committed by doc-hex
parent c1e17d3a26
commit da1d6e28bd
2 changed files with 5 additions and 6 deletions

View File

@ -63,7 +63,7 @@ wallet (on testnet, always with the same seed). But there are other options:
- `--segregate` => scroll down to `Running simulators in parallel` section
- `--bricked` => simulate a system w/ bricked SE1: no more pin tries, etc.
- `--fails N` => simulate N wrong PIN attempts before login, where (1 <= N <= 13)
- `--log` => enable logging to `/tmp/cc-simulators/<pid>/cc_simulator.log`
- `--log` => enable logging to `/tmp/cc_simulator.log`, or to `/tmp/cc-simulators/<pid>/cc_simulator.log` when used with `--segregate`
See `variant/sim_settings.py` for the details of settings-related options.

View File

@ -863,12 +863,15 @@ Q1 specials:
cc_mpy = os.path.join(cwd, "coldcard-mpy")
sim_boot = os.path.join(cwd, "sim_boot.py")
log_base_dir = "/tmp"
if segregate:
os.makedirs("/tmp/cc-simulators", exist_ok=True)
os.chdir("/tmp/cc-simulators")
# our new work /tmp/cc-simulators/<PID>
os.mkdir(str(pid))
os.chdir(str(pid))
log_base_dir = os.getcwd()
os.mkdir("MicroSD")
os.mkdir("settings")
os.mkdir("VirtDisk")
@ -907,11 +910,7 @@ Q1 specials:
log = ("--log" in sys.argv)
if log:
logfile = '/tmp/cc-simulators/%d/cc_simulator.log' % pid
# create dir for the file in /tmp
os.makedirs(os.path.dirname(logfile), exist_ok=True)
logfile = os.path.join(log_base_dir, 'cc_simulator.log')
# create or truncate logfile and set correct permissions before starting xterm
file_desc = os.open(logfile, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o644)
os.close(file_desc)