Comments (9)
Hi, sorry for late reply, we've been very busy lately. Does this manifest also when you compile and run unit and integration tests? Please post the results of tests. What architecture and compiler are you using?
from sdbus-cpp.
Hello,
@kollekolli can you please try v0.2.6 or newer?
There was a fixed issue related to sdbus::Variant.
from sdbus-cpp.
I am also seeing this issue.I am using sdbus-cpp:master.
Here is my code. Get GetAll method is from the DBus interface org.freedesktop.DBus.Properties. myClass inherits from public sdbus::ProxyInterfaces<org::freedesktop::DBus::Properties_proxy>
void myClass::func()
std::map<std::string, sdbus::Variant> adapterProperties =
GetAll("org.bluez.Adapter1");
{
std::string valueType = adapterProperties["Name"].peekValueType();
logger.WriteLog(DebugLogger::DebugLevel::DEBUG_STATUS, "value type : %s",
valueType.c_str());
}
This first peekValueType works fine and prints "s"
Then I call sdbus::Variant.getstd::string(). This somehow mutates the data.
{
std::string a = adapterProperties["Name"].get<std::string>();
logger.WriteLog(DebugLogger::DebugLevel::DEBUG_STATUS,
"Creating Controller a [%s]", a.c_str());
}
When I call peekValueType again, I get a segmentation fault.
{
std::string valueType = adapterProperties["Name"].peekValueType();
logger.WriteLog(DebugLogger::DebugLevel::DEBUG_STATUS, "value type : %s",
valueType.c_str());
}
Back trace
[ STATUS ] [/org/bluez/hci0] value type : s
[ STATUS ] [/org/bluez/hci0] Creating Controller a [BlueZ 5.50]
Thread 1 "polaris-bluetoo" received signal SIGSEGV, Segmentation fault.
0x00005555555b06fa in std::char_traits<char>::length (__s=0x0) at /usr/include/c++/8.2.1/bits/char_traits.h:320
320 return __builtin_strlen(__s);
(gdb) bt
#0 0x00005555555b06fa in std::char_traits<char>::length(char const*) (__s=0x0) at /usr/include/c++/8.2.1/bits/char_traits.h:320
#1 0x00005555555b953d in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign(char const*) (this=0x7fffffffde00, __s=0x0) at /usr/include/c++/8.2.1/bits/basic_string.h:1439
#2 0x00005555555b7a3d in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(char const*) (this=0x7fffffffde00, __s=0x0) at /usr/include/c++/8.2.1/bits/basic_string.h:704
#3 0x00007ffff79f2eb3 in sdbus::Message::peekType(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) const () at /usr/local/lib64/libsdbus-c++.so.0
#4 0x00007ffff7a06b81 in sdbus::Variant::peekValueType[abi:cxx11]() const () at /usr/local/lib64/libsdbus-c++.so.0
#5 0x00005555555ce1a4 in BluetoothAdapter::BluetoothAdapter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (this=0x555555618850, objectPath="/org/bluez/hci0")
at /home/prater/src/polaris-bluetooth/ktm/src/polaris-bluetooth-adapter.cpp:25
#6 0x00005555555cc3a9 in __gnu_cxx::new_allocator<BluetoothAdapter>::construct<BluetoothAdapter, sdbus::ObjectPath const&>(BluetoothAdapter*, sdbus::ObjectPath const&)
(this=0x7fffffffdf97, __p=0x555555618850, __args#0=...) at /usr/include/c++/8.2.1/ext/new_allocator.h:136
#7 0x00005555555cbb82 in std::allocator_traits<std::allocator<BluetoothAdapter> >::construct<BluetoothAdapter, sdbus::ObjectPath const&>(std::allocator<BluetoothAdapter>&, BluetoothAdapter*, sdbus::ObjectPath const&) (__a=..., __p=0x555555618850, __args#0=...) at /usr/include/c++/8.2.1/bits/alloc_traits.h:475
#8 0x00005555555cab5c in std::_Sp_counted_ptr_inplace<BluetoothAdapter, std::allocator<BluetoothAdapter>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<sdbus::ObjectPath const&>(std::allocator<BluetoothAdapter>, sdbus::ObjectPath const&) (this=0x555555618840, __a=...) at /usr/include/c++/8.2.1/bits/shared_ptr_base.h:541
#9 0x00005555555c9428 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<BluetoothAdapter, std::allocator<BluetoothAdapter>, sdbus::ObjectPath const&>(std::_Sp_make_shared_tag, BluetoothAdapter*, std::allocator<BluetoothAdapter> const&, sdbus::ObjectPath const&) (this=0x7fffffffe148, __a=...) at /usr/include/c++/8.2.1/bits/shared_ptr_base.h:658
#10 0x00005555555c794a in std::__shared_ptr<BluetoothAdapter, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<BluetoothAdapter>, sdbus::ObjectPath const&>(std::_Sp_make_shared_tag, std::allocator<BluetoothAdapter> const&, sdbus::ObjectPath const&) (this=0x7fffffffe140, __tag=..., __a=...) at /usr/include/c++/8.2.1/bits/shared_ptr_base.h:1324
#11 0x00005555555c550b in std::shared_ptr<BluetoothAdapter>::shared_ptr<std::allocator<BluetoothAdapter>, sdbus::ObjectPath const&>(std::_Sp_make_shared_tag, std::allocator<BluetoothAdapter> const&, sdbus::ObjectPath const&) (this=0x7fffffffe140, __tag=..., __a=...) at /usr/include/c++/8.2.1/bits/shared_ptr.h:360
#12 0x00005555555c34fd in std::allocate_shared<BluetoothAdapter, std::allocator<BluetoothAdapter>, sdbus::ObjectPath const&>(std::allocator<BluetoothAdapter> const&, sdbus::ObjectPath const&)
(__a=..., __args#0=...) at /usr/include/c++/8.2.1/bits/shared_ptr.h:707
#13 0x00005555555c0d12 in std::make_shared<BluetoothAdapter, sdbus::ObjectPath const&>(sdbus::ObjectPath const&) (__args#0=...) at /usr/include/c++/8.2.1/bits/shared_ptr.h:723
#14 0x00005555555bcd2d in PolarisBluetooth::InterfacesAdded(sdbus::ObjectPath const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sdbus::Variant, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, sdbus::Variant> > >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sdbus::Variant, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, sdbus::Variant> > > > > > const&) (this=0x7fffffffe290, object=..., interfaces=std::map with 7 elements = {...}) at /home/prater/src/polaris-bluetooth/ktm/src/polaris-bluetooth.cpp:61
#15 0x00005555555bc99b in PolarisBluetooth::PolarisBluetooth() (this=0x7fffffffe290) at /home/prater/src/polaris-bluetooth/ktm/src/polaris-bluetooth.cpp:20
#16 0x00005555555af979 in main() () at /home/prater/src/polaris-bluetooth/ktm/src/main.cpp:7
I think somehow the std::string is being destroyed once the get method completes. I will try it with some trivial types and see if the behavior is the same...
from sdbus-cpp.
When using a trivial type such as a bool, the issue is still reproducible.
{
std::string valueType = adapterProperties["Powered"].peekValueType();
logger.WriteLog(DebugLogger::DebugLevel::DEBUG_STATUS, "value type : %s",
valueType.c_str());
}
{
bool a = adapterProperties["Powered"].get<bool>();
logger.WriteLog(DebugLogger::DebugLevel::DEBUG_STATUS,
"Controller is powered [%d]", a);
}
{
std::string valueType = adapterProperties["Powered"].peekValueType();
logger.WriteLog(DebugLogger::DebugLevel::DEBUG_STATUS, "value type : %s",
valueType.c_str());
}
[ STATUS ] [/org/bluez/hci0] value type : b
[ STATUS ] [/org/bluez/hci0] Controller is powered [1]
Thread 1 "polaris-bluetoo" received signal SIGSEGV, Segmentation fault.
0x00005555555b06fa in std::char_traits<char>::length (__s=0x0) at /usr/include/c++/8.2.1/bits/char_traits.h:320
320 return __builtin_strlen(__s);
(gdb) bt
#0 0x00005555555b06fa in std::char_traits<char>::length(char const*) (__s=0x0) at /usr/include/c++/8.2.1/bits/char_traits.h:320
#1 0x00005555555b953d in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign(char const*) (this=0x7fffffffde00, __s=0x0) at /usr/include/c++/8.2.1/bits/basic_string.h:1439
#2 0x00005555555b7a3d in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(char const*) (this=0x7fffffffde00, __s=0x0) at /usr/include/c++/8.2.1/bits/basic_string.h:704
#3 0x00007ffff79f2eb3 in sdbus::Message::peekType(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) const () at /usr/local/lib64/libsdbus-c++.so.0
#4 0x00007ffff7a06b81 in sdbus::Variant::peekValueType[abi:cxx11]() const () at /usr/local/lib64/libsdbus-c++.so.0
#5 0x00005555555ce176 in BluetoothAdapter::BluetoothAdapter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (this=0x555555618850, objectPath="/org/bluez/hci0")
at /home/prater/src/polaris-bluetooth/ktm/src/polaris-bluetooth-adapter.cpp:25
#6 0x00005555555cc3a9 in __gnu_cxx::new_allocator<BluetoothAdapter>::construct<BluetoothAdapter, sdbus::ObjectPath const&>(BluetoothAdapter*, sdbus::ObjectPath const&)
(this=0x7fffffffdf97, __p=0x555555618850, __args#0=...) at /usr/include/c++/8.2.1/ext/new_allocator.h:136
#7 0x00005555555cbb82 in std::allocator_traits<std::allocator<BluetoothAdapter> >::construct<BluetoothAdapter, sdbus::ObjectPath const&>(std::allocator<BluetoothAdapter>&, BluetoothAdapter*, sdbus::ObjectPath const&) (__a=..., __p=0x555555618850, __args#0=...) at /usr/include/c++/8.2.1/bits/alloc_traits.h:475
#8 0x00005555555cab5c in std::_Sp_counted_ptr_inplace<BluetoothAdapter, std::allocator<BluetoothAdapter>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<sdbus::ObjectPath const&>(std::allocator<BluetoothAdapter>, sdbus::ObjectPath const&) (this=0x555555618840, __a=...) at /usr/include/c++/8.2.1/bits/shared_ptr_base.h:541
#9 0x00005555555c9428 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<BluetoothAdapter, std::allocator<BluetoothAdapter>, sdbus::ObjectPath const&>(std::_Sp_make_shared_tag, BluetoothAdapter*, std::allocator<BluetoothAdapter> const&, sdbus::ObjectPath const&) (this=0x7fffffffe148, __a=...) at /usr/include/c++/8.2.1/bits/shared_ptr_base.h:658
#10 0x00005555555c794a in std::__shared_ptr<BluetoothAdapter, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<BluetoothAdapter>, sdbus::ObjectPath const&>(std::_Sp_make_shared_tag, std::allocator<BluetoothAdapter> const&, sdbus::ObjectPath const&) (this=0x7fffffffe140, __tag=..., __a=...) at /usr/include/c++/8.2.1/bits/shared_ptr_base.h:1324
#11 0x00005555555c550b in std::shared_ptr<BluetoothAdapter>::shared_ptr<std::allocator<BluetoothAdapter>, sdbus::ObjectPath const&>(std::_Sp_make_shared_tag, std::allocator<BluetoothAdapter> const&, sdbus::ObjectPath const&) (this=0x7fffffffe140, __tag=..., __a=...) at /usr/include/c++/8.2.1/bits/shared_ptr.h:360
#12 0x00005555555c34fd in std::allocate_shared<BluetoothAdapter, std::allocator<BluetoothAdapter>, sdbus::ObjectPath const&>(std::allocator<BluetoothAdapter> const&, sdbus::ObjectPath const&)
(__a=..., __args#0=...) at /usr/include/c++/8.2.1/bits/shared_ptr.h:707
#13 0x00005555555c0d12 in std::make_shared<BluetoothAdapter, sdbus::ObjectPath const&>(sdbus::ObjectPath const&) (__args#0=...) at /usr/include/c++/8.2.1/bits/shared_ptr.h:723
#14 0x00005555555bcd2d in PolarisBluetooth::InterfacesAdded(sdbus::ObjectPath const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sdbus::Variant, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, sdbus::Variant> > >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sdbus::Variant, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, sdbus::Variant> > > > > > const&) (this=0x7fffffffe290, object=..., interfaces=std::map with 7 elements = {...}) at /home/prater/src/polaris-bluetooth/ktm/src/polaris-bluetooth.cpp:61
#15 0x00005555555bc99b in PolarisBluetooth::PolarisBluetooth() (this=0x7fffffffe290) at /home/prater/src/polaris-bluetooth/ktm/src/polaris-bluetooth.cpp:20
#16 0x00005555555af979 in main() () at /home/prater/src/polaris-bluetooth/ktm/src/main.cpp:7
from sdbus-cpp.
I'm going to dig into the get<>() method, it must be mutating some member data.
from sdbus-cpp.
You get<>() rewinds the sdbus message prior to access, where peekValueType does not. So if you read the message, it's position is reset, then when you try to peekValueType, the message pointer is at the end, returning invalid data.
[ STATUS ] [/org/bluez/hci1] value type : b
[ STATUS ] [/org/bluez/hci1] Controller is powered [1]
[ STATUS ] [/org/bluez/hci1] value type : b
[ STATUS ] [/org/bluez/hci1] Creating Controller b [1]
[ STATUS ] [/org/bluez/hci1] Creating Controller Powered [1]
[ STATUS ] [/org/bluez/hci1] value type : s
index 71cfa38..51672ed 100644
--- a/src/Types.cpp
+++ b/src/Types.cpp
@@ -51,6 +51,7 @@ void Variant::deserializeFrom(Message& msg)
std::string Variant::peekValueType() const
{
+ msg_.rewind(false);
std::string type;
std::string contents;
msg_.peekType(type, contents);```
I'll make a PR
from sdbus-cpp.
Still not quite fixed...
what(): [org.freedesktop.DBus.Error.AccessDenied] Failed to rewind the message (Operation not permitted)
Thread 1 "polaris-bluetoo" received signal SIGABRT, Aborted.
0x00007ffff748dd7f in raise () from /usr/lib/libc.so.6
(gdb) bt
#0 0x00007ffff748dd7f in raise () at /usr/lib/libc.so.6
#1 0x00007ffff7478672 in abort () at /usr/lib/libc.so.6
#2 0x00007ffff784458e in __gnu_cxx::__verbose_terminate_handler() () at /build/gcc/src/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#3 0x00007ffff784adfa in __cxxabiv1::__terminate(void (*)()) (handler=<optimized out>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:47
#4 0x00007ffff784ae57 in std::terminate() () at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:57
#5 0x00007ffff784b0ac in __cxxabiv1::__cxa_throw(void*, std::type_info*, void (*)(void*)) (obj=<optimized out>, tinfo=0x5555555ee968 <typeinfo for sdbus::Error>, dest=0x5555555bf47a <sdbus::Error::~Error()>)
at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:95
#6 0x00007ffff79f2c45 in sdbus::Message::rewind(bool) () at /usr/local/lib64/libsdbus-c++.so.0
#7 0x00005555555c0dab in sdbus::Variant::get<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >() const (this=0x55555563c900) at /usr/local/include/sdbus-c++/Types.h:64
#8 0x00005555555d3cc6 in BluetoothDevice::BluetoothDevice(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
(this=0x55555560c820, objectPath="/org/bluez/hci1/dev_34_E0_CF_EF_CD_0F") at /home/prater/src/polaris-bluetooth/ktm/src/polaris-bluetooth-device.cpp:9
from sdbus-cpp.
This looks like get<>() threw in a noexecpt function because message had not yet been read, so rewind(false) failed. I can live with that in my local fork and have commented out
index 6aefc8c..3876e8f 100755
--- a/src/Message.cpp
+++ b/src/Message.cpp
@@ -533,7 +533,7 @@ void Message::seal()
void Message::rewind(bool complete)
{
auto r = sd_bus_message_rewind((sd_bus_message*)msg_, complete);
- SDBUS_THROW_ERROR_IF(r < 0, "Failed to rewind the message", -r);
+ // SDBUS_THROW_ERROR_IF(r < 0, "Failed to rewind the message", -r);
}
std::string Message::getInterfaceName() const
However that is not a good fix, more code should be refactored.
from sdbus-cpp.
Possibly disregard those last 2 comments, I was trying to access the std::map<std::string, sdbus::Variant> elements in an initializer list during class construction. I moved it from the initializer list to the body of the constructor and it works fine... I think it was just too early.
from sdbus-cpp.
Related Issues (20)
- CanCallMethodSynchronouslyWithoutAnEventLoopThread hangs since 1.3.0 if built by Clang HOT 8
- Disable sd-event in release/v2.0 once #358 is merged and release/v2.0 rebased HOT 2
- Support for creating tcp connections via sd_bus_set_address or sd_bus_set_fd HOT 2
- pkgconfig fails to resolve dependencies
- Tests installation path should respect install prefix
- Allow moving ProxyInterfaces HOT 2
- Error when implementing ObjectManager on System Bus Connection
- Sporadic missed NameAcquired signal if requestName called after enterEventLoopAsync HOT 2
- doesn't notice signal without method call HOT 7
- Serialization of maps into structs and vice versa
- Manually configuring choice of sd-bus implementation library HOT 4
- [org.freedesktop.DBus.Error.ServiceUnknown] The name com.example.test was not provided by any .service files HOT 5
- why: uncaught exception of type sdbus::Error ([org.freedesktop.DBus.Error.FileNotFound] Failed to open bus (No such file or directory)) HOT 1
- Crash when running a connection event loop HOT 2
- How to do IPC between two process by sdbus::createServerBus and sdbus::createDirectBusConnection
- Allow arbitrary structs in an sdbus interface HOT 4
- Support for serializing `std::variant<>` types HOT 2
- Can't receive signals by ObjectProxy at client side (but see this signals at dbus-monitor) HOT 2
- SEGFAULT after generated proxy move HOT 5
- Ambiguous Template Instantiation when trying to use enum class with sdbus-cpp HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdbus-cpp.