parasite-syscall: describe task's state on trap failure

Submitted by Dmitry Safonov on June 9, 2016, 11:56 a.m.

Details

Message ID 20160609115650.13488-1-dsafonov@virtuozzo.com
State Rejected
Series "parasite-syscall: describe task's state on trap failure"
Headers show

Commit Message

Dmitry Safonov June 9, 2016, 11:56 a.m.
I think we can improve error messages to distinguish task's kills
from segfaults from ptrace failures & etc.

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
---
 criu/parasite-syscall.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
index f9e0bac7ffbf..e8e31fb2da4a 100644
--- a/criu/parasite-syscall.c
+++ b/criu/parasite-syscall.c
@@ -934,6 +934,26 @@  static int parasite_fini_seized(struct parasite_ctl *ctl)
 	return 0;
 }
 
+static bool task_is_trapped(int status, pid_t pid)
+{
+	if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP)
+		return true;
+
+	pr_err("Task %d is in unexpected state: %x\n", pid, status);
+	if (WIFEXITED(status))
+		pr_err("Task exited with %d\n", WEXITSTATUS(status));
+	if (WIFSIGNALED(status))
+		pr_err("Task signaled with %d: %s\n",
+			WTERMSIG(status), strsignal(WTERMSIG(status)));
+	if (WIFSTOPPED(status))
+		pr_err("Task stopped with %d: %s\n",
+			WSTOPSIG(status), strsignal(WSTOPSIG(status)));
+	if (WIFCONTINUED(status))
+		pr_err("Task continued\n");
+
+	return false;
+}
+
 /*
  * Trap tasks on the exit from the specified syscall
  *
@@ -957,10 +977,8 @@  int parasite_stop_on_syscall(int tasks, const int sys_nr, enum trace_flags trace
 			return -1;
 		}
 
-		if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGTRAP) {
-			pr_err("Task is in unexpected state: %x\n", status);
+		if (!task_is_trapped(status, pid))
 			return -1;
-		}
 
 		pr_debug("%d was trapped\n", pid);
 
@@ -996,10 +1014,8 @@  int parasite_stop_on_syscall(int tasks, const int sys_nr, enum trace_flags trace
 				return -1;
 			}
 
-			if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGTRAP) {
-				pr_err("Task is in unexpected state: %x\n", status);
+			if (!task_is_trapped(status, pid))
 				return -1;
-			}
 
 			pr_debug("%d was stopped\n", pid);
 			tasks--;

Comments

Andrey Vagin June 9, 2016, 8:41 p.m.
Acked-by: Andrew Vagin <avagin@virtuozzo.com>

On Thu, Jun 09, 2016 at 02:56:50PM +0300, Dmitry Safonov wrote:
> I think we can improve error messages to distinguish task's kills
> from segfaults from ptrace failures & etc.
> 
> Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
> ---
>  criu/parasite-syscall.c | 28 ++++++++++++++++++++++------
>  1 file changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
> index f9e0bac7ffbf..e8e31fb2da4a 100644
> --- a/criu/parasite-syscall.c
> +++ b/criu/parasite-syscall.c
> @@ -934,6 +934,26 @@ static int parasite_fini_seized(struct parasite_ctl *ctl)
>  	return 0;
>  }
>  
> +static bool task_is_trapped(int status, pid_t pid)
> +{
> +	if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP)
> +		return true;
> +
> +	pr_err("Task %d is in unexpected state: %x\n", pid, status);
> +	if (WIFEXITED(status))
> +		pr_err("Task exited with %d\n", WEXITSTATUS(status));
> +	if (WIFSIGNALED(status))
> +		pr_err("Task signaled with %d: %s\n",
> +			WTERMSIG(status), strsignal(WTERMSIG(status)));
> +	if (WIFSTOPPED(status))
> +		pr_err("Task stopped with %d: %s\n",
> +			WSTOPSIG(status), strsignal(WSTOPSIG(status)));
> +	if (WIFCONTINUED(status))
> +		pr_err("Task continued\n");
> +
> +	return false;
> +}
> +
>  /*
>   * Trap tasks on the exit from the specified syscall
>   *
> @@ -957,10 +977,8 @@ int parasite_stop_on_syscall(int tasks, const int sys_nr, enum trace_flags trace
>  			return -1;
>  		}
>  
> -		if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGTRAP) {
> -			pr_err("Task is in unexpected state: %x\n", status);
> +		if (!task_is_trapped(status, pid))
>  			return -1;
> -		}
>  
>  		pr_debug("%d was trapped\n", pid);
>  
> @@ -996,10 +1014,8 @@ int parasite_stop_on_syscall(int tasks, const int sys_nr, enum trace_flags trace
>  				return -1;
>  			}
>  
> -			if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGTRAP) {
> -				pr_err("Task is in unexpected state: %x\n", status);
> +			if (!task_is_trapped(status, pid))
>  				return -1;
> -			}
>  
>  			pr_debug("%d was stopped\n", pid);
>  			tasks--;
> -- 
> 2.8.3
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
Pavel Emelianov June 10, 2016, 3:29 p.m.
Applied