machinectl.c revision d21ed1ead18d16d35c30299a69d3366847f8a039
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen This file is part of systemd.
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen Copyright 2013 Lennart Poettering
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen systemd is free software; you can redistribute it and/or modify it
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen under the terms of the GNU Lesser General Public License as published by
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen (at your option) any later version.
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen systemd is distributed in the hope that it will be useful, but
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen Lesser General Public License for more details.
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen You should have received a copy of the GNU Lesser General Public License
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahanistatic bool arg_all = false;
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahanistatic bool arg_full = false;
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersenstatic bool arg_no_pager = false;
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahanistatic bool arg_ask_password = true;
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahanistatic BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
cffacc741cb79f63999720525ceaa65aae01a542Susant Sahanistatic void pager_open_if_enabled(void) {
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen /* Cache result before we open the pager */
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahanistatic int list_machines(sd_bus *bus, char **args, unsigned n) {
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani unsigned k = 0;
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
&reply,
if (on_tty())
goto fail;
goto fail;
goto fail;
if (on_tty())
fail:
const char *cgroup;
int r, output_flags;
if (!path)
return log_oom();
r = sd_bus_get_property(
bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Scope",
&error,
&reply,
c = columns();
show_cgroup_and_extra(SYSTEMD_CGROUP_CONTROLLER, cgroup, "\t\t ", c, false, &leader, leader > 0, output_flags);
typedef struct MachineStatusInfo {
const char *name;
const char *class;
const char *service;
const char *scope;
const char *root_directory;
assert(i);
if (s1)
else if (s2)
if (i->leader > 0) {
if (i->service) {
if (i->class)
} else if (i->class)
if (i->root_directory)
if (i->scope) {
static int status_property_machine(const char *name, sd_bus_message *property, MachineStatusInfo *i) {
char type;
const char *contents;
assert(i);
switch (type) {
case SD_BUS_TYPE_STRING: {
if (!isempty(s)) {
i->name = s;
i->class = s;
i->service = s;
i->scope = s;
i->root_directory = s;
case SD_BUS_TYPE_UINT32: {
uint32_t u;
case SD_BUS_TYPE_UINT64: {
uint64_t u;
case SD_BUS_TYPE_ARRAY: {
size_t n;
if (arg_all)
static int show_one(const char *verb, sd_bus *bus, const char *path, bool show_properties, bool *new_line) {
r = sd_bus_call_method(
bus,
path,
&error,
&reply,
if (*new_line)
*new_line = true;
goto fail;
const char *name;
const char *contents;
goto fail;
goto fail;
goto fail;
if (show_properties)
goto fail;
goto fail;
goto fail;
goto fail;
goto fail;
if (!show_properties)
fail:
int r, ret = 0;
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
&reply,
ret = r;
return ret;
if (!arg_kill_who)
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
NULL,
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
NULL,
static int help(void) {
" show [NAME...] Show properties of one or more VMs/containers\n"
" terminate [NAME...] Terminate one or more VMs/containers\n"
help();
case ARG_VERSION:
return log_oom();
arg_all = true;
arg_all = true;
arg_full = true;
case ARG_NO_PAGER:
arg_no_pager = true;
case ARG_NO_ASK_PASSWORD:
arg_ask_password = false;
case ARG_KILL_WHO:
if (arg_signal < 0) {
return -EINVAL;
return -EINVAL;
return -EINVAL;
const char* verb;
MORE,
LESS,
} argc_cmp;
const int argc;
} verbs[] = {
int left;
if (left <= 0)
help();
return -EINVAL;
case EQUAL:
return -EINVAL;
case MORE:
return -EINVAL;
case LESS:
return -EINVAL;
return -EIO;
log_open();
goto finish;
goto finish;
goto finish;
pager_close();
return ret;