Commit 9733011a authored by yonghong-song's avatar yonghong-song Committed by GitHub

Merge pull request #1762 from javierhonduco/usdt-inexistent-path

usdt: fail when binary doesn't exist. Fixes #1749
parents 19b7f74f dcb9b9ad
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <unordered_set> #include <unordered_set>
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
...@@ -393,10 +394,19 @@ extern "C" { ...@@ -393,10 +394,19 @@ extern "C" {
void *bcc_usdt_new_frompid(int pid, const char *path) { void *bcc_usdt_new_frompid(int pid, const char *path) {
USDT::Context *ctx; USDT::Context *ctx;
if (!path) if (!path) {
ctx = new USDT::Context(pid); 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); ctx = new USDT::Context(pid, path);
}
if (!ctx->loaded()) { if (!ctx->loaded()) {
delete ctx; delete ctx;
return nullptr; return nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment