libimobiledevice/libusbmuxd

usbmuxd_subscribe call back didn't call

piaojin opened this issue · 15 comments

I try to call usbmuxd_subscrib
int res = usbmuxd_subscribe(usbmux_event_cb, NULL);
And res = 0, but won't call usbmux_event_cb. 'usbmuxd_events_subscribe' API has the same issue.

static void usbmux_event_cb(const usbmuxd_event_t *event, void *user_data) {

}

Xcode 11.4
MacOS 10.15.4

I found "device_monitor" didn't call. The debug code is "USBMUXD_API int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *ctx, usbmuxd_event_cb_t callback, void *user_data)" line "int res = thread_new(&devmon, device_monitor, NULL);".
image

I have updated libimobiledevice, libplist, libusbmuxd, openssl and usbmuxd to the lastest version.

What are you doing after calling usbmuxd_subscribe? Remember this runs in a new thread so if you don't wait in the main thread (or the thread you call usbmuxd_subscribe from) it won't get a chance to call the callback function.

@nikias I call usbmuxd_subscribe in the main thread. And I just updated libimobiledevice, libplist, libusbmuxd, openssl and usbmuxd to the lastest version.

@nikias This is MacApp demo. Call usbmuxd_subscribe in applicationDidFinishLaunching. And the callback function "usbmux_event_cb" didn't be called.
MacDemo.zip

Hmm maybe it can't connect to /var/run/usbmuxd socket file? Also you are using static libs which is not really what LGPL license was meant for.

Oh actually you said device_monitor isn't called. Weird. Can you single step through usbmuxd_events_subscribe and see if it actually tries to call thread_new at all?

@nikias I single-step debugging through usbmuxd_events_subscribe and thread_new was called. The res is 0.
image

Ok now break inside device_monitor here:
https://github.com/libimobiledevice/libusbmuxd/blob/master/src/libusbmuxd.c#L1098
and see where it stops

I break inside the start line of device_monitor, but the breakpoint didn't come to the start line of device_monitor. device_monitor didn't be called.

image

Well I guess this is because you are linking in the libraries as static libraries. If you compile shared libraries and use those it will probably work.

Well I guess this is because you are linking in the libraries as static libraries. If you compile shared libraries and use those it will probably work.

Thanks, I will have a try.

@piaojin Did you solve this problem? I met it too

@piaojin Did you solve this problem? I met it too

@Glen-Bai Sorry No.

See my assumption above why this doesn't work. I know the code works if done properly, it's being used in a lot of projects, for example in checkra1n app.