systemctl.c revision 86aa7ba4f9969bbfc75ebd51f944313695f1a0a1
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering This file is part of systemd.
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Copyright 2010 Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering systemd is free software; you can redistribute it and/or modify it
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering under the terms of the GNU General Public License as published by
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering the Free Software Foundation; either version 2 of the License, or
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering (at your option) any later version.
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering systemd is distributed in the hope that it will be useful, but
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering General Public License for more details.
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering You should have received a copy of the GNU General Public License
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool arg_all = false;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic const char *arg_job_mode = "replace";
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool arg_immediate = false;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool arg_no_block = false;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool arg_no_legend = false;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool arg_no_pager = false;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool arg_no_wtmp = false;
cc3773810855956bad92337cee8fa193584ab62eLennart Poetteringstatic bool arg_no_sync = false;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool arg_no_wall = false;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool arg_no_reload = false;
cc3773810855956bad92337cee8fa193584ab62eLennart Poetteringstatic bool arg_dry = false;
cc3773810855956bad92337cee8fa193584ab62eLennart Poetteringstatic bool arg_quiet = false;
cc3773810855956bad92337cee8fa193584ab62eLennart Poetteringstatic bool arg_full = false;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool arg_force = false;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool arg_ask_password = false;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool arg_failed = false;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool arg_runtime = false;
90b2de37b80603168f4e9c9c81cff7eea4efa21aZbigniew Jędrzejewski-Szmek} arg_action = ACTION_SYSTEMCTL;
88231eb62cafc8bb51406919c8cf6019dc1ac916Thomas Hindoe Paaboel Andersen} arg_transport = TRANSPORT_NORMAL;
88231eb62cafc8bb51406919c8cf6019dc1ac916Thomas Hindoe Paaboel Andersenstatic bool private_bus = false;
88231eb62cafc8bb51406919c8cf6019dc1ac916Thomas Hindoe Paaboel Andersenstatic int daemon_reload(DBusConnection *bus, char **args);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool on_tty(void) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering static int t = -1;
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering /* Note that this is invoked relatively early, before we start
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering * the pager. That means the value we return reflects whether
88231eb62cafc8bb51406919c8cf6019dc1ac916Thomas Hindoe Paaboel Andersen * we originally were started on a tty, not if we currently
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering * are. But this is intended, since we want colour and so on
88231eb62cafc8bb51406919c8cf6019dc1ac916Thomas Hindoe Paaboel Andersen * when run in our own pager. */
88231eb62cafc8bb51406919c8cf6019dc1ac916Thomas Hindoe Paaboel Andersen t = isatty(STDOUT_FILENO) > 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic void pager_open_if_enabled(void) {
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering /* Cache result before we open the pager */
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poetteringstatic void agent_open_if_enabled(void) {
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering /* Open the password agent as a child process if necessary */
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic const char *ansi_highlight(bool b) {
de0671ee7fe465e108f62dcbbbe9366f81dd9e9aZbigniew Jędrzejewski-Szmek return b ? ANSI_HIGHLIGHT_ON : ANSI_HIGHLIGHT_OFF;
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poetteringstatic const char *ansi_highlight_green(bool b) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return b ? ANSI_HIGHLIGHT_GREEN_ON : ANSI_HIGHLIGHT_OFF;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool error_is_no_service(const DBusError *error) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (dbus_error_has_name(error, DBUS_ERROR_NAME_HAS_NO_OWNER))
de0671ee7fe465e108f62dcbbbe9366f81dd9e9aZbigniew Jędrzejewski-Szmek if (dbus_error_has_name(error, DBUS_ERROR_SERVICE_UNKNOWN))
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return startswith(error->name, "org.freedesktop.DBus.Error.Spawn.");
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic int translate_bus_error_to_exit_status(int r, const DBusError *error) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (dbus_error_has_name(error, DBUS_ERROR_ACCESS_DENIED) ||
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering dbus_error_has_name(error, BUS_ERROR_ONLY_BY_DEPENDENCY) ||
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering dbus_error_has_name(error, BUS_ERROR_NO_ISOLATION) ||
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering dbus_error_has_name(error, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE))
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (dbus_error_has_name(error, BUS_ERROR_NO_SUCH_UNIT))
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering if (dbus_error_has_name(error, BUS_ERROR_JOB_TYPE_NOT_APPLICABLE) ||
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering dbus_error_has_name(error, BUS_ERROR_NOT_SUPPORTED))
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering if (dbus_error_has_name(error, BUS_ERROR_LOAD_FAILED))
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poetteringstatic void warn_wall(enum action action) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering static const char *table[_ACTION_MAX] = {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering [ACTION_HALT] = "The system is going down for system halt NOW!",
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering [ACTION_REBOOT] = "The system is going down for reboot NOW!",
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering [ACTION_POWEROFF] = "The system is going down for power-off NOW!",
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering [ACTION_KEXEC] = "The system is going down for kexec reboot NOW!",
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering [ACTION_RESCUE] = "The system is going down to rescue mode NOW!",
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering [ACTION_EMERGENCY] = "The system is going down to emergency mode NOW!"
527b7a421ff3927d4f3f170b1b143452e88ae1dcLennart Poetteringstatic bool avoid_bus(void) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic int compare_unit_info(const void *a, const void *b) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering const struct unit_info *u = a, *v = b;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic bool output_show_unit(const struct unit_info *u) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return (!arg_type || ((dot = strrchr(u->id, '.')) &&
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering (arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0);
151b9b9662a90455262ce575a8a8ae74bf4ff336Lennart Poetteringstatic void output_units_list(const struct unit_info *unit_infos, unsigned c) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering unsigned id_len, max_id_len, active_len, sub_len, job_len, desc_len, n_shown = 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering const struct unit_info *u;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering for (u = unit_infos; u < unit_infos + c; u++) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering max_id_len = MAX(max_id_len, strlen(u->id));
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering active_len = MAX(active_len, strlen(u->active_state));
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering sub_len = MAX(sub_len, strlen(u->sub_state));
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering job_len = MAX(job_len, strlen(u->job_type));
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering basic_len = 5 + id_len + 6 + active_len + sub_len + job_len;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering /* Either UNIT already got 25, or is fully satisfied.
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering * Grant up to 25 to DESC now. */
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering /* split the remaining space between UNIT and DESC,
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering * but do not give UNIT more than it needs. */
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering incr = MIN(extra_len / 2, max_id_len - id_len);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering printf("%-*s %-6s %-*s %-*s %-*s ", id_len, "UNIT", "LOAD",
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering active_len, "ACTIVE", sub_len, "SUB", job_len, "JOB");
2c4f86c1298f402220965682ab0e7729e150a562Lennart Poettering printf("%.*s\n", desc_len, "DESCRIPTION");
2c4f86c1298f402220965682ab0e7729e150a562Lennart Poettering for (u = unit_infos; u < unit_infos + c; u++) {
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering e = arg_full ? NULL : ellipsize(u->id, id_len, 33);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering printf("%-*s %s%-6s%s %s%-*s %-*s%s %-*s ",
409133be63387fc04d927e8aecd2f6ba03d2f143Lennart Poettering printf("%.*s\n", desc_len, u->description);
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering printf("\nLOAD = Reflects whether the unit definition was properly loaded.\n"
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering "ACTIVE = The high-level unit activation state, i.e. generalization of SUB.\n"
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering "SUB = The low-level unit activation state, values depend on unit type.\n"
85a428c69465b047731b6abb5005f01824f1444eLennart Poettering "JOB = Pending job for the unit.\n");
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering printf("\n%u units listed. Pass --all to see inactive units, too.\n", n_shown);
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poetteringstatic int list_units(DBusConnection *bus, char **args) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering unsigned c = 0, n_units = 0;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering "org.freedesktop.systemd1.Manager",
8e7fd6ade44ce5dde0867ba748c7978ed1206865Lennart Poettering "ListUnits"))) {
8e7fd6ade44ce5dde0867ba748c7978ed1206865Lennart Poettering log_error("Could not allocate message.");
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) {
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering log_error("Failed to issue method call: %s", bus_error_message(&error));
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering if (!dbus_message_iter_init(reply, &iter) ||
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRUCT) {
a2a5291b3f5ab6ed4c92f51d0fd10a03047380d8Zbigniew Jędrzejewski-Szmek while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
4943c1c94ba751c98763f4232b4350481b22c90aLennart Poettering if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) {
a2a5291b3f5ab6ed4c92f51d0fd10a03047380d8Zbigniew Jędrzejewski-Szmek log_error("Failed to parse reply.");
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering w = realloc(unit_infos, sizeof(struct unit_info) * n_units);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering log_error("Failed to allocate unit array.");
r = -EIO;
goto finish;
if (reply)
static int compare_unit_file_list(const void *a, const void *b) {
const UnitFileList *u = a, *v = b;
const char *dot;
const UnitFileList *u;
if (!output_show_unit_file(u))
if (!arg_full) {
unsigned basic_cols;
if (!arg_no_legend)
const char *id;
if (!output_show_unit_file(u))
n_shown++;
free(e);
if (!arg_no_legend)
unsigned c = 0, n_units = 0;
if (avoid_bus()) {
Hashmap *h;
UnitFileList *u;
Iterator i;
return -ENOMEM;
if (!units) {
return -ENOMEM;
HASHMAP_FOREACH(u, h, i) {
free(u);
hashmap_free(h);
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
return -ENOMEM;
if (!reply) {
r = -EIO;
goto finish;
r = -EIO;
goto finish;
UnitFileList *u;
const char *state;
r = -EIO;
goto finish;
if (c >= n_units) {
UnitFileList *w;
r = -ENOMEM;
goto finish;
units = w;
u = units+c;
r = -EIO;
goto finish;
if (reply)
static const char * const colors[] = {
const char *c = NULL;
case DBUS_TYPE_ARRAY:
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
path,
r = -ENOMEM;
goto finish;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
const char *prop;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
if (reply)
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
return -ENOMEM;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
goto finish;
if (on_tty())
"-- Try a shell pipeline like 'systemctl dot | dot -Tsvg > systemd.svg'!\n");
if (reply)
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
return -ENOMEM;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
if (on_tty())
r = -EIO;
goto finish;
r = -EIO;
goto finish;
free(e);
if (on_tty())
if (reply)
char **name;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
r = -ENOMEM;
goto finish;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
char **name;
unsigned id;
const char *path;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
r = -ENOMEM;
goto finish;
goto finish;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Job",
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
if (reply)
*path;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
goto finish;
if (!dbus_message_append_args(m,
goto finish;
goto finish;
goto finish;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
path,
goto finish;
if (!dbus_message_append_args(m,
goto finish;
goto finish;
goto finish;
goto finish;
if (reply)
typedef struct WaitData {
char *result;
} WaitData;
static DBusHandlerResult wait_filter(DBusConnection *connection, DBusMessage *message, void *data) {
assert(d);
free(p);
if (*result)
goto finish;
#ifndef LEGACY
free(p);
if (!success)
goto finish;
if (private_bus)
"sender='org.freedesktop.systemd1',"
"interface='org.freedesktop.systemd1.Manager',"
"path='/org/freedesktop/systemd1'",
&error);
return -EIO;
WaitData d;
assert(s);
zero(d);
d.set = s;
r = -ENOMEM;
goto finish;
while (!set_isempty(s) &&
r = -ETIME;
r = -ECANCELED;
r = -EIO;
static int start_unit_one(
const char *method,
const char *name,
const char *mode,
Set *s) {
const char *path;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
method))) {
r = -ENOMEM;
goto finish;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
r = -EADDRNOTAVAIL;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
log_warning("Warning: Unit file of created job changed on disk, 'systemctl %s daemon-reload' recommended.",
if (!arg_no_block) {
r = -ENOMEM;
goto finish;
if ((r = set_put(s, p)) < 0) {
free(p);
goto finish;
if (reply)
return ACTION_HALT;
return ACTION_POWEROFF;
return ACTION_REBOOT;
return ACTION_KEXEC;
return ACTION_RESCUE;
return ACTION_EMERGENCY;
return ACTION_DEFAULT;
return ACTION_EXIT;
return ACTION_INVALID;
int r, ret = 0;
char **name;
method =
mode =
if (!arg_no_block) {
goto finish;
goto finish;
if (one_name) {
goto finish;
if (!arg_no_block)
ret = r;
goto finish;
set_free_free(s);
return ret;
if (arg_force &&
char **name;
const char *state;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
r = -ENOMEM;
goto finish;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
if (!arg_quiet)
m = NULL;
r = -EIO;
goto finish;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
path,
r = -ENOMEM;
goto finish;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
if (!arg_quiet)
if (reply)
char **name;
if (!arg_kill_who)
if (!arg_kill_mode)
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
r = -ENOMEM;
goto finish;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
r = -EIO;
if (reply)
typedef struct ExecStatusInfo {
char *name;
char *path;
char **argv;
bool ignore;
int code;
int status;
assert(i);
free(i);
const char*path;
assert(i);
assert(i);
return -EIO;
return -EIO;
return -ENOMEM;
return -EIO;
return -ENOMEM;
return -ENOMEM;
return -EIO;
typedef struct UnitStatusInfo {
const char *id;
const char *load_state;
const char *active_state;
const char *sub_state;
const char *unit_file_state;
const char *description;
const char *following;
const char *path;
const char *default_control_group;
const char *load_error;
bool need_daemon_reload;
const char *status_text;
#ifdef HAVE_SYSV_COMPAT
bool condition_result;
unsigned n_accepted;
unsigned n_connections;
bool accept;
const char *sysfs_path;
const char *where;
const char *what;
ExecStatusInfo *p;
assert(i);
if (i->following)
if (i->load_error)
else if (i->path)
if (ss)
on,
ss,
off);
on,
off);
if (s1)
else if (s2)
if (s1)
else if (s2)
if (i->sysfs_path)
if (i->where)
if (i->what)
if (i->accept)
bool good;
if (p->code == 0)
free(t);
#ifdef HAVE_SYSV_COMPAT
if (i->is_sysv)
if (!good) {
#ifdef HAVE_SYSV_COMPAT
i->main_pid = 0;
i->control_pid = 0;
if (i->main_pid > 0) {
if (i->running) {
char *t = NULL;
free(t);
} else if (i->exit_code > 0) {
#ifdef HAVE_SYSV_COMPAT
if ((c = exit_status_to_string(i->exit_status, i->is_sysv ? EXIT_STATUS_LSB : EXIT_STATUS_SYSTEMD)))
if (i->control_pid > 0) {
char *t = NULL;
free(t);
if (i->status_text)
if (i->default_control_group) {
if (i->need_daemon_reload)
ansi_highlight(true),
ansi_highlight(false),
assert(i);
case DBUS_TYPE_STRING: {
if (!isempty(s)) {
i->id = s;
i->load_state = s;
i->active_state = s;
i->sub_state = s;
i->description = s;
i->path = s;
#ifdef HAVE_SYSV_COMPAT
i->is_sysv = true;
i->path = s;
i->default_control_group = s;
i->status_text = s;
i->sysfs_path = s;
i->where = s;
i->what = s;
i->following = s;
i->unit_file_state = s;
case DBUS_TYPE_BOOLEAN: {
dbus_bool_t b;
i->accept = b;
i->need_daemon_reload = b;
i->condition_result = b;
case DBUS_TYPE_UINT32: {
uint32_t u;
i->running = true;
i->n_accepted = u;
i->n_connections = u;
case DBUS_TYPE_INT32: {
int32_t j;
i->exit_code = (int) j;
i->exit_status = (int) j;
case DBUS_TYPE_UINT64: {
uint64_t u;
case DBUS_TYPE_ARRAY: {
return -ENOMEM;
return -ENOMEM;
case DBUS_TYPE_STRUCT: {
const char *n, *message;
case DBUS_TYPE_STRUCT: {
uint32_t u;
else if (arg_all)
if (arg_all || s[0])
case DBUS_TYPE_ARRAY:
if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRUCT && streq(name, "EnvironmentFiles")) {
const char *path;
const char *base;
base,
} else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRUCT && streq(name, "ControlGroupAttributes")) {
attr,
value);
} else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRUCT && startswith(name, "Exec")) {
printf("%s={ path=%s ; argv[]=%s ; ignore_errors=%s ; start_time=[%s] ; stop_time=[%s] ; pid=%u ; code=%s ; status=%i%s%s }\n",
name,
strna(t),
free(t);
if (arg_all)
static int show_one(const char *verb, DBusConnection *bus, const char *path, bool show_properties, bool *new_line) {
ExecStatusInfo *p;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
path,
r = -ENOMEM;
goto finish;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
if (*new_line)
*new_line = true;
const char *name;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
if (show_properties)
r = -EIO;
goto finish;
if (!show_properties)
if (reply)
int r, ret = 0;
char **name;
if (show_properties)
goto finish;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
goto finish;
if (!dbus_message_append_args(m,
goto finish;
goto finish;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
goto finish;
if (!dbus_message_append_args(m,
goto finish;
goto finish;
} else if (show_properties) {
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
goto finish;
if (!dbus_message_append_args(m,
goto finish;
goto finish;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
goto finish;
if (!dbus_message_append_args(m,
goto finish;
goto finish;
goto finish;
ret = r;
if (reply)
return ret;
const char *text;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
return -ENOMEM;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
if (reply)
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
return -ENOMEM;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
path,
return -ENOMEM;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
if (!arg_quiet)
if (reply)
char **name;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
r = -ENOMEM;
goto finish;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Snapshot",
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
if (reply)
const char *method;
method =
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
method))) {
return -ENOMEM;
r = -EADDRNOTAVAIL;
goto finish;
goto finish;
r = -EIO;
goto finish;
if (reply)
char **name;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
r = -ENOMEM;
goto finish;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
return -ENOMEM;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
const char *text;
r = -EIO;
goto finish;
if (reply)
const char *method;
char **name;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
method))) {
return -ENOMEM;
r = -ENOMEM;
goto finish;
r = -ENOMEM;
goto finish;
r = -ENOMEM;
goto finish;
r = -EIO;
goto finish;
if (reply)
#if defined (HAVE_SYSV_COMPAT) && (defined(TARGET_FEDORA) || defined(TARGET_MANDRIVA) || defined(TARGET_SUSE) || defined(TARGET_MEEGO) || defined(TARGET_ALTLINUX) || defined(TARGET_MAGEIA))
const char *name;
char **k, *l, *q = NULL;
p = NULL;
r = -ENOMEM;
goto finish;
free(p);
if (found_native)
if (found_native)
p = NULL;
r = -ENOMEM;
goto finish;
if (!found_sysv) {
free(p);
argv[c++] =
free(q);
free(p);
r = -ENOMEM;
goto finish;
free(l);
if (pid < 0) {
free(p);
free(q);
r = -errno;
goto finish;
} else if (pid == 0) {
free(p);
free(q);
goto finish;
if (!arg_quiet)
if (!arg_quiet)
r = -EINVAL;
goto finish;
r = -EPROTO;
goto finish;
unsigned n_changes = 0, i;
carries_install_info = r;
carries_install_info = r;
carries_install_info = r;
goto finish;
for (i = 0; i < n_changes; i++) {
const char *method;
dbus_bool_t a, b;
expect_carries_install_info = true;
send_force = false;
expect_carries_install_info = true;
expect_carries_install_info = true;
send_force = false;
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
method);
r = -ENOMEM;
goto finish;
goto finish;
a = arg_runtime;
r = -ENOMEM;
goto finish;
if (send_force) {
b = arg_force;
r = -ENOMEM;
goto finish;
if (!reply) {
r = -EIO;
goto finish;
goto finish;
if (expect_carries_install_info) {
goto finish;
carries_install_info = b;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
if (!arg_no_reload)
if (carries_install_info == 0)
if (reply)
bool enabled;
char **name;
enabled = r > 0;
if (state < 0) {
r = state;
goto finish;
enabled = true;
if (!arg_quiet)
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
r = -ENOMEM;
goto finish;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
if (!reply) {
r = -EIO;
goto finish;
DBUS_TYPE_STRING, &s,
r = -EIO;
goto finish;
enabled = true;
if (!arg_quiet)
puts(s);
if (reply)
static int systemctl_help(void) {
" -a --all Show all units/properties, including dead/empty ones\n"
static int halt_help(void) {
static int shutdown_help(void) {
static int telinit_help(void) {
" 2, 3, 4, 5 Start runlevelX.target unit\n"
static int runlevel_help(void) {
arg_ask_password = true;
case ARG_VERSION:
return -ENOMEM;
arg_property = l;
arg_all = true;
arg_all = true;
case ARG_FAIL:
case ARG_IGNORE_DEPENDENCIES:
case ARG_USER:
case ARG_SYSTEM:
case ARG_GLOBAL:
case ARG_NO_BLOCK:
arg_no_block = true;
case ARG_NO_LEGEND:
arg_no_legend = true;
case ARG_NO_PAGER:
arg_no_pager = true;
case ARG_NO_WALL:
arg_no_wall = true;
case ARG_ORDER:
case ARG_REQUIRE:
case ARG_ROOT:
case ARG_FULL:
arg_full = true;
case ARG_FAILED:
arg_failed = true;
arg_quiet = true;
arg_force = true;
case ARG_NO_RELOAD:
arg_no_reload = true;
case ARG_KILL_WHO:
case ARG_KILL_MODE:
return -EINVAL;
case ARG_NO_ASK_PASSWORD:
arg_ask_password = false;
case ARG_RUNTIME:
arg_runtime = true;
return -EINVAL;
return -EINVAL;
return -EINVAL;
int c, runlevel;
arg_immediate = true;
case ARG_HELP:
halt_help();
case ARG_HALT:
case ARG_REBOOT:
arg_immediate = true;
arg_dry = true;
arg_no_wtmp = true;
arg_no_sync = true;
case ARG_NO_WALL:
arg_no_wall = true;
return -EINVAL;
return -EINVAL;
return -EINVAL;
assert(t);
*_u = 0;
uint64_t u;
if (safe_atou64(t, &u) < 0)
return -EINVAL;
char *e = NULL;
time_t s;
usec_t n;
errno = 0;
return -EINVAL;
return -EINVAL;
while (*_u <= n)
case ARG_HELP:
if (kexec_loaded())
arg_dry = true;
case ARG_NO_WALL:
arg_no_wall = true;
return -EINVAL;
return -EINVAL;
char from;
} table[] = {
case ARG_HELP:
telinit_help();
case ARG_NO_WALL:
arg_no_wall = true;
return -EINVAL;
return -EINVAL;
telinit_help();
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
optind ++;
case ARG_HELP:
return -EINVAL;
return -EINVAL;
return -EINVAL;
if (kexec_loaded())
if (sd_booted() > 0) {
return -EIO;
static int action_to_runlevel(void) {
static int talk_upstart(void) {
goto finish;
r = -EIO;
goto finish;
goto finish;
if (!(m = dbus_message_new_method_call(
r = -ENOMEM;
goto finish;
r = -ENOMEM;
goto finish;
r = -EADDRNOTAVAIL;
goto finish;
r = -EIO;
goto finish;
if (reply)
if (bus) {
static int talk_initctl(void) {
int r, fd;
char rl;
return -errno;
errno = 0;
const char* verb;
MORE,
LESS,
} argc_cmp;
const int argc;
} verbs[] = {
int left;
if (left <= 0)
return -EINVAL;
case EQUAL:
return -EINVAL;
case MORE:
return -EINVAL;
case LESS:
return -EINVAL;
if (running_in_chroot() > 0) {
if (!bus) {
return -EIO;
return -EIO;
struct shutdownd_command c;
zero(c);
c.elapse = t;
if (message)
return -errno;
return -errno;
if (bus) {
return -errno;
if (bus) {
goto done;
if (talk_upstart() > 0)
goto done;
if (talk_initctl() > 0)
goto done;
return -EIO;
done:
if (geteuid() != 0) {
return -EPERM;
if (arg_when > 0) {
free(m);
if (!arg_no_wtmp) {
if (sd_booted() > 0)
else if ((r = utmp_put_shutdown()) < 0)
if (!arg_no_sync)
sync();
if (arg_dry)
switch (arg_action) {
case ACTION_HALT:
case ACTION_POWEROFF:
case ACTION_REBOOT:
return -ENOSYS;
static int runlevel_main(void) {
log_open();
goto finish;
goto finish;
r = runlevel_main();
goto finish;
retval = 0;
goto finish;
if (!avoid_bus()) {
bus_connect(arg_scope == UNIT_FILE_SYSTEM ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, &bus, &private_bus, &error);
private_bus = false;
private_bus = false;
switch (arg_action) {
case ACTION_SYSTEMCTL:
case ACTION_HALT:
case ACTION_POWEROFF:
case ACTION_REBOOT:
case ACTION_KEXEC:
case ACTION_RUNLEVEL2:
case ACTION_RUNLEVEL3:
case ACTION_RUNLEVEL4:
case ACTION_RUNLEVEL5:
case ACTION_RESCUE:
case ACTION_EMERGENCY:
case ACTION_DEFAULT:
case ACTION_RELOAD:
case ACTION_REEXEC:
case ACTION_CANCEL_SHUTDOWN:
case ACTION_INVALID:
case ACTION_RUNLEVEL:
if (bus) {
pager_close();
agent_close();
return retval;