Skip to content

Commit

Permalink
pacat-simple-vchan: improve cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fepitre committed Apr 26, 2024
1 parent 65cd1d7 commit c4b92a0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pulse/pacat-simple-vchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,11 @@ static void vchan_rec_async_connect(pa_mainloop_api *UNUSED(a),
connect_pa_daemon(u);
}

void cleanup_pidfile(char *pidfile_path, int pidfile_fd) {
unlink(pidfile_path);
close(pidfile_fd);
}

static _Noreturn void usage(char *arg0, int arg) {
FILE *stream = arg ? stderr : stdout;
fprintf(stream, "usage: %s [-l] [--] domid domname\n",
Expand Down Expand Up @@ -1087,12 +1092,14 @@ int main(int argc, char *argv[])
u.play_ctrl = libvchan_client_init_async(u.domid, QUBES_PA_SINK_VCHAN_PORT, &u.play_watch_fd);
if (!u.play_ctrl) {
perror("libvchan_client_init_async");
exit(1);
cleanup_pidfile(pidfile_path, pidfile_fd);
exit(u.ret);
}
u.rec_ctrl = libvchan_client_init_async(u.domid, QUBES_PA_SOURCE_VCHAN_PORT, &u.rec_watch_fd);
if (!u.rec_ctrl) {
perror("libvchan_client_init_async");
exit(1);
cleanup_pidfile(pidfile_path, pidfile_fd);
exit(u.ret);
}
if (setgid(getgid()) < 0) {
perror("setgid");
Expand Down Expand Up @@ -1223,11 +1230,10 @@ int main(int argc, char *argv[])

g_mutex_clear(&u.prop_mutex);

unlink(pidfile_path);
close(pidfile_fd);

if (!u.ret)
goto main;

cleanup_pidfile(pidfile_path, pidfile_fd);

return u.ret;
}

0 comments on commit c4b92a0

Please sign in to comment.