Skip to content

Commit

Permalink
usdt: fail when binary doesn't exist. Fixes iovisor#1749
Browse files Browse the repository at this point in the history
And add error message to hint if the problem is that the passed binary
path is not absolute or if the binary doesn't exist.

In case the PID is correct:

* but the binary couldn't be found, it will print:

  ```
  HINT: Specified binary doesn't exist.
  [...]
  ```

* but the binary is not absolute:

  ```
  HINT: Binary path should be absolute.
  [...]
  ```

Otherwise, it should keep behaving as before.
  • Loading branch information
javierhonduco committed May 18, 2018
1 parent 03a0e2b commit dcb9b9a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/cc/usdt/usdt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <unordered_set>

#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

Expand Down Expand Up @@ -393,10 +394,19 @@ extern "C" {
void *bcc_usdt_new_frompid(int pid, const char *path) {
USDT::Context *ctx;

if (!path)
if (!path) {
ctx = new USDT::Context(pid);
else
} else {
struct stat buffer;
if (strlen(path) >= 1 && path[0] != '/') {
fprintf(stderr, "HINT: Binary path should be absolute.\n\n");
return nullptr;
} else if (stat(path, &buffer) == -1) {
fprintf(stderr, "HINT: Specified binary doesn't exist.\n\n");
return nullptr;
}
ctx = new USDT::Context(pid, path);
}
if (!ctx->loaded()) {
delete ctx;
return nullptr;
Expand Down

0 comments on commit dcb9b9a

Please sign in to comment.