Skip to content

Commit

Permalink
audio: fix reacting on mic enable/disable requests
Browse files Browse the repository at this point in the history
First of all, after getting an event of QubesDB FD, actually call
qdb_read_watch() so the event is cleared and the next one can be
received.

But that's not enough. libqubesdb's queueing of watches doesn't handle
well using the same connection for both watches and commands, and using
non-blocking mode (monitoring qdb_watch_fd(), instead of calling
qdb_read_watch() in a loop). While this issue wants fixing on the
libqubesdb side, for now use separate connection to workaround the
issue.

Fixes QubesOS/qubes-issues#9619
  • Loading branch information
marmarek committed Dec 6, 2024
1 parent 11703f4 commit 97c9e36
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
27 changes: 23 additions & 4 deletions pulse/pacat-simple-vchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,10 +847,19 @@ static void control_socket_callback(pa_mainloop_api *UNUSED(a),

struct userdata *u = userdata;
int new_rec_allowed = -1;
char *watch_path;

if (!(f & PA_IO_EVENT_INPUT))
return;

watch_path = qdb_read_watch(u->watch_qdb);
if (!watch_path) {
pacat_log("Failed to read the qdb watch");
return;
}
/* don't bother checking which watch fired, there is just one */
free(watch_path);

new_rec_allowed = is_rec_allowed_from_qdb(u);
if (new_rec_allowed >= 0) {
g_mutex_lock(&u->prop_mutex);
Expand Down Expand Up @@ -903,13 +912,20 @@ static int setup_control(struct userdata *u) {
u->qdb_config_path = NULL;
goto fail;
}

// Setup a QubesDB watch to get authorization on demand
if (!qdb_watch(u->qdb, u->qdb_config_path)) {
u->watch_qdb = qdb_open(NULL);
if (!u->watch_qdb) {
pacat_log("qdb_open (watch) failed: %s", strerror(errno));
goto fail;
}

if (!qdb_watch(u->watch_qdb, u->qdb_config_path)) {
pacat_log("failed to setup watch on %s: %m\n", u->qdb_config_path);
goto fail;
}

socket_fd = qdb_watch_fd(u->qdb);
socket_fd = qdb_watch_fd(u->watch_qdb);
if (socket_fd < 0)
goto fail;

Expand Down Expand Up @@ -946,8 +962,9 @@ static int setup_control(struct userdata *u) {
if (u->control_socket_event)
u->mainloop_api->io_free(u->control_socket_event);
u->control_socket_event = NULL;
if (socket_fd >= 0)
close(socket_fd);
if (u->watch_qdb)
qdb_close(u->watch_qdb);
u->watch_qdb = NULL;

return 1;
}
Expand All @@ -964,6 +981,8 @@ static void control_cleanup(struct userdata *u) {
free(u->qdb_status_path);
if (u->qdb_request_path)
free(u->qdb_request_path);
if (u->watch_qdb)
qdb_close(u->watch_qdb);
if (u->qdb)
qdb_close(u->qdb);
}
Expand Down
1 change: 1 addition & 0 deletions pulse/pacat-simple-vchan.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct userdata {

GMutex prop_mutex;
qdb_handle_t qdb;
qdb_handle_t watch_qdb; // separate connection for watches
char *qdb_config_path;
char *qdb_status_path;
char *qdb_request_path;
Expand Down

0 comments on commit 97c9e36

Please sign in to comment.