/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "sd-messages.h"
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-util.h"
#include "escape.h"
#include "extract-word.h"
#include "fd-util.h"
#include "fileio.h"
#include "formats-util.h"
#include "hashmap.h"
#include "machine-dbus.h"
#include "machine.h"
#include "mkdir.h"
#include "parse-util.h"
#include "process-util.h"
#include "special.h"
#include "string-table.h"
#include "terminal-util.h"
#include "unit-name.h"
#include "util.h"
Machine *m;
/* Passing class == _MACHINE_CLASS_INVALID here is fine. It
* means as much as "we don't know yet", and that we'll figure
* it out later when loading the state file. */
if (!m)
return NULL;
if (!m->name)
goto fail;
if (class != MACHINE_HOST) {
if (!m->state_file)
goto fail;
}
goto fail;
return m;
fail:
free(m->state_file);
free(m);
return NULL;
}
assert(m);
while (m->operations)
if (m->in_gc_queue)
if (m->manager->host_machine == m)
if (m->leader > 0)
free(m->state_file);
free(m->root_directory);
free(m);
}
int r;
assert(m);
if (!m->state_file)
return 0;
if (!m->started)
return 0;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
fprintf(f,
"# This is private data. Do not parse.\n"
"NAME=%s\n",
m->name);
if (m->unit) {
if (!escaped) {
r = -ENOMEM;
goto fail;
}
fprintf(f, "SCOPE=%s\n", escaped); /* We continue to call this "SCOPE=" because it is internal only, and we want to stay compatible with old files */
}
if (m->scope_job)
if (m->service) {
if (!escaped) {
r = -ENOMEM;
goto fail;
}
}
if (m->root_directory) {
if (!escaped) {
r = -ENOMEM;
goto fail;
}
}
if (m->leader != 0)
if (m->class != _MACHINE_CLASS_INVALID)
if (dual_timestamp_is_set(&m->timestamp))
fprintf(f,
if (m->n_netif > 0) {
unsigned i;
fputs("NETIF=", f);
for (i = 0; i < m->n_netif; i++) {
if (i != 0)
fputc(' ', f);
}
fputc('\n', f);
}
r = fflush_and_check(f);
if (r < 0)
goto fail;
r = -errno;
goto fail;
}
if (m->unit) {
char *sl;
/* Create a symlink from the unit name to the machine
* name, so that we can quickly find the machine for
* each given unit. Ignore error. */
}
return 0;
fail:
(void) unlink(m->state_file);
if (temp_path)
}
assert(m);
if (m->unit) {
char *sl;
}
if (m->state_file)
(void) unlink(m->state_file);
}
_cleanup_free_ char *realtime = NULL, *monotonic = NULL, *id = NULL, *leader = NULL, *class = NULL, *netif = NULL;
int r;
assert(m);
if (!m->state_file)
return 0;
"SCOPE", &m->unit,
"SCOPE_JOB", &m->scope_job,
"SERVICE", &m->service,
"ROOT", &m->root_directory,
"ID", &id,
"LEADER", &leader,
"CLASS", &class,
"REALTIME", &realtime,
"MONOTONIC", &monotonic,
"NETIF", &netif,
NULL);
if (r < 0) {
if (r == -ENOENT)
return 0;
}
if (id)
if (leader)
if (class) {
MachineClass c;
if (c >= 0)
m->class = c;
}
if (realtime) {
unsigned long long l;
}
if (monotonic) {
unsigned long long l;
}
if (netif) {
const char *p;
p = netif;
for(;;) {
int ifi;
if (r == 0)
break;
if (r == -ENOMEM)
return log_oom();
if (r < 0) {
break;
}
continue;
return log_oom();
}
}
}
return r;
}
int r = 0;
assert(m);
if (!m->unit) {
if (!escaped)
return log_oom();
if (!scope)
return log_oom();
r = manager_start_scope(m->manager, scope, m->leader, SPECIAL_MACHINE_SLICE, description, properties, error, &job);
if (r < 0) {
return r;
} else {
}
}
if (m->unit)
return r;
}
int r;
assert(m);
return -EOPNOTSUPP;
if (m->started)
return 0;
if (r < 0)
return r;
/* Create cgroup */
if (r < 0)
return r;
"NAME=%s", m->name,
NULL);
if (!dual_timestamp_is_set(&m->timestamp))
dual_timestamp_get(&m->timestamp);
m->started = true;
/* Save new machine data */
machine_save(m);
machine_send_signal(m, true);
return 0;
}
int r;
assert(m);
if (!m->unit)
return 0;
if (r < 0) {
return r;
}
return 0;
}
int r;
assert(m);
return -EOPNOTSUPP;
r = machine_stop_scope(m);
m->stopping = true;
machine_save(m);
return r;
}
assert(m);
if (m->started)
"NAME=%s", m->name,
NULL);
machine_unlink(m);
if (m->started) {
machine_send_signal(m, false);
m->started = false;
}
return 0;
}
assert(m);
if (m->class == MACHINE_HOST)
return true;
if (drop_not_started && !m->started)
return false;
return true;
return true;
return false;
}
assert(m);
if (m->in_gc_queue)
return;
m->in_gc_queue = true;
}
assert(s);
if (s->class == MACHINE_HOST)
return MACHINE_RUNNING;
if (s->stopping)
return MACHINE_CLOSING;
if (s->scope_job)
return MACHINE_OPENING;
return MACHINE_RUNNING;
}
assert(m);
return -EOPNOTSUPP;
if (!m->unit)
return -ESRCH;
if (who == KILL_LEADER) {
/* If we shall simply kill the leader, do so directly */
return -errno;
return 0;
}
/* Otherwise, make PID 1 do it for us, for the entire cgroup */
}
assert(m);
switch (m->class) {
case MACHINE_HOST: {
int fd;
if (fd < 0)
return -errno;
return -errno;
return fd;
}
case MACHINE_CONTAINER:
if (m->leader <= 0)
return -EINVAL;
default:
return -EOPNOTSUPP;
}
}
assert(m);
switch (m->class) {
case MACHINE_HOST:
case MACHINE_CONTAINER:
if (m->leader <= 0)
return -EINVAL;
default:
return -EOPNOTSUPP;
}
}
if (!o)
return NULL;
safe_close(o->errno_fd);
if (o->pid > 1)
if (o->machine) {
o->machine->n_operations--;
}
free(o);
return NULL;
}
assert(m);
if (!m->unit)
return;
}
[MACHINE_CONTAINER] = "container",
[MACHINE_VM] = "vm",
[MACHINE_HOST] = "host",
};
[MACHINE_OPENING] = "opening",
[MACHINE_RUNNING] = "running",
[MACHINE_CLOSING] = "closing"
};
[KILL_LEADER] = "leader",
[KILL_ALL] = "all"
};