@@ -1032,10 +1032,8 @@ int main(int argc, char *argv[])
10321032 struct userdata u ;
10331033 pa_glib_mainloop * m = NULL ;
10341034 pa_time_event * time_event = NULL ;
1035- int domid = -1 ;
10361035 char * pidfile_path ;
10371036 int pidfile_fd ;
1038- int play_watch_fd , rec_watch_fd ;
10391037 int i ;
10401038
10411039 memset (& u , 0 , sizeof (u ));
@@ -1068,27 +1066,30 @@ int main(int argc, char *argv[])
10681066 if (l_domid < 0 || l_domid >= 0x7FF0 || errno == ERANGE )
10691067 errx (1 , "domid %ld out of range 0 through %d inclusive" , l_domid ,
10701068 0x7FF0 - 1 );
1071- domid = l_domid ;
10721069 if (errno )
10731070 err (1 , "invalid domid %s" , domid_str );
10741071 if (* endptr )
10751072 errx (1 , "trailing junk after domid %s" , domid_str );
1076- if (create_pidfile (domid , & pidfile_path , & pidfile_fd ) < 0 )
1073+
1074+ u .domid = (int )l_domid ;
1075+ u .name = domname ;
1076+
1077+ if (create_pidfile (u .domid , & pidfile_path , & pidfile_fd ) < 0 )
10771078 /* error already printed by create_pidfile() */
10781079 exit (1 );
1080+ goto main ;
10791081
1082+ main :
10801083 u .ret = 1 ;
10811084
10821085 g_mutex_init (& u .prop_mutex );
10831086
1084- u .name = domname ;
1085-
1086- u .play_ctrl = libvchan_client_init_async (domid , QUBES_PA_SINK_VCHAN_PORT , & play_watch_fd );
1087+ u .play_ctrl = libvchan_client_init_async (u .domid , QUBES_PA_SINK_VCHAN_PORT , & u .play_watch_fd );
10871088 if (!u .play_ctrl ) {
10881089 perror ("libvchan_client_init_async" );
10891090 exit (1 );
10901091 }
1091- u .rec_ctrl = libvchan_client_init_async (domid , QUBES_PA_SOURCE_VCHAN_PORT , & rec_watch_fd );
1092+ u .rec_ctrl = libvchan_client_init_async (u . domid , QUBES_PA_SOURCE_VCHAN_PORT , & u . rec_watch_fd );
10921093 if (!u .rec_ctrl ) {
10931094 perror ("libvchan_client_init_async" );
10941095 exit (1 );
@@ -1125,15 +1126,15 @@ int main(int argc, char *argv[])
11251126 goto quit ;
11261127 }
11271128
1128- u .play_ctrl_event = u .mainloop_api -> io_new (u . mainloop_api ,
1129- play_watch_fd , PA_IO_EVENT_INPUT , vchan_play_async_connect , & u );
1129+ u .play_ctrl_event = u .mainloop_api -> io_new (
1130+ u . mainloop_api , u . play_watch_fd , PA_IO_EVENT_INPUT , vchan_play_async_connect , & u );
11301131 if (!u .play_ctrl_event ) {
11311132 pacat_log ("io_new play_ctrl failed" );
11321133 goto quit ;
11331134 }
11341135
1135- u .rec_ctrl_event = u .mainloop_api -> io_new (u . mainloop_api ,
1136- rec_watch_fd , PA_IO_EVENT_INPUT , vchan_rec_async_connect , & u );
1136+ u .rec_ctrl_event = u .mainloop_api -> io_new (
1137+ u . mainloop_api , u . rec_watch_fd , PA_IO_EVENT_INPUT , vchan_rec_async_connect , & u );
11371138 if (!u .rec_ctrl_event ) {
11381139 pacat_log ("io_new rec_ctrl failed" );
11391140 goto quit ;
@@ -1163,14 +1164,21 @@ int main(int argc, char *argv[])
11631164 control_cleanup (& u );
11641165 }
11651166
1166- if (u .play_stream )
1167+ if (u .play_stream ) {
11671168 pa_stream_unref (u .play_stream );
1169+ u .play_stream = NULL ;
1170+ }
11681171
1169- if (u .rec_stream )
1172+ if (u .rec_stream ) {
11701173 pa_stream_unref (u .rec_stream );
1174+ u .rec_stream = NULL ;
1175+ }
11711176
1172- if (u .context )
1177+ if (u .context ) {
1178+ pa_context_disconnect (u .context );
11731179 pa_context_unref (u .context );
1180+ u .context = NULL ;
1181+ }
11741182
11751183 if (time_event ) {
11761184 assert (u .mainloop_api );
@@ -1217,5 +1225,9 @@ int main(int argc, char *argv[])
12171225
12181226 unlink (pidfile_path );
12191227 close (pidfile_fd );
1228+
1229+ if (!u .ret )
1230+ goto main ;
1231+
12201232 return u .ret ;
12211233}
0 commit comments