Skip to content

Commit

Permalink
Fix #15296 - *BSD builds (#15309) ##build
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Kochkov authored and radare committed Oct 18, 2019
1 parent 5fd8afc commit 0f430b5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions libr/io/p/io_ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ static bool __plugin_open(RIO *io, const char *file, bool many) {
return false;
}

static inline bool is_pid_already_attached (RIO *io, int pid, siginfo_t *sig) {
#ifdef __linux__
return -1 != r_io_ptrace (io, PTRACE_GETSIGINFO, pid, NULL, sig);
#else
return false;
#endif
}

static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
RIODesc *desc = NULL;
int ret = -1;
Expand All @@ -189,10 +197,9 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {

int pid = atoi (file + 9);

// Safely check if the PID has already been attached to avoid printing errors.
ret = r_io_ptrace (io, PTRACE_GETSIGINFO, pid, NULL, &sig);
// Attempt attaching on failure
if (-1 == ret) {
// Safely check if the PID has already been attached to avoid printing errors
// and attempt attaching on failure
if (!is_pid_already_attached(io, pid, &sig)) {
ret = r_io_ptrace (io, PTRACE_ATTACH, pid, 0, 0);
if (ret == -1) {
#ifdef __ANDROID__
Expand Down

0 comments on commit 0f430b5

Please sign in to comment.