pi-shorthand 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/linux-observer.c +6 -4
- package/package.json +1 -1
package/linux-observer.c
CHANGED
|
@@ -94,17 +94,20 @@ static void capture(const char *file, char kind) {
|
|
|
94
94
|
if (*relative == '/') relative++;
|
|
95
95
|
request(kind, *relative ? relative : ".", "");
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
/* Returns 0 when the stopped thread is gone (ESRCH): SIGKILL or a sibling's exec retired it, so the syscall it
|
|
98
|
+
* stopped in never executes and there is nothing to observe. */
|
|
99
|
+
static int trace_string(pid_t pid, uint64_t address, char result[PATH_MAX]) {
|
|
98
100
|
for (size_t offset = 0; offset < PATH_MAX;) {
|
|
99
101
|
uintptr_t location = address + offset;
|
|
100
102
|
size_t skip = location % sizeof(long);
|
|
101
103
|
errno = 0;
|
|
102
104
|
long word = ptrace(PTRACE_PEEKDATA, pid, (void *)(location - skip), 0);
|
|
105
|
+
if (errno == ESRCH) return 0;
|
|
103
106
|
if (errno) die("cannot inspect syscall path");
|
|
104
107
|
size_t count = sizeof(word) - skip;
|
|
105
108
|
if (count > PATH_MAX - offset) count = PATH_MAX - offset;
|
|
106
109
|
memcpy(result + offset, (char *)&word + skip, count);
|
|
107
|
-
if (memchr((char *)&word + skip, 0, count)) return;
|
|
110
|
+
if (memchr((char *)&word + skip, 0, count)) return 1;
|
|
108
111
|
offset += count;
|
|
109
112
|
}
|
|
110
113
|
die("overlong syscall path");
|
|
@@ -267,8 +270,7 @@ static void resolve_name(pid_t pid, int fd, const char *input, int follow, char
|
|
|
267
270
|
}
|
|
268
271
|
static void resolve_path(pid_t pid, int fd, uint64_t address, int follow, char result[PATH_MAX]) {
|
|
269
272
|
char input[PATH_MAX];
|
|
270
|
-
if (!address) { result[0] = 0; return; }
|
|
271
|
-
trace_string(pid, address, input);
|
|
273
|
+
if (!address || !trace_string(pid, address, input)) { result[0] = 0; return; }
|
|
272
274
|
resolve_name(pid, fd, input, follow, result);
|
|
273
275
|
}
|
|
274
276
|
|