!462 fix lost return codes of spawned processe

Merge pull request !462 from zmr_2020/master
This commit is contained in:
haozi007 2023-05-06 09:20:18 +00:00 committed by Gitee
commit 2d20e993c6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 47 additions and 1 deletions

View File

@ -0,0 +1,39 @@
From 4ebca5a005afbc19c08f663e24d3e76518d12fa8 Mon Sep 17 00:00:00 2001
From: Mohammed Ajmal Siddiqui <ajmalsiddiqui21@gmail.com>
Date: Wed, 5 Oct 2022 12:20:58 +0530
Subject: [PATCH] lxc-attach: Fix lost return codes of spawned processes that
are killed
lxc-attach swallows the return codes of processes that are terminated
via a signal, and by default exits with a return code of 0 (i.e.
indicating success) even if the command it tried to execute was
terminated.
This patch fixes it by explicitly checking if the process was terminated
via a signal, and returning an appropriate exit code.
Note that we add 128 to the signal value to generate the exit code
because by convention the exit code is 128 + signal number. e.g. if a
process is killed via signal 9, then the error code is 9 + 128 = 137.
Signed-off-by: Mohammed Ajmal Siddiqui <ajmalsiddiqui21@gmail.com>
---
src/lxc/tools/lxc_attach.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c
index fa303c7b4..6482b0aee 100644
--- a/src/lxc/tools/lxc_attach.c
+++ b/src/lxc/tools/lxc_attach.c
@@ -399,6 +399,8 @@ int lxc_attach_main(int argc, char *argv[])
}
if (WIFEXITED(ret))
wexit = WEXITSTATUS(ret);
+ else if (WIFSIGNALED(ret))
+ wexit = WTERMSIG(ret) + 128;
out:
lxc_container_put(c);
--
2.33.0

View File

@ -1,4 +1,4 @@
%global _release 2022102417
%global _release 2022102418
Name: lxc
Version: 4.0.3
@ -38,6 +38,7 @@ Patch0027: 0027-add-loongarch64-support-for-lxc.patch
Patch0028: 0028-use-ocihooks-env-after-getenv.patch
Patch0029: 0029-fix-mixed-use-of-signed-and-unsigned-type.patch
Patch0030: 0030-remove-unused-meminfo-stats.patch
Patch0031: 0031-lxc-attach-Fix-lost-return-codes-of-spawned-processe.patch
BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath
BuildRequires: pkgconfig(libseccomp)
@ -224,6 +225,12 @@ rm -rf %{buildroot}%{_sysconfdir}/default/%{name}
%endif
%changelog
* Thu May 04 2023 Jian Zhang<zhang_jian7@hoperun.com> - 4.0.3-2022102418
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: fix lost return codes of spawned processe
* Fri Apr 21 2023 zhangxiaoyu<zhangxiaoyu58@huawei.com> - 4.0.3-2022102417
- Type:bugfix
- ID:NA