Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Better error reporting if attaching to a child fails.

  • Loading branch information...
commit 61ea2b910b0d4ee582dd717532c98c54d70372f0 1 parent c2c4701
Nelson Elhage authored

Showing 2 changed files with 9 additions and 9 deletions. Show diff stats Hide diff stats

  1. 16  attach.c
  2. 2  reptyr.c
16  attach.c
@@ -105,14 +105,14 @@ int attach_child(pid_t pid, const char *pty) {
105 105
 
106 106
 
107 107
     if (ptrace_attach_child(&child, pid))
108  
-        return errno;
  108
+        return child.error;
109 109
 
110 110
     if (ptrace_advance_to_state(&child, ptrace_at_syscall)) {
111  
-        err = errno;
  111
+        err = child.error;
112 112
         goto out_detach;
113 113
     }
114 114
     if (ptrace_save_regs(&child)) {
115  
-        err = errno;
  115
+        err = child.error;
116 116
         goto out_detach;
117 117
     }
118 118
 
@@ -120,8 +120,8 @@ int attach_child(pid_t pid, const char *pty) {
120 120
                                          PAGE_SIZE, PROT_READ|PROT_WRITE,
121 121
                                          MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
122 122
 
123  
-    if (scratch_page > (unsigned long)-100) {
124  
-        err = scratch_page;
  123
+    if (scratch_page > (unsigned long)-1000) {
  124
+        err = -(signed long)scratch_page;
125 125
         goto out_unmap;
126 126
     }
127 127
 
@@ -129,12 +129,12 @@ int attach_child(pid_t pid, const char *pty) {
129 129
 
130 130
     child_tty_fds = get_child_tty_fds(&child, &n_fds);
131 131
     if (!child_tty_fds) {
132  
-        err = -1;
  132
+        err = child.error;
133 133
         goto out_unmap;
134 134
     }
135 135
 
136 136
     if (ptrace_memcpy_to_child(&child, scratch_page, pty, strlen(pty)+1)) {
137  
-        err = errno;
  137
+        err = child.error;
138 138
         goto out_free_fds;
139 139
     }
140 140
 
@@ -177,7 +177,7 @@ int attach_child(pid_t pid, const char *pty) {
177 177
     dummy.state = ptrace_after_syscall;
178 178
     memcpy(&dummy.user, &child.user, sizeof child.user);
179 179
     if (ptrace_restore_regs(&dummy)) {
180  
-        err = errno;
  180
+        err = dummy.error;
181 181
         goto out_kill;
182 182
     }
183 183
 
2  reptyr.c
@@ -145,7 +145,7 @@ int main(int argc, char **argv) {
145 145
         pid_t child = atoi(argv[1]);
146 146
         int err;
147 147
         if ((err = attach_child(child, ptsname(pty)))) {
148  
-            fprintf(stderr, "Attaching to child: %s\n", strerror(-err));
  148
+            fprintf(stderr, "Unable to attach to pid %d: %s\n", child, strerror(err));
149 149
             return 1;
150 150
         }
151 151
     } else {

0 notes on commit 61ea2b9

Please sign in to comment.
Something went wrong with that request. Please try again.