@@ -1032,10 +1032,8 @@ int main(int argc, char *argv[])
1032
1032
struct userdata u ;
1033
1033
pa_glib_mainloop * m = NULL ;
1034
1034
pa_time_event * time_event = NULL ;
1035
- int domid = -1 ;
1036
1035
char * pidfile_path ;
1037
1036
int pidfile_fd ;
1038
- int play_watch_fd , rec_watch_fd ;
1039
1037
int i ;
1040
1038
1041
1039
memset (& u , 0 , sizeof (u ));
@@ -1068,27 +1066,30 @@ int main(int argc, char *argv[])
1068
1066
if (l_domid < 0 || l_domid >= 0x7FF0 || errno == ERANGE )
1069
1067
errx (1 , "domid %ld out of range 0 through %d inclusive" , l_domid ,
1070
1068
0x7FF0 - 1 );
1071
- domid = l_domid ;
1072
1069
if (errno )
1073
1070
err (1 , "invalid domid %s" , domid_str );
1074
1071
if (* endptr )
1075
1072
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 )
1077
1078
/* error already printed by create_pidfile() */
1078
1079
exit (1 );
1080
+ goto main ;
1079
1081
1082
+ main :
1080
1083
u .ret = 1 ;
1081
1084
1082
1085
g_mutex_init (& u .prop_mutex );
1083
1086
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 );
1087
1088
if (!u .play_ctrl ) {
1088
1089
perror ("libvchan_client_init_async" );
1089
1090
exit (1 );
1090
1091
}
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 );
1092
1093
if (!u .rec_ctrl ) {
1093
1094
perror ("libvchan_client_init_async" );
1094
1095
exit (1 );
@@ -1125,15 +1126,15 @@ int main(int argc, char *argv[])
1125
1126
goto quit ;
1126
1127
}
1127
1128
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 );
1130
1131
if (!u .play_ctrl_event ) {
1131
1132
pacat_log ("io_new play_ctrl failed" );
1132
1133
goto quit ;
1133
1134
}
1134
1135
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 );
1137
1138
if (!u .rec_ctrl_event ) {
1138
1139
pacat_log ("io_new rec_ctrl failed" );
1139
1140
goto quit ;
@@ -1163,14 +1164,21 @@ int main(int argc, char *argv[])
1163
1164
control_cleanup (& u );
1164
1165
}
1165
1166
1166
- if (u .play_stream )
1167
+ if (u .play_stream ) {
1167
1168
pa_stream_unref (u .play_stream );
1169
+ u .play_stream = NULL ;
1170
+ }
1168
1171
1169
- if (u .rec_stream )
1172
+ if (u .rec_stream ) {
1170
1173
pa_stream_unref (u .rec_stream );
1174
+ u .rec_stream = NULL ;
1175
+ }
1171
1176
1172
- if (u .context )
1177
+ if (u .context ) {
1178
+ pa_context_disconnect (u .context );
1173
1179
pa_context_unref (u .context );
1180
+ u .context = NULL ;
1181
+ }
1174
1182
1175
1183
if (time_event ) {
1176
1184
assert (u .mainloop_api );
@@ -1217,5 +1225,9 @@ int main(int argc, char *argv[])
1217
1225
1218
1226
unlink (pidfile_path );
1219
1227
close (pidfile_fd );
1228
+
1229
+ if (!u .ret )
1230
+ goto main ;
1231
+
1220
1232
return u .ret ;
1221
1233
}
0 commit comments