[CRIU] [PATCH 5/6] dump: store signals in core->tc->signals, instead of writing them to signal_p/s*.img

Ruslan Kuprieiev kupruser at gmail.com
Tue Aug 5 01:36:00 PDT 2014


Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 cr-dump.c | 56 ++++++++++++++++++++++++++++++--------------------------
 1 file changed, 30 insertions(+), 26 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index c8be0bd..ba9e1c2 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -701,6 +701,7 @@ int dump_thread_core(int pid, CoreEntry *core, const struct parasite_dump_thread
 static int dump_task_core_all(struct pstree_item *item,
 		const struct proc_pid_stat *stat,
 		const struct parasite_dump_misc *misc,
+		SignalsEntry *signals,
 		const struct cr_fdset *cr_fdset)
 {
 	int fd_core = fdset_fd(cr_fdset, CR_FD_CORE);
@@ -725,6 +726,8 @@ static int dump_task_core_all(struct pstree_item *item,
 	if (ret)
 		goto err;
 
+	core->tc->signals = signals;
+
 	ret = dump_task_rlimits(pid, core->tc->rlimits);
 	if (ret)
 		goto err;
@@ -1165,11 +1168,12 @@ err:
 	return ret;
 }
 
-static int dump_signal_queue(pid_t tid, int fd, bool group)
+static int dump_signal_queue(pid_t tid, SignalQueueEntry **sqe, bool group)
 {
 	struct ptrace_peeksiginfo_args arg;
 	siginfo_t siginfo[32]; /* One page or all non-rt signals */
 	int ret, i = 0, j, nr;
+	SignalQueueEntry *queue = NULL;
 
 	pr_debug("Dump %s signals of %d\n", group ? "shared" : "private", tid);
 
@@ -1178,6 +1182,12 @@ static int dump_signal_queue(pid_t tid, int fd, bool group)
 	if (group)
 		arg.flags |= PTRACE_PEEKSIGINFO_SHARED;
 
+	queue = xmalloc(sizeof(*queue));
+	if (!queue)
+		return -1;
+
+	signal_queue_entry__init(queue);
+
 	for (; ; ) {
 		arg.off = i;
 
@@ -1195,48 +1205,41 @@ static int dump_signal_queue(pid_t tid, int fd, bool group)
 			break;
 		nr = ret;
 
-		for (j = 0; j < nr; j++) {
-			SiginfoEntry sie = SIGINFO_ENTRY__INIT;
+		queue->n_signals += nr;
+		queue->signals = xrealloc(queue->signals, sizeof(*queue->signals) * queue->n_signals);
+		if (!queue->signals)
+			break;
 
-			sie.siginfo.len = sizeof(siginfo_t);
-			sie.siginfo.data = (void *) (siginfo + j);
+		for (j = queue->n_signals - nr; j < queue->n_signals; j++) {
+			queue->signals[j]->siginfo.len = sizeof(siginfo_t);
+			queue->signals[j]->siginfo.data = (void *) (siginfo + j);
 
-			ret = pb_write_one(fd, &sie, PB_SIGINFO);
-			if (ret < 0)
-				break;
 			i++;
 		}
 	}
 
-	return ret;
-}
-
-static int dump_thread_signals(struct pid *tid)
-{
-	int fd, ret;
-
-	fd = open_image(CR_FD_PSIGNAL, O_DUMP, tid->virt);
-	if (fd < 0)
-		return -1;
-	ret = dump_signal_queue(tid->real, fd, false);
-	close(fd);
+	*sqe = queue;
 
 	return ret;
 }
 
-static int dump_task_signals(pid_t pid, struct pstree_item *item,
-		struct cr_fdset *cr_fdset)
+static int dump_task_signals(pid_t pid, struct pstree_item *item, SignalsEntry *signals)
 {
 	int i, ret;
 
-	ret = dump_signal_queue(pid, fdset_fd(cr_fdset, CR_FD_SIGNAL), true);
+	ret = dump_signal_queue(pid, &signals->shared, true);
 	if (ret) {
 		pr_err("Can't dump pending signals (pid: %d)\n", pid);
 		return -1;
 	}
 
+	signals->n_private_ = item->nr_threads;
+	signals->private_ = xmalloc(sizeof(*signals->private_) * signals->n_private_);
+	if (!signals->private_)
+		return -1;
+
 	for (i = 0; i < item->nr_threads; i++) {
-		ret = dump_thread_signals(&item->threads[i]);
+		ret = dump_signal_queue(item->threads[i].real, &signals->private_[i], false);
 		if (ret)
 			return -1;
 	}
@@ -1447,6 +1450,7 @@ static int dump_one_task(struct pstree_item *item)
 	struct parasite_drain_fd *dfds = NULL;
 	struct proc_posix_timers_stat proc_args;
 	struct proc_status_creds cr;
+	SignalsEntry signals = SIGNALS_ENTRY__INIT;
 
 	INIT_LIST_HEAD(&vmas.h);
 	vmas.nr = 0;
@@ -1498,7 +1502,7 @@ static int dump_one_task(struct pstree_item *item)
 		goto err;
 	}
 
-	ret = dump_task_signals(pid, item, cr_fdset);
+	ret = dump_task_signals(pid, item, &signals);
 	if (ret) {
 		pr_err("Dump %d signals failed %d\n", pid, ret);
 		goto err;
@@ -1602,7 +1606,7 @@ static int dump_one_task(struct pstree_item *item)
 		goto err_cure;
 	}
 
-	ret = dump_task_core_all(item, &pps_buf, &misc, cr_fdset);
+	ret = dump_task_core_all(item, &pps_buf, &misc, &signals, cr_fdset);
 	if (ret) {
 		pr_err("Dump core (pid: %d) failed with %d\n", pid, ret);
 		goto err_cure;
-- 
1.9.1



More information about the CRIU mailing list