diff --git a/src/core/service.c b/src/core/service.c index 7513972fb37..9ad3c3d9953 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -2763,7 +2763,16 @@ static int service_serialize_exec_command(Unit *u, FILE *f, const ExecCommand *c return log_oom(); key = strjoina(type, "-command"); - (void) serialize_item_format(f, key, "%s %u %s %s", service_exec_command_to_string(id), idx, p, args); + + /* We use '+1234' instead of '1234' to mark the last command in a sequence. + * This is used in service_deserialize_exec_command(). */ + (void) serialize_item_format( + f, key, + "%s %s%u %s %s", + service_exec_command_to_string(id), + command->command_next ? "" : "+", + idx, + p, args); return 0; } @@ -2877,7 +2886,7 @@ int service_deserialize_exec_command( Service *s = SERVICE(u); int r; unsigned idx = 0, i; - bool control, found = false; + bool control, found = false, last = false; ServiceExecCommand id = _SERVICE_EXEC_COMMAND_INVALID; ExecCommand *command = NULL; _cleanup_free_ char *path = NULL; @@ -2918,9 +2927,15 @@ int service_deserialize_exec_command( state = STATE_EXEC_COMMAND_INDEX; break; case STATE_EXEC_COMMAND_INDEX: + /* PID 1234 is serialized as either '1234' or '+1234'. The second form is used to + * mark the last command in a sequence. We warn if the deserialized command doesn't + * match what we have loaded from the unit, but we don't need to warn if that is the + * last command. */ + r = safe_atou(arg, &idx); if (r < 0) return r; + last = arg[0] == '+'; state = STATE_EXEC_COMMAND_PATH; break; @@ -2965,6 +2980,8 @@ int service_deserialize_exec_command( s->control_command_id = id; } else if (command) s->main_command = command; + else if (last) + log_unit_debug(u, "Current command vanished from the unit file."); else log_unit_warning(u, "Current command vanished from the unit file, execution of the command list won't be resumed.");