@@ -1162,6 +1162,8 @@ static int fsmonitor_run_daemon_1(struct fsmonitor_daemon_state *state)
1162
1162
*/
1163
1163
.uds_disallow_chdir = 0
1164
1164
};
1165
+ int listener_started = 0 ;
1166
+ int err = 0 ;
1165
1167
1166
1168
/*
1167
1169
* Start the IPC thread pool before the we've started the file
@@ -1182,15 +1184,20 @@ static int fsmonitor_run_daemon_1(struct fsmonitor_daemon_state *state)
1182
1184
if (pthread_create (& state -> listener_thread , NULL ,
1183
1185
fsm_listen__thread_proc , state ) < 0 ) {
1184
1186
ipc_server_stop_async (state -> ipc_server_data );
1185
- ipc_server_await (state -> ipc_server_data );
1186
-
1187
- return error (_ ("could not start fsmonitor listener thread" ));
1187
+ err = error (_ ("could not start fsmonitor listener thread" ));
1188
+ goto cleanup ;
1188
1189
}
1190
+ listener_started = 1 ;
1189
1191
1190
1192
/*
1191
1193
* The daemon is now fully functional in background threads.
1194
+ * Our primary thread should now just wait while the threads
1195
+ * do all the work.
1196
+ */
1197
+ cleanup :
1198
+ /*
1192
1199
* Wait for the IPC thread pool to shutdown (whether by client
1193
- * request or from filesystem activity).
1200
+ * request, from filesystem activity, or an error ).
1194
1201
*/
1195
1202
ipc_server_await (state -> ipc_server_data );
1196
1203
@@ -1199,10 +1206,16 @@ static int fsmonitor_run_daemon_1(struct fsmonitor_daemon_state *state)
1199
1206
* event from the IPC thread pool, but it doesn't hurt to tell
1200
1207
* it again. And wait for it to shutdown.
1201
1208
*/
1202
- fsm_listen__stop_async (state );
1203
- pthread_join (state -> listener_thread , NULL );
1209
+ if (listener_started ) {
1210
+ fsm_listen__stop_async (state );
1211
+ pthread_join (state -> listener_thread , NULL );
1212
+ }
1204
1213
1205
- return state -> error_code ;
1214
+ if (err )
1215
+ return err ;
1216
+ if (state -> error_code )
1217
+ return state -> error_code ;
1218
+ return 0 ;
1206
1219
}
1207
1220
1208
1221
static int fsmonitor_run_daemon (void )
0 commit comments