Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

usdt: fail when binary doesn't exist. Fixes #1749 #1762

Merged
merged 1 commit into from
May 18, 2018

Conversation

javierhonduco
Copy link
Contributor

@javierhonduco javierhonduco commented May 15, 2018

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.

Let me know if there are better approaches to do this (first steps in C++ here 馃槃)!

@yonghong-song
Copy link
Collaborator

[buildbot, ok to test]

else
} else {
struct stat buffer;
if ((strlen(path) >= 1 && path[0] != '/' ) || stat(path, &buffer) == -1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put the error messages here? You can see from libbpf.c and usdt.cc where a lot of errors are printed out simply with fprintf(stderr, ...). This way, in python, you do not need to check startwith('/' or open(path) any more, you can just throw an exception since the detailed errors and hints have been printed out.

If you added the error messages in bcc_usdt_new_frompid, C++ and lua will be automatically covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! I was somehow trying to avoid printing from there for some reason. Should have checked before if that was done in these files :)

@@ -129,10 +129,28 @@ def __init__(self, pid=None, path=None):
self.pid = pid
if path:
self.context = lib.bcc_usdt_new_frompid(pid, path.encode('ascii'))
if self.context == None:
if not path.startswith('/'):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole if ... else ... can be done in usdt.cc.

@javierhonduco javierhonduco force-pushed the usdt-inexistent-path branch 2 times, most recently from e851ce6 to 92b436d Compare May 15, 2018 17:26
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.
@javierhonduco
Copy link
Contributor Author

@yonghong-song I think it's ready for a second review 馃槃

BTW, didn't add the checks to bcc_usdt_new_frompath, because I couldn't make tools/trace.py work only with the path without a pid. Once I manage to make that work I would create another PR to add the check to that function as well :)

@yonghong-song
Copy link
Collaborator

LGTM. Thanks!

@yonghong-song yonghong-song merged commit 9733011 into iovisor:master May 18, 2018
@javierhonduco javierhonduco deleted the usdt-inexistent-path branch May 18, 2018 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants