iSulad/0122-2149-archive-fork-process-set-pdeathsig.patch
openeuler-sync-bot bc22968026 !624 [sync] PR-623: upgrade from upstream
* upgrade from upstream
2023-09-19 02:54:09 +00:00

77 lines
2.6 KiB
Diff

From f43397d5c5a730e8beb14b19f934efbc7b13d493 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Tue, 29 Aug 2023 03:56:30 +0000
Subject: [PATCH 122/145] !2149 archive fork process set pdeathsig * archive
fork process set pdeathsig
---
src/utils/tar/util_archive.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/utils/tar/util_archive.c b/src/utils/tar/util_archive.c
index a6946413..19e6a6b1 100644
--- a/src/utils/tar/util_archive.c
+++ b/src/utils/tar/util_archive.c
@@ -598,7 +598,7 @@ int archive_unpack_handler(const struct io_read_wrapper *content, const struct a
ret = archive_read_open(a, mydata, NULL, read_content, NULL);
if (ret != 0) {
- SYSERROR("Failed to open archive");
+ ERROR("Failed to open archive: %s", archive_error_string(a));
fprintf(stderr, "Failed to open archive: %s", strerror(errno));
ret = -1;
goto out;
@@ -709,6 +709,13 @@ static void close_archive_pipes_fd(int *pipes, size_t pipe_size)
}
}
+static void set_child_process_pdeathsig(void)
+{
+ if (prctl(PR_SET_PDEATHSIG, SIGKILL) < 0) {
+ SYSERROR("Failed to set child process pdeathsig");
+ }
+}
+
int archive_unpack(const struct io_read_wrapper *content, const char *dstdir, const struct archive_options *options,
char **errmsg)
{
@@ -737,6 +744,8 @@ int archive_unpack(const struct io_read_wrapper *content, const char *dstdir, co
}
if (pid == (pid_t)0) {
+ set_child_process_pdeathsig();
+
keepfds[0] = isula_libutils_get_log_fd();
keepfds[1] = *(int *)(content->context);
keepfds[2] = pipe_stderr[1];
@@ -1141,6 +1150,8 @@ int archive_chroot_tar(char *path, char *file, char **errmsg)
}
if (pid == (pid_t)0) {
+ set_child_process_pdeathsig();
+
keepfds[0] = isula_libutils_get_log_fd();
keepfds[1] = pipe_for_read[1];
ret = util_check_inherited_exclude_fds(true, keepfds, 2);
@@ -1375,6 +1386,8 @@ int archive_chroot_untar_stream(const struct io_read_wrapper *context, const cha
}
if (pid == (pid_t)0) {
+ set_child_process_pdeathsig();
+
keepfds[0] = isula_libutils_get_log_fd();
keepfds[1] = pipe_stderr[1];
keepfds[2] = pipe_stream[0];
@@ -1504,6 +1517,8 @@ int archive_chroot_tar_stream(const char *chroot_dir, const char *tar_path, cons
char *tar_dir_name = NULL;
char *tar_base_name = NULL;
+ set_child_process_pdeathsig();
+
keepfds[0] = isula_libutils_get_log_fd();
keepfds[1] = pipe_stderr[1];
keepfds[2] = pipe_stream[1];
--
2.40.1