systemctl.c revision d889a2069a87e4617b32ddbdeace5a53a12c699d
c82fca6d3f5608b946f18d37e8710b1d71e3478dnd/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
5f5d1b4cc970b7f06ff8ef6526128e9a27303d88nd This file is part of systemd.
816bc7965d58c92c0d02fd42d6ea58090f70c6bdnd Copyright 2010 Lennart Poettering
031b91a62d25106ae69d4693475c79618dd5e884fielding systemd is free software; you can redistribute it and/or modify it
031b91a62d25106ae69d4693475c79618dd5e884fielding under the terms of the GNU Lesser General Public License as published by
031b91a62d25106ae69d4693475c79618dd5e884fielding the Free Software Foundation; either version 2.1 of the License, or
031b91a62d25106ae69d4693475c79618dd5e884fielding (at your option) any later version.
816bc7965d58c92c0d02fd42d6ea58090f70c6bdnd systemd is distributed in the hope that it will be useful, but
816bc7965d58c92c0d02fd42d6ea58090f70c6bdnd WITHOUT ANY WARRANTY; without even the implied warranty of
816bc7965d58c92c0d02fd42d6ea58090f70c6bdnd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
816bc7965d58c92c0d02fd42d6ea58090f70c6bdnd Lesser General Public License for more details.
816bc7965d58c92c0d02fd42d6ea58090f70c6bdnd You should have received a copy of the GNU Lesser General Public License
816bc7965d58c92c0d02fd42d6ea58090f70c6bdnd along with systemd; If not, see <http://www.gnu.org/licenses/>.
f7d880929d4c572ba3f240a6cded38f2fbeaa40ehumbedoohstatic bool arg_all = false;
c82fca6d3f5608b946f18d37e8710b1d71e3478dndstatic bool arg_no_block = false;
c82fca6d3f5608b946f18d37e8710b1d71e3478dndstatic bool arg_no_legend = false;
c82fca6d3f5608b946f18d37e8710b1d71e3478dndstatic bool arg_no_pager = false;
c82fca6d3f5608b946f18d37e8710b1d71e3478dndstatic bool arg_no_wtmp = false;
static bool arg_no_sync = false;
static bool arg_no_wall = false;
static bool arg_no_reload = false;
static bool arg_dry = false;
static bool arg_quiet = false;
static bool arg_full = false;
static int arg_force = 0;
static bool arg_ask_password = true;
static bool arg_failed = false;
static bool arg_runtime = false;
static enum action {
static enum dot {
static enum transport {
static bool arg_follow = false;
static bool private_bus = false;
static bool on_tty(void) {
if (_unlikely_(t < 0))
static void pager_open_if_enabled(void) {
on_tty();
if (arg_no_pager)
pager_open();
static void ask_password_agent_open_if_enabled(void) {
if (!arg_ask_password)
static void polkit_agent_open_if_enabled(void) {
if (!arg_ask_password)
static const char *ansi_highlight_red(bool b) {
if (!on_tty())
static const char *ansi_highlight_green(bool b) {
if (!on_tty())
return EXIT_NOPERMISSION;
return EXIT_NOTINSTALLED;
return EXIT_NOTIMPLEMENTED;
return EXIT_NOTCONFIGURED;
return EXIT_FAILURE;
if (arg_no_wall)
if (arg_wall) {
free(p);
free(p);
if (!table[a])
static bool avoid_bus(void) {
if (running_in_chroot() > 0)
if (sd_booted() <= 0)
struct unit_info {
const char *id;
const char *description;
const char *load_state;
const char *active_state;
const char *sub_state;
const char *following;
const char *unit_path;
const char *job_type;
const char *job_path;
static int compare_unit_info(const void *a, const void *b) {
const struct unit_info *u = a, *v = b;
const char *dot;
if (arg_failed)
const struct unit_info *u;
desc_len = 0;
if (!output_show_unit(u))
if (u->job_id != 0)
if (!arg_full) {
unsigned basic_len;
if (extra_len > 0) {
if (!arg_no_legend) {
if (!output_show_unit(u))
n_shown++;
free(e);
if (!arg_no_legend) {
if (arg_all)
unsigned c = 0, n_units = 0;
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;
struct unit_info *u;
r = -EIO;
goto finish;
if (c >= n_units) {
struct unit_info *w;
r = -ENOMEM;
goto finish;
unit_infos = w;
u = unit_infos+c;
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 (*result)
goto finish;
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_SUSPEND;
return ACTION_HIBERNATE;
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;
#ifdef HAVE_LOGIND
const char *method;
case ACTION_REBOOT:
case ACTION_POWEROFF:
case ACTION_SUSPEND:
case ACTION_HIBERNATE:
return -EINVAL;
"/org/freedesktop/login1",
method);
r = -ENOMEM;
goto finish;
if (!dbus_message_append_args(m,
r = -ENOMEM;
goto finish;
if (!reply) {
r = -ENOENT;
goto finish;
r = -EACCES;
goto finish;
r = -EIO;
goto finish;
if (reply)
return -ENOSYS;
enum action a;
return -EPERM;
(a == ACTION_HALT ||
a == ACTION_POWEROFF ||
a == ACTION_REBOOT))
halt_now(a);
(a == ACTION_HALT ||
a == ACTION_POWEROFF ||
a == ACTION_REBOOT ||
a == ACTION_KEXEC ||
a == ACTION_EXIT))
if (geteuid() != 0 &&
(a == ACTION_POWEROFF ||
a == ACTION_REBOOT ||
a == ACTION_SUSPEND ||
a == ACTION_HIBERNATE)) {
warn_wall(a);
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;
const char *result;
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) {
c = columns();
if (i->main_pid > 0)
if (i->control_pid > 0)
show_journal_by_unit(i->id, arg_output, 0, i->inactive_exit_timestamp_monotonic, arg_lines, arg_all, arg_follow);
if (i->need_daemon_reload)
ansi_highlight_red(true),
ansi_highlight_red(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;
i->result = 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;
if (!arg_quiet) {
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_quiet) {
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) {
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;
case ARG_FORCE:
arg_force ++;
case ARG_FOLLOW:
arg_follow = true;
arg_force ++;
arg_follow = 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;
if (arg_output < 0) {
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
int c, runlevel;
case ARG_HELP:
halt_help();
case ARG_HALT:
case ARG_REBOOT:
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) {
return -EIO;
return -EIO;
int fd;
struct sd_shutdown_command c;
if (fd < 0)
return -errno;
zero(c);
c.usec = t;
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:
case ACTION_HALT:
case ACTION_POWEROFF:
case ACTION_REBOOT:
if (geteuid() != 0) {
if (arg_when <= 0 &&
!arg_dry &&
!arg_force &&
return -EPERM;
if (arg_when > 0) {
free(m);
if (!arg_no_wtmp) {
if (sd_booted() > 0)
r = utmp_put_shutdown();
if (!arg_no_sync)
sync();
if (arg_dry)
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();
return retval;