@@ -149,33 +149,39 @@ pub(crate) fn run_with_api(
149
149
let api_thread = thread:: Builder :: new ( )
150
150
. name ( "fc_api" . to_owned ( ) )
151
151
. spawn ( move || {
152
- match ApiServer :: new ( to_vmm, from_vmm, to_vmm_event_fd) . bind_and_run (
152
+ let res = ApiServer :: new ( to_vmm, from_vmm, to_vmm_event_fd) . bind_and_run (
153
153
& api_bind_path,
154
154
process_time_reporter,
155
155
& api_seccomp_filter,
156
156
api_payload_limit,
157
157
socket_ready_sender,
158
- ) {
159
- Ok ( _) => ( ) ,
160
- Err ( api_server:: Error :: ServerCreation ( ServerError :: IOError ( inner) ) )
158
+ ) ;
159
+
160
+ let Err ( err) = res else {
161
+ return ;
162
+ } ;
163
+
164
+ match err {
165
+ api_server:: Error :: ServerCreation ( ServerError :: IOError ( inner) )
161
166
if inner. kind ( ) == std:: io:: ErrorKind :: AddrInUse =>
162
167
{
163
168
let sock_path = api_bind_path. display ( ) . to_string ( ) ;
164
169
error ! (
165
170
"Failed to open the API socket at: {sock_path}. Check that it is not \
166
171
already used."
167
172
) ;
168
- std:: process:: exit ( vmm:: FcExitCode :: GenericError as i32 ) ;
169
173
}
170
- Err ( api_server:: Error :: ServerCreation ( err) ) => {
174
+ api_server:: Error :: ServerCreation ( err) => {
171
175
error ! ( "Failed to bind and run the HTTP server: {err}" ) ;
172
- std:: process:: exit ( vmm:: FcExitCode :: GenericError as i32 ) ;
173
176
}
174
177
}
178
+
179
+ std:: process:: exit ( vmm:: FcExitCode :: GenericError as i32 ) ;
175
180
} )
176
181
. expect ( "API thread spawn failed." ) ;
177
182
178
183
let mut event_manager = EventManager :: new ( ) . expect ( "Unable to create EventManager" ) ;
184
+
179
185
// Create the firecracker metrics object responsible for periodically printing metrics.
180
186
let firecracker_metrics = Arc :: new ( Mutex :: new ( super :: metrics:: PeriodicMetrics :: new ( ) ) ) ;
181
187
event_manager. add_subscriber ( firecracker_metrics. clone ( ) ) ;
@@ -199,11 +205,13 @@ pub(crate) fn run_with_api(
199
205
let req = from_api
200
206
. recv ( )
201
207
. expect ( "The channel's sending half was disconnected. Cannot receive data." ) ;
208
+
202
209
// Also consume the API event along with the message. It is safe to unwrap()
203
210
// because this event_fd is blocking.
204
211
api_event_fd
205
212
. read ( )
206
213
. expect ( "VMM: Failed to read the API event_fd" ) ;
214
+
207
215
* req
208
216
} ,
209
217
|response| {
0 commit comments