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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass negative error code to Error::from_raw_os_error #693

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

honsunrise
Copy link
Contributor

Since libbpf_get_error always returns negative error code, it should be inverted before passing in Error::from_raw_os_error.

@danielocfb
Copy link
Collaborator

What's the call you made that failed with a negative error code in this way @honsunrise ?

@honsunrise
Copy link
Contributor Author

The call stack:

thread 'runtime::tests::runtime_loop_test' panicked at /builds/collie/agent/.cargo/registry/src/mirrors.dev.in.chaitin.net-466efa1d1eb93b42/libbpf-rs-0.22.1/src/error.rs:334:9:
OS error code should be positive integer; got: -2
stack backtrace:
   0:     0x5651f4d77716 - std::backtrace_rs::backtrace::libunwind::trace::h24a2eb3edb39d0f3
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x5651f4d77716 - std::backtrace_rs::backtrace::trace_unsynchronized::h9690b32974005e28
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5651f4d77716 - std::sys_common::backtrace::_print_fmt::h50333491dc4fc462
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x5651f4d77716 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he8279f297710df71
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x5651f4da644c - core::fmt::rt::Argument::fmt::h4c6b6c3e0f65b4f1
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/core/src/fmt/rt.rs:142:9
   5:     0x5651f4da644c - core::fmt::write::h361c1f46d14a47aa
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/core/src/fmt/mod.rs:1120:17
   6:     0x5651f4d7388f - std::io::Write::write_fmt::h7e6f4046f5f4bd4f
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/std/src/io/mod.rs:1846:15
   7:     0x5651f4d774c4 - std::sys_common::backtrace::_print::hb7c6965646d03340
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x5651f4d774c4 - std::sys_common::backtrace::print::h2d4726478ed3fcc3
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x5651f4d791ab - std::panicking::default_hook::{{closure}}::h349609a89998c39e
  10:     0x5651f4d78e8b - std::panicking::default_hook::h56f95df654325ad9
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/std/src/panicking.rs:289:9
  11:     0x5651f3025b37 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hf64406b5442f710d
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/alloc/src/boxed.rs:2030:9
  12:     0x5651f3025b37 - test::test_main::{{closure}}::h974315e22cc09cfb
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/test/src/lib.rs:138:21
  13:     0x5651f4d797e0 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h3ba55c6055e52deb
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/alloc/src/boxed.rs:2030:9
  14:     0x5651f4d797e0 - std::panicking::rust_panic_with_hook::h98b728a1b3f62701
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/std/src/panicking.rs:783:13
  15:     0x5651f4d79522 - std::panicking::begin_panic_handler::{{closure}}::h3998c72d5aeca2ca
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/std/src/panicking.rs:657:13
  16:     0x5651f4d77bf6 - std::sys_common::backtrace::__rust_end_short_backtrace::h4da7fe95a2aa1e6f
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/std/src/sys_common/backtrace.rs:171:18
  17:     0x5651f4d79254 - rust_begin_unwind
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/std/src/panicking.rs:645:5
  18:     0x5651f275ecc5 - core::panicking::panic_fmt::h9fa2a341c4c930d8
                               at /rustc/878c8a2a62d49ca5c454547ad67290a1df746cb5/library/core/src/panicking.rs:72:14
  19:     0x5651f35092cc - libbpf_rs::error::Error::from_raw_os_error::he287ba41575176a6
                               at /builds/collie/agent/.cargo/registry/src/mirrors.dev.in.chaitin.net-466efa1d1eb93b42/libbpf-rs-0.22.1/src/error.rs:334:9
  20:     0x5651f350f08c - libbpf_rs::util::create_bpf_entity_checked_opt::h5432dc8835851f96
                               at /builds/collie/agent/.cargo/registry/src/mirrors.dev.in.chaitin.net-466efa1d1eb93b42/libbpf-rs-0.22.1/src/util.rs:124:20
  21:     0x5651f350ef1a - libbpf_rs::util::create_bpf_entity_checked::h64b4241ba097e860
                               at /builds/collie/agent/.cargo/registry/src/mirrors.dev.in.chaitin.net-466efa1d1eb93b42/libbpf-rs-0.22.1/src/util.rs:93:5
  22:     0x5651f3502e29 - libbpf_rs::program::Program::attach_tracepoint_impl::h5af7f392f33cff5e
                               at /builds/collie/agent/.cargo/registry/src/mirrors.dev.in.chaitin.net-466efa1d1eb93b42/libbpf-rs-0.22.1/src/program.rs:628:9
  23:     0x5651f34bb1f6 - libbpf_rs::program::Program::attach_tracepoint::h96e81702024b3a5d
                               at /builds/collie/agent/.cargo/registry/src/mirrors.dev.in.chaitin.net-466efa1d1eb93b42/libbpf-rs-0.22.1/src/program.rs:662:9

@honsunrise
Copy link
Contributor Author

What's the call you made that failed with a negative error code in this way @honsunrise ?

Error::from_raw_os_error check the error code must be positive integer.

#[inline]
pub fn from_raw_os_error(code: i32) -> Self {
debug_assert!(
code > 0,
"OS error code should be positive integer; got: {code}"
);
Self::from(io::Error::from_raw_os_error(code))
}

Copy link
Collaborator

@danielocfb danielocfb left a comment

Choose a reason for hiding this comment

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

Thanks!

@danielocfb danielocfb merged commit 7cd094e into libbpf:master Mar 6, 2024
12 checks passed
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.

2 participants