Skip to content

Commit

Permalink
Merge pull request iovisor#1762 from javierhonduco/usdt-inexistent-path
Browse files Browse the repository at this point in the history
usdt: fail when binary doesn't exist. Fixes iovisor#1749
  • Loading branch information
yonghong-song committed May 18, 2018
2 parents 19b7f74 + dcb9b9a commit 9733011
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 9733011

Please sign in to comment.