1
0
forked from drath/libratbag

ratbagd: encode the test device iteration in the test device name

The sequence triggered by the ratbagctl.test suite is:
- DBus call Commit()
- ratbagd schedules the callback as idle func
- DBus call ResetTestDevice()
- ratbagd cleans up the test device
- callback is called on next idle
  - boom! the device is already freed

To avoid this, we need to take a ref of the device while it's being scheduled
for the commit handling. But that blocks the object paths for new test devices
because the test device name is encoded in those paths (like "hidraw" for real
devices) and it doesn't change. So let's add a count to the test device name
to make sure the new device doesn't re-use the old device's paths.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2019-07-26 09:00:05 +10:00
parent 8259c2e706
commit 71a399f20f
2 changed files with 6 additions and 2 deletions

View File

@@ -174,6 +174,7 @@ static void ratbagd_device_commit_pending(void *data)
r = ratbag_device_commit(device->lib_device);
if (r < 0)
ratbagd_device_resync(device, device->ctx->bus);
ratbagd_device_unref(device);
}
static int ratbagd_device_commit(sd_bus_message *m,
@@ -184,7 +185,7 @@ static int ratbagd_device_commit(sd_bus_message *m,
ratbagd_schedule_task(device->ctx,
ratbagd_device_commit_pending,
device);
ratbagd_device_ref(device));
CHECK_CALL(sd_bus_reply_method_return(m, "u", 0));

View File

@@ -178,10 +178,12 @@ int ratbagd_reset_test_device(sd_bus_message *m,
void *userdata,
sd_bus_error *error)
{
static int count;
static struct ratbagd_device *ratbagd_test_device = NULL;
struct ratbagd *ctx = userdata;
struct ratbag_device *device;
int r;
char devicename[64];
if (ratbagd_test_device) {
ratbagd_device_unlink(ratbagd_test_device);
@@ -196,7 +198,8 @@ int ratbagd_reset_test_device(sd_bus_message *m,
device = ratbag_device_new_test_device(ctx->lib_ctx, &ratbagd_test_device_descr);
r = ratbagd_device_new(&ratbagd_test_device, ctx, "test_device", device);
snprintf(devicename, sizeof(devicename), "test_device_%d", count++);
r = ratbagd_device_new(&ratbagd_test_device, ctx, devicename, device);
/* the ratbagd_device takes its own reference, drop ours */
ratbag_device_unref(device);