Permalink
Browse files

Better error reporting if attaching to a child fails.

  • Loading branch information...
nelhage committed Jan 22, 2011
1 parent c2c4701 commit 61ea2b910b0d4ee582dd717532c98c54d70372f0
Showing with 9 additions and 9 deletions.
  1. +8 −8 attach.c
  2. +1 −1 reptyr.c
View
@@ -105,36 +105,36 @@ int attach_child(pid_t pid, const char *pty) {
if (ptrace_attach_child(&child, pid))
- return errno;
+ return child.error;
if (ptrace_advance_to_state(&child, ptrace_at_syscall)) {
- err = errno;
+ err = child.error;
goto out_detach;
}
if (ptrace_save_regs(&child)) {
- err = errno;
+ err = child.error;
goto out_detach;
}
scratch_page = ptrace_remote_syscall(&child, mmap_syscall, 0,
PAGE_SIZE, PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
- if (scratch_page > (unsigned long)-100) {
- err = scratch_page;
+ if (scratch_page > (unsigned long)-1000) {
+ err = -(signed long)scratch_page;
goto out_unmap;
}
debug("Allocated scratch page: %lx", scratch_page);
child_tty_fds = get_child_tty_fds(&child, &n_fds);
if (!child_tty_fds) {
- err = -1;
+ err = child.error;
goto out_unmap;
}
if (ptrace_memcpy_to_child(&child, scratch_page, pty, strlen(pty)+1)) {
- err = errno;
+ err = child.error;
goto out_free_fds;
}
@@ -177,7 +177,7 @@ int attach_child(pid_t pid, const char *pty) {
dummy.state = ptrace_after_syscall;
memcpy(&dummy.user, &child.user, sizeof child.user);
if (ptrace_restore_regs(&dummy)) {
- err = errno;
+ err = dummy.error;
goto out_kill;
}
View
@@ -145,7 +145,7 @@ int main(int argc, char **argv) {
pid_t child = atoi(argv[1]);
int err;
if ((err = attach_child(child, ptsname(pty)))) {
- fprintf(stderr, "Attaching to child: %s\n", strerror(-err));
+ fprintf(stderr, "Unable to attach to pid %d: %s\n", child, strerror(err));
return 1;
}
} else {

0 comments on commit 61ea2b9

Please sign in to comment.