Skip to content

Commit f221fc4

Browse files
committed
mark units that failed at startup as StoppedFinal
1 parent fe123e9 commit f221fc4

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

src/control/control.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,15 @@ pub fn execute_command(
290290
for unit in units {
291291
let unit_locked = unit.lock().unwrap();
292292
let status = {
293-
*run_info
293+
run_info
294294
.status_table
295295
.read()
296296
.unwrap()
297297
.get(&unit_locked.id)
298298
.unwrap()
299299
.lock()
300300
.unwrap()
301+
.clone()
301302
};
302303
if name.ends_with(".service") {
303304
result_vec
@@ -327,14 +328,15 @@ pub fn execute_command(
327328
.map(|(_id, unit)| {
328329
let unit_locked = &unit.lock().unwrap();
329330
let status = {
330-
*run_info
331+
run_info
331332
.status_table
332333
.read()
333334
.unwrap()
334335
.get(&unit_locked.id)
335336
.unwrap()
336337
.lock()
337338
.unwrap()
339+
.clone()
338340
};
339341
match unit_locked.specialized {
340342
UnitSpecialized::Socket(_) => format_socket(&unit_locked, status),

src/socket_activation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn start_socketactivation_thread(
5050
{
5151
let srvc_status = {
5252
let status_locked = status.lock().unwrap();
53-
*status_locked
53+
status_locked.clone()
5454
};
5555

5656
if srvc_status != crate::units::UnitStatus::StartedWaitingForSocket {

src/units/activate.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ fn activate_units_recursive(
113113
tpool_copy.execute(next_services_job);
114114
}
115115
Ok(StartResult::WaitForDependencies) => {
116-
// Thats ok. The unit is waiting for more dependencies
117-
// TODO make this more explicit
116+
// Thats ok. The unit is waiting for more dependencies and will be
117+
// activated again when another dependency has finished starting
118118
}
119119
Err(e) => {
120120
error!("Error while activating unit {}", e);
@@ -233,6 +233,13 @@ pub fn activate_unit(
233233
let mut status_locked = status.lock().unwrap();
234234
*status_locked = new_status;
235235
StartResult::Started(next_services_ids)
236+
}).map_err(|e| {
237+
// Update the status while we still lock the unit
238+
let status_table_locked = run_info.status_table.read().unwrap();
239+
let status = status_table_locked.get(&unit_locked.id).unwrap();
240+
let mut status_locked = status.lock().unwrap();
241+
*status_locked = UnitStatus::StoppedFinal(format!("{}", e));
242+
e
236243
})
237244
// drop all the locks "at once". Ordering of dropping should be irrelevant?
238245
}

src/units/deactivate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn deactivate_unit(
4141
}
4242
UnitStatus::NeverStarted
4343
| UnitStatus::Stopped
44-
| UnitStatus::StoppedFinal
44+
| UnitStatus::StoppedFinal(_)
4545
| UnitStatus::Stopping => {
4646
return Ok(());
4747
}
@@ -53,7 +53,7 @@ pub fn deactivate_unit(
5353
let status = status_table_locked.get(&id_to_kill).unwrap();
5454
let mut status_locked = status.lock().unwrap();
5555
if killfinal {
56-
*status_locked = UnitStatus::StoppedFinal;
56+
*status_locked = UnitStatus::StoppedFinal("Deactivated cleanly".into());
5757
} else {
5858
*status_locked = UnitStatus::Stopped;
5959
}

src/units/units.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ pub enum PidEntry {
9191
HelperExited(crate::signal_handler::ChildTermination),
9292
}
9393

94-
#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)]
94+
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
9595
pub enum UnitStatus {
9696
NeverStarted,
9797
Starting,
9898
Started,
9999
StartedWaitingForSocket,
100100
Stopping,
101101
Stopped,
102-
StoppedFinal,
102+
StoppedFinal(String),
103103
}
104104

105105
#[derive(Debug)]

0 commit comments

Comments
 (0)