[CRIU] [PATCH] signal: fix logig about SIGMAX (v2)

Andrey Vagin avagin at openvz.org
Mon Dec 3 09:35:26 EST 2012


A value of signo is in [1, SIGMAX].
Currenly signals are enumirated from 1 to SIGMAX, but SIGMAX
is not included. This patch fixes this mestake.

v2: * save backward compatibility
    * set a correct value of SIGMAX = 64. It can not be in a
    separate patch, because a format is changed again.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-restore.c       | 17 +++++++++++++----
 include/types.h    |  3 ++-
 parasite-syscall.c |  8 +++++---
 pie/parasite.c     |  6 ++++--
 4 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index ddc0737..78ee82d 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -531,11 +531,20 @@ static int prepare_sigactions(int pid)
 	if (fd_sigact < 0)
 		return -1;
 
-	for (sig = 1; sig < SIGMAX; sig++) {
+	for (sig = 1; sig <= SIGMAX; sig++) {
 		if (sig == SIGKILL || sig == SIGSTOP)
 			continue;
 
-		ret = pb_read_one(fd_sigact, &e, PB_SIGACT);
+		ret = pb_read_one_eof(fd_sigact, &e, PB_SIGACT);
+		if (ret == 0) {
+			if (sig != SIGMAX_OLD + 1) { /* backward compatibility */
+				pr_err("Unexpected EOF %d\n", sig);
+				ret = -1;
+				break;
+			}
+			pr_warn("This format of sigacts-%d.img is depricated\n", pid);
+			break;
+		}
 		if (ret < 0)
 			break;
 
@@ -649,7 +658,7 @@ static void zombie_prepare_signals(void)
 	memset(&act, 0, sizeof(act));
 	act.sa_handler = SIG_DFL;
 
-	for (sig = 1; sig < SIGMAX; sig++)
+	for (sig = 1; sig <= SIGMAX; sig++)
 		sigaction(sig, &act, NULL);
 }
 
@@ -684,7 +693,7 @@ static void zombie_prepare_signals(void)
 
 static inline int sig_fatal(int sig)
 {
-	return (sig > 0) && (sig < SIGMAX) && (SIG_FATAL_MASK & (1 << sig));
+	return (sig > 0) && (sig < SIGMAX) && (SIG_FATAL_MASK & (1UL << sig));
 }
 
 struct task_entries *task_entries;
diff --git a/include/types.h b/include/types.h
index ab09e28..29b27ec 100644
--- a/include/types.h
+++ b/include/types.h
@@ -61,7 +61,8 @@
 #define CLONE_CHILD_USEPID      0x02000000
 #define CLONE_VFORK		0x00004000
 
-#define SIGMAX			32
+#define SIGMAX			64
+#define SIGMAX_OLD		31
 
 #define ERESTARTSYS		512
 #define ERESTARTNOINTR		513
diff --git a/parasite-syscall.c b/parasite-syscall.c
index b2a1570..708b1b9 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -437,7 +437,7 @@ int parasite_dump_thread_seized(struct parasite_ctl *ctl, pid_t pid,
 int parasite_dump_sigacts_seized(struct parasite_ctl *ctl, struct cr_fdset *cr_fdset)
 {
 	struct parasite_dump_sa_args *args;
-	int ret, i, fd;
+	int ret, sig, fd;
 	SaEntry se = SA_ENTRY__INIT;
 
 	args = parasite_args(ctl, struct parasite_dump_sa_args);
@@ -448,8 +448,10 @@ int parasite_dump_sigacts_seized(struct parasite_ctl *ctl, struct cr_fdset *cr_f
 
 	fd = fdset_fd(cr_fdset, CR_FD_SIGACT);
 
-	for (i = 1; i < SIGMAX; i++) {
-		if (i == SIGSTOP || i == SIGKILL)
+	for (sig = 1; sig <= SIGMAX; sig++) {
+		int i = sig - 1;
+
+		if (sig == SIGSTOP || sig == SIGKILL)
 			continue;
 
 		ASSIGN_TYPED(se.sigaction, args->sas[i].rt_sa_handler);
diff --git a/pie/parasite.c b/pie/parasite.c
index fcfcf27..d9e2a1d 100644
--- a/pie/parasite.c
+++ b/pie/parasite.c
@@ -247,11 +247,13 @@ static int dump_sigact(struct parasite_dump_sa_args *da)
 {
 	int sig, ret = 0;
 
-	for (sig = 1; sig < SIGMAX; sig++) {
+	for (sig = 1; sig <= SIGMAX; sig++) {
+		int i = sig - 1;
+
 		if (sig == SIGKILL || sig == SIGSTOP)
 			continue;
 
-		ret = sys_sigaction(sig, NULL, &da->sas[sig], sizeof(rt_sigset_t));
+		ret = sys_sigaction(sig, NULL, &da->sas[i], sizeof(rt_sigset_t));
 		if (ret < 0) {
 			pr_err("sys_sigaction failed\n");
 			break;
-- 
1.7.11.7



More information about the CRIU mailing list