From 185f9e63ff07621ef355a4c680e1fe838a2a50e6 Mon Sep 17 00:00:00 2001 From: Adrian Reber Date: Thu, 9 Jul 2026 13:02:19 +0000 Subject: [PATCH] test/exhaustive: catch Exception instead of BaseException Replace bare except clauses with except Exception to avoid catching BaseException subclasses like SystemExit and KeyboardInterrupt. Assisted-by: Claude Code (claude-opus-4-6) Signed-off-by: Adrian Reber --- test/exhaustive/pipe.py | 8 ++++---- test/exhaustive/unix.py | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/exhaustive/pipe.py b/test/exhaustive/pipe.py index 22b9317cc..a89dd7aa1 100755 --- a/test/exhaustive/pipe.py +++ b/test/exhaustive/pipe.py @@ -56,7 +56,7 @@ def make_pipes(task_nr, nr_pipes, pipes, comb, status_pipe): def get_pipe_ino(pid, fd): try: return os.stat('/proc/%d/fd/%d' % (pid, fd)).st_ino - except: + except Exception: return None @@ -205,7 +205,7 @@ def cr_test(pid): criu_bin, 'dump', '-t', '%d' % pid, '-D', img_dir, '-o', 'dump.log', '-v4', '-j' ]) - except: + except Exception: print('`- dump fail') return False @@ -215,7 +215,7 @@ def cr_test(pid): criu_bin, 'restore', '-D', img_dir, '-o', 'rst.log', '-v4', '-j', '-d', '-S' ]) - except: + except Exception: print('`- restore fail') return False @@ -248,7 +248,7 @@ def run(comb, opts): try: # Kick the test to check its state s.sendto(res, '\0CRIUPCSK') - except: + except Exception: # Restore might have failed or smth else happened os.kill(pid, signal.SIGKILL) s.close() diff --git a/test/exhaustive/unix.py b/test/exhaustive/unix.py index 26f30bdd8..5cd2f4500 100755 --- a/test/exhaustive/unix.py +++ b/test/exhaustive/unix.py @@ -476,7 +476,7 @@ def chk_real_state(st): rsk = st.real_sockets[sk.sk_id] try: s_st = os.fstat(rsk.fileno()) - except: + except Exception: print('FAIL: Socket %d lost' % sk.sk_id) return CHK_FAIL_SOCKET if not stat.S_ISSOCK(s_st.st_mode): @@ -518,7 +518,7 @@ def chk_real_state(st): acc.act(st) try: acc.do(st) - except: + except Exception: print('FAIL: Cannot accept pending connection for %d' % sk.sk_id) return CHK_FAIL_ACCEPT @@ -537,7 +537,7 @@ def chk_real_state(st): msg = sk.inqueue.pop(0) try: r_msg, m_from = rsk.recvfrom(128) - except: + except Exception: print('FAIL: No message in queue for %d' % sk.sk_id) return CHK_FAIL_RECV_0 @@ -570,7 +570,7 @@ def chk_real_state(st): try: rsk.send(msgv) rmsg = psk.recv(128) - except: + except Exception: print('FAIL: Connectivity %d -> %d lost' % (sk.sk_id, sk.peer)) return CHK_FAIL_CONNECT @@ -621,7 +621,7 @@ def chk_state(st, opts): criu_bin, "dump", "-t", "%d" % pid, "-D", img_path, "-v4", "-o", "dump.log", "-j" ]) - except: + except Exception: print("Dump failed") os.kill(pid, signal.SIGKILL) return CHK_FAIL_DUMP @@ -633,7 +633,7 @@ def chk_state(st, opts): criu_bin, "restore", "-D", img_path, "-v4", "-o", "rst.log", "-j", "-d", "-S" ]) - except: + except Exception: print("Restore failed") return CHK_FAIL_RESTORE @@ -641,7 +641,7 @@ def chk_state(st, opts): signal_sk = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0) try: signal_sk.sendto('check', sigsk_name) - except: + except Exception: # Probably the peer has died before us or smth else went wrong os.kill(pid, signal.SIGKILL)