machine.c | machine.c | |||
---|---|---|---|---|
skipping to change at line 97 | skipping to change at line 97 | |||
if (m->leader > 0) | if (m->leader > 0) | |||
hashmap_remove_value(m->manager->machine_leaders, UINT_TO_P TR(m->leader), m); | hashmap_remove_value(m->manager->machine_leaders, UINT_TO_P TR(m->leader), m); | |||
sd_bus_message_unref(m->create_message); | sd_bus_message_unref(m->create_message); | |||
free(m->name); | free(m->name); | |||
free(m->state_file); | free(m->state_file); | |||
free(m->service); | free(m->service); | |||
free(m->root_directory); | free(m->root_directory); | |||
free(m->netif); | ||||
free(m); | free(m); | |||
} | } | |||
int machine_save(Machine *m) { | int machine_save(Machine *m) { | |||
_cleanup_free_ char *temp_path = NULL; | _cleanup_free_ char *temp_path = NULL; | |||
_cleanup_fclose_ FILE *f = NULL; | _cleanup_fclose_ FILE *f = NULL; | |||
int r; | int r; | |||
assert(m); | assert(m); | |||
assert(m->state_file); | assert(m->state_file); | |||
skipping to change at line 179 | skipping to change at line 180 | |||
if (m->class != _MACHINE_CLASS_INVALID) | if (m->class != _MACHINE_CLASS_INVALID) | |||
fprintf(f, "CLASS=%s\n", machine_class_to_string(m->class)) ; | fprintf(f, "CLASS=%s\n", machine_class_to_string(m->class)) ; | |||
if (dual_timestamp_is_set(&m->timestamp)) | if (dual_timestamp_is_set(&m->timestamp)) | |||
fprintf(f, | fprintf(f, | |||
"REALTIME="USEC_FMT"\n" | "REALTIME="USEC_FMT"\n" | |||
"MONOTONIC="USEC_FMT"\n", | "MONOTONIC="USEC_FMT"\n", | |||
m->timestamp.realtime, | m->timestamp.realtime, | |||
m->timestamp.monotonic); | m->timestamp.monotonic); | |||
if (m->n_netif > 0) { | ||||
unsigned i; | ||||
fputs("NETIF=", f); | ||||
for (i = 0; i < m->n_netif; i++) { | ||||
if (i != 0) | ||||
fputc(' ', f); | ||||
fprintf(f, "%i", m->netif[i]); | ||||
} | ||||
fputc('\n', f); | ||||
} | ||||
r = fflush_and_check(f); | r = fflush_and_check(f); | |||
if (r < 0) | if (r < 0) | |||
goto finish; | goto finish; | |||
if (rename(temp_path, m->state_file) < 0) { | if (rename(temp_path, m->state_file) < 0) { | |||
r = -errno; | r = -errno; | |||
goto finish; | goto finish; | |||
} | } | |||
if (m->unit) { | if (m->unit) { | |||
skipping to change at line 225 | skipping to change at line 241 | |||
sl = strappenda("/run/systemd/machines/unit:", m->unit); | sl = strappenda("/run/systemd/machines/unit:", m->unit); | |||
unlink(sl); | unlink(sl); | |||
} | } | |||
if (m->state_file) | if (m->state_file) | |||
unlink(m->state_file); | unlink(m->state_file); | |||
} | } | |||
int machine_load(Machine *m) { | int machine_load(Machine *m) { | |||
_cleanup_free_ char *realtime = NULL, *monotonic = NULL, *id = NULL , *leader = NULL, *class = NULL; | _cleanup_free_ char *realtime = NULL, *monotonic = NULL, *id = NULL , *leader = NULL, *class = NULL, *netif = NULL; | |||
int r; | int r; | |||
assert(m); | assert(m); | |||
r = parse_env_file(m->state_file, NEWLINE, | r = parse_env_file(m->state_file, NEWLINE, | |||
"SCOPE", &m->unit, | "SCOPE", &m->unit, | |||
"SCOPE_JOB", &m->scope_job, | "SCOPE_JOB", &m->scope_job, | |||
"SERVICE", &m->service, | "SERVICE", &m->service, | |||
"ROOT", &m->root_directory, | "ROOT", &m->root_directory, | |||
"ID", &id, | "ID", &id, | |||
"LEADER", &leader, | "LEADER", &leader, | |||
"CLASS", &class, | "CLASS", &class, | |||
"REALTIME", &realtime, | "REALTIME", &realtime, | |||
"MONOTONIC", &monotonic, | "MONOTONIC", &monotonic, | |||
"NETIF", &netif, | ||||
NULL); | NULL); | |||
if (r < 0) { | if (r < 0) { | |||
if (r == -ENOENT) | if (r == -ENOENT) | |||
return 0; | return 0; | |||
log_error("Failed to read %s: %s", m->state_file, strerror( -r)); | log_error("Failed to read %s: %s", m->state_file, strerror( -r)); | |||
return r; | return r; | |||
} | } | |||
if (id) | if (id) | |||
skipping to change at line 275 | skipping to change at line 292 | |||
if (sscanf(realtime, "%llu", &l) > 0) | if (sscanf(realtime, "%llu", &l) > 0) | |||
m->timestamp.realtime = l; | m->timestamp.realtime = l; | |||
} | } | |||
if (monotonic) { | if (monotonic) { | |||
unsigned long long l; | unsigned long long l; | |||
if (sscanf(monotonic, "%llu", &l) > 0) | if (sscanf(monotonic, "%llu", &l) > 0) | |||
m->timestamp.monotonic = l; | m->timestamp.monotonic = l; | |||
} | } | |||
if (netif) { | ||||
size_t l, allocated = 0, nr = 0; | ||||
const char *word, *state; | ||||
int *ni = NULL; | ||||
FOREACH_WORD(word, l, netif, state) { | ||||
char buf[l+1]; | ||||
int ifi; | ||||
*(char*) (mempcpy(buf, word, l)) = 0; | ||||
if (safe_atoi(buf, &ifi) < 0) | ||||
continue; | ||||
if (ifi <= 0) | ||||
continue; | ||||
if (!GREEDY_REALLOC(ni, allocated, nr+1)) { | ||||
free(ni); | ||||
return log_oom(); | ||||
} | ||||
ni[nr++] = ifi; | ||||
} | ||||
free(m->netif); | ||||
m->netif = ni; | ||||
m->n_netif = nr; | ||||
} | ||||
return r; | return r; | |||
} | } | |||
static int machine_start_scope(Machine *m, sd_bus_message *properties, sd_b us_error *error) { | static int machine_start_scope(Machine *m, sd_bus_message *properties, sd_b us_error *error) { | |||
int r = 0; | int r = 0; | |||
assert(m); | assert(m); | |||
if (!m->unit) { | if (!m->unit) { | |||
_cleanup_free_ char *escaped = NULL; | _cleanup_free_ char *escaped = NULL; | |||
skipping to change at line 374 | skipping to change at line 420 | |||
r = manager_stop_unit(m->manager, m->unit, &error, &job); | r = manager_stop_unit(m->manager, m->unit, &error, &job); | |||
if (r < 0) { | if (r < 0) { | |||
log_error("Failed to stop machine scope: %s", bus_e rror_message(&error, r)); | log_error("Failed to stop machine scope: %s", bus_e rror_message(&error, r)); | |||
return r; | return r; | |||
} | } | |||
} | } | |||
free(m->scope_job); | free(m->scope_job); | |||
m->scope_job = job; | m->scope_job = job; | |||
return r; | return 0; | |||
} | } | |||
int machine_stop(Machine *m) { | int machine_stop(Machine *m) { | |||
int r = 0, k; | int r = 0, k; | |||
assert(m); | assert(m); | |||
if (m->started) | if (m->started) | |||
log_struct(LOG_INFO, | log_struct(LOG_INFO, | |||
MESSAGE_ID(SD_MESSAGE_MACHINE_STOP), | MESSAGE_ID(SD_MESSAGE_MACHINE_STOP), | |||
"NAME=%s", m->name, | "NAME=%s", m->name, | |||
skipping to change at line 450 | skipping to change at line 496 | |||
assert(m); | assert(m); | |||
if (!m->unit) | if (!m->unit) | |||
return -ESRCH; | return -ESRCH; | |||
if (who == KILL_LEADER) { | if (who == KILL_LEADER) { | |||
/* If we shall simply kill the leader, do so directly */ | /* If we shall simply kill the leader, do so directly */ | |||
if (kill(m->leader, signo) < 0) | if (kill(m->leader, signo) < 0) | |||
return -errno; | return -errno; | |||
return 0; | ||||
} | } | |||
/* Otherwise make PID 1 do it for us, for the entire cgroup */ | /* Otherwise make PID 1 do it for us, for the entire cgroup */ | |||
return manager_kill_unit(m->manager, m->unit, signo, NULL); | return manager_kill_unit(m->manager, m->unit, signo, NULL); | |||
} | } | |||
static const char* const machine_class_table[_MACHINE_CLASS_MAX] = { | static const char* const machine_class_table[_MACHINE_CLASS_MAX] = { | |||
[MACHINE_CONTAINER] = "container", | [MACHINE_CONTAINER] = "container", | |||
[MACHINE_VM] = "vm" | [MACHINE_VM] = "vm" | |||
}; | }; | |||
End of changes. 7 change blocks. | ||||
2 lines changed or deleted | 50 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |