From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 5DC3B1FF0A5 for ; Thu, 19 Nov 2026 15:50:58 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 67C1B21736; Thu, 19 Nov 2026 15:50:56 +0100 (CET) From: Jordyn Hamilton To: pve-devel@lists.proxmox.com Subject: [PATCH common 2/2] Added logic to check for d state to run subroutine Date: Thu, 19 Nov 2026 09:50:11 -0500 Message-ID: <20261119145011.8017-3-j.hamilton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261119145011.8017-1-j.hamilton@proxmox.com> References: <20261119145011.8017-1-j.hamilton@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795099851702 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.093 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: YEHRP7CBCCW6443DUA5QVWDR2R5RN3RJ X-Message-ID-Hash: YEHRP7CBCCW6443DUA5QVWDR2R5RN3RJ X-MailFrom: j.hamilton@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: j.hamilton@proxmox.com, c.hughes@proxmox.com X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Within the timeout error logic branch, I added flow to check for a D state and customize the error message to reflect that state. I chose the timeout branch as the d state check would only be required if the process takes long enough to time out. Logic tree queues a `SIGKILL` prior to any D state checking, as the system would queue the signal if the process is in a D state, meaning it would auto terminate once the state resolves. This also means the standard timeout error checking remains untouched, it still sends the signal, waits for the process to terminate then dies. Since there is no way to terminate D state processes programatically, the program only overwrites the error message then terminates. It directs the user in the right direction for debugging and provides all the information necessary for beginning that process including the `$pid` and `$cmd_str`. Modified the d state error message to include that the process can only be terminated by resolving the errors or performing a system reboot. Signed-off-by: Jordyn Hamilton --- src/PVE/Cmd.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/PVE/Cmd.pm b/src/PVE/Cmd.pm index 773e55a..20cd62b 100644 --- a/src/PVE/Cmd.pm +++ b/src/PVE/Cmd.pm @@ -53,7 +53,7 @@ sub in_d_state($pid) { # extracting the stat character from the input my $status = $1 if $stat_in =~ /^\d+\s+\(.*\)\s+([A-Z])/; - return ($status eq 'D'); + return $status eq 'D'; } # The $cmd parameter can be: @@ -326,7 +326,17 @@ sub run($cmd, %param) { if ($err) { if ($pid && ($err eq "got timeout\n")) { kill(9, $pid); - waitpid($pid, 0); + if (in_d_state($pid)) { + $err = "process '$pid' is in an uninterruptible sleep " . + "and cannot resolve or be terminated by this program.\n" . + "This process can only be terminated by resolving the errors " . + "or performing a system reboot.\n" . + "This is due to underlying kernel or hardware errors, " . + "check dmesg for errors or " . + "kernel messages.\n"; + }else { + waitpid($pid, 0); + } die "command '$cmdstr' failed: $err"; } -- 2.47.3