Comments (15)
As an aside, I also noticed that I get two events for every plug and unplug. Is there a way to prevent that?
from systemd.
Now here's where it gets weird. If you plug in a device and then start watching events, then unplug the device, all fields are empty except Vendor and Vendor ID, which have garbage data (
//////�
and�����
, respectively).On unplug,
Vendor ID
is always garbage (�����
).
smells a lot like a memory corruption in your code. Maybe valgrind the thing?
from systemd.
I don't grok your code. you never allocate an event loop, not sure how anything would work there. Hence sd_device_monitor_get_event() should always return NULL?
from systemd.
As an aside, I also noticed that I get two events for every plug and unplug. Is there a way to prevent that?
my edcuated guess, it's the "add" and "bind" events. i.e. use sd_device_get_action() to see which event it is
from systemd.
As an aside, I also noticed that I get two events for every plug and unplug. Is there a way to prevent that?
my edcuated guess, it's the "add" and "bind" events. i.e. use sd_device_get_action() to see which event it is
Thank you, I'll look into this.
I don't grok your code. you never allocate an event loop, not sure how anything would work there. Hence sd_device_monitor_get_event() should always return NULL?
No offense, but the documentation for some these libraries is just short of nonexistent.
Doesn't sd_device_monitor_new
and sd_device_monitor_start
set up an event loop? If not, how are they supposed to work in relation to sd_device_monitor_get_event
? And if not, how does this code work at all?
from systemd.
As an aside, I also noticed that I get two events for every plug and unplug. Is there a way to prevent that?
my edcuated guess, it's the "add" and "bind" events. i.e. use sd_device_get_action() to see which event it is
Thank you, I'll look into this.
I don't grok your code. you never allocate an event loop, not sure how anything would work there. Hence sd_device_monitor_get_event() should always return NULL?
No offense, but the documentation for some these libraries is just short of nonexistent.
None taken, yeah, some are better documented than others. sd-device docs could use some love.
Doesn't
sd_device_monitor_new
andsd_device_monitor_start
set up an event loop?
They do not.
If not, how are they supposed to work in relation to
sd_device_monitor_get_event
?
You attach them to an event loop via sd_device_monitor_attach_event(). That event loop you can in turn integrate into another event loop of your choice, see sd_event_get_fd()
from systemd.
Oh... I'm surprised this code doesn't explode then.
from systemd.
I just need a simple event that runs in its own thread and spits out structures. I'll start by looking at the options available to me in sd_event (which seems to be somewhat better documented) and see what happens. Thank you for taking the time to point me in the right direction.
from systemd.
Doesn't
sd_device_monitor_new
andsd_device_monitor_start
set up an event loop?They do not.
If not, how are they supposed to work in relation to
sd_device_monitor_get_event
?You attach them to an event loop via sd_device_monitor_attach_event(). That event loop you can in turn integrate into another event loop of your choice, see sd_event_get_fd()
So, if I'm using sd_device_monitor_attach_event
, should I not use sd_device_monitor_get_event
? What is the purpose of that function?
from systemd.
After starting the event loop myself and attaching the monitor to the event loop using sd_device_monitor_attach_event
, the results are the same. I'll try to use valgrind next to see what's happening.
from systemd.
I just need a simple event that runs in its own thread
threads you say? i do hope you are not passing around the memory that sd-device gives you pointers to to other threads. sd-device/sd-event/… is not thread-safe (it's threads aware though, i.e. as long as you use an object only from a single thread you are fine), and you must copy out everything you want to pass to other threads.
from systemd.
Now here's where it gets weird. If you plug in a device and then start watching events, then unplug the device, all fields are empty except Vendor and Vendor ID, which have garbage data (
//////�
and�����
, respectively).
On unplug,Vendor ID
is always garbage (�����
).smells a lot like a memory corruption in your code. Maybe valgrind the thing?
Yep, turns out I didn't initialize the strings in the structure I'm copying the data to. The structures are now just consistently empty when the device is unplugged. It seems like this is normal though, right?
I just need a simple event that runs in its own thread
threads you say? i do hope you are not passing around the memory that sd-device gives you pointers to to other threads. sd-device/sd-event/… is not thread-safe (it's threads aware though, i.e. as long as you use an object only from a single thread you are fine), and you must copy out everything you want to pass to other threads.
I read that in the documentation. I haven't added threading yet; I'm just trying to get it running the way I expect it to first (and it looks like I just did; no issues reported by valgrind).
from systemd.
I got the application running now. Thank you so much for your help. Unfortunately, I now have to restructure some more of the program I was writing to accommodate for the fact that unplugging a device returns nothing from the sd_device_get_property_value
functions, but that shouldn't be anywhere near as painful.
from systemd.
Yep, turns out I didn't initialize the strings in the structure I'm copying the data to. The structures are now just consistently empty when the device is unplugged. It seems like this is normal though, right?
Yes, that's correct. When a device goes away we cannot talk to it anymore. Hence most props are gone by then.
from systemd.
I should have realized that. Thank you for all your help, Mr. Poettering! You are a gentleman, and a scholar.
from systemd.
Related Issues (20)
- Try unlock with FIDO2 key before asking for password(/PIN). HOT 2
- systemd.network Kind=/Type= ambiguity
- systemd.network Name=enp* matches eno* HOT 4
- IPv6 Compliance Failure Summary (April 25, 2024)
- systemctl hibernate error message on "not enough space" could use more detail
- machined: Assertion '(_error) != 0' failed at src/shared/discover-image.c:1450, function image_read_metadata(). Aborting. (in developer mode)
- WorkingDirectory= feature to normalize or ability to use ".." ? HOT 1
- systemd-repart: document implied copy deny lists, and how to cancel them out HOT 3
- IPv6 Compliance RFC4862: Address Lifetime Expiry (Hosts Only) [v6LC.3.2.2] HOT 3
- sysupdate / Automatic Boot Assessment: For rootfs image as well?
- systemd-repart refuses to copy blocks from unaligned files HOT 1
- Add missing plain dm-crypt options
- Please allow partition numbers to be overriden HOT 4
- Resolved uses wrong dns HOT 1
- `uaccess` tag by default for dma_heap subsystem HOT 3
- TEST-63-PATH is flaky in Github Actions HOT 1
- Support for @current, @oneshot and @default for systemctl reboot --boot-loader-entry
- LoadCredential= doesn't fail with 243/CREDENTIALS but silently skips if non-existent ID is specified (without explicit PATH) HOT 6
- run0: missing SELinux support
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 systemd.