module-rt: don't block on method calls

Don't block on the method calls to make realtime or high priority.
Those calls don't return anything and other errors (invalid method,
invalid arguments, no service,...) can be caught differently async.

Fixes #3357
This commit is contained in:
Wim Taymans 2023-07-19 13:41:18 +02:00
parent 719e48a76d
commit 2211016516

View file

@ -414,10 +414,10 @@ static long long pw_rtkit_get_rttime_usec_max(struct impl *impl)
static int pw_rtkit_make_realtime(struct impl *impl, pid_t thread, int priority) static int pw_rtkit_make_realtime(struct impl *impl, pid_t thread, int priority)
{ {
DBusMessage *m = NULL, *r = NULL; DBusMessage *m = NULL;
dbus_uint64_t pid; dbus_uint64_t pid;
dbus_uint64_t u64; dbus_uint64_t u64;
dbus_uint32_t u32; dbus_uint32_t u32, serial;
DBusError error; DBusError error;
int ret; int ret;
struct pw_rtkit_bus *connection = impl->rtkit_bus; struct pw_rtkit_bus *connection = impl->rtkit_bus;
@ -446,17 +446,10 @@ static int pw_rtkit_make_realtime(struct impl *impl, pid_t thread, int priority)
goto finish; goto finish;
} }
if (!(r = dbus_connection_send_with_reply_and_block(connection->bus, m, -1, &error))) { if (!dbus_connection_send(connection->bus, m, &serial)) {
ret = translate_error(error.name); ret = translate_error(error.name);
goto finish; goto finish;
} }
if (dbus_set_error_from_message(&error, r)) {
ret = translate_error(error.name);
goto finish;
}
ret = 0; ret = 0;
finish: finish:
@ -464,26 +457,20 @@ finish:
if (m) if (m)
dbus_message_unref(m); dbus_message_unref(m);
if (r)
dbus_message_unref(r);
dbus_error_free(&error);
return ret; return ret;
} }
static int pw_rtkit_make_high_priority(struct impl *impl, pid_t thread, int nice_level) static int pw_rtkit_make_high_priority(struct impl *impl, pid_t thread, int nice_level)
{ {
DBusMessage *m = NULL, *r = NULL; DBusMessage *m = NULL;
dbus_uint64_t pid; dbus_uint64_t pid;
dbus_uint64_t u64; dbus_uint64_t u64;
dbus_int32_t s32; dbus_int32_t s32;
DBusError error; dbus_uint32_t serial;
int ret; int ret;
struct pw_rtkit_bus *connection = impl->rtkit_bus; struct pw_rtkit_bus *connection = impl->rtkit_bus;
dbus_error_init(&error);
if (thread == 0) if (thread == 0)
thread = _gettid(); thread = _gettid();
@ -505,20 +492,10 @@ static int pw_rtkit_make_high_priority(struct impl *impl, pid_t thread, int nice
ret = -ENOMEM; ret = -ENOMEM;
goto finish; goto finish;
} }
if (!dbus_connection_send(connection->bus, m, &serial)) {
ret = -EIO;
if (!(r = dbus_connection_send_with_reply_and_block(connection->bus, m, -1, &error))) {
ret = translate_error(error.name);
goto finish; goto finish;
} }
if (dbus_set_error_from_message(&error, r)) {
ret = translate_error(error.name);
goto finish;
}
ret = 0; ret = 0;
finish: finish:
@ -526,11 +503,6 @@ finish:
if (m) if (m)
dbus_message_unref(m); dbus_message_unref(m);
if (r)
dbus_message_unref(r);
dbus_error_free(&error);
return ret; return ret;
} }
#endif /* HAVE_DBUS */ #endif /* HAVE_DBUS */
@ -675,6 +647,9 @@ static int set_nice(struct impl *impl, int nice_level, bool warn)
if (warn) if (warn)
pw_log_warn("could not set nice-level to %d: %s", pw_log_warn("could not set nice-level to %d: %s",
nice_level, spa_strerror(res)); nice_level, spa_strerror(res));
} else if (res > 0) {
pw_log_info("main thread setting nice level to %d: %s",
nice_level, spa_strerror(-res));
} else { } else {
pw_log_info("main thread nice level set to %d", pw_log_info("main thread nice level set to %d",
nice_level); nice_level);