systemctl.c revision a9616cd17fb0a57ac92d39e1ad261caa1039d7b1
1689N/A along with systemd; If not, see <http://www.gnu.org/licenses/>.
2086N/A#include "sd-daemon.h"
1689N/A#include "sd-shutdown.h"
1689N/A#include "sd-login.h"
1689N/A#include "utmp-wtmp.h"
3853N/A#include "path-util.h"
1689N/A#include "cgroup-show.h"
1689N/A#include "cgroup-util.h"
1689N/A#include "path-lookup.h"
1689N/A#include "conf-parser.h"
1689N/A#include "exit-status.h"
3853N/A#include "bus-errors.h"
1689N/A#include "unit-name.h"
1689N/A#include "spawn-ask-password-agent.h"
1689N/A#include "spawn-polkit-agent.h"
1689N/A#include "logs-show.h"
1689N/A#include "path-util.h"
1689N/A#include "socket-util.h"
1689N/A#include "bus-util.h"
1689N/A#include "bus-message.h"
1689N/A#include "bus-error.h"
1689N/Astatic bool original_stdout_is_tty;
1689N/Astatic enum dependency {
1689N/Astatic bool arg_no_block = false;
1689N/Astatic bool arg_no_legend = false;
1689N/Astatic bool arg_no_pager = false;
1689N/Astatic bool arg_no_wtmp = false;
1689N/Astatic bool arg_no_wall = false;
1689N/Astatic bool arg_no_reload = false;
1689N/Astatic bool arg_show_types = false;
1689N/Astatic bool arg_ignore_inhibitors = false;
1689N/Astatic bool arg_ask_password = true;
1689N/Astatic bool arg_runtime = false;
1689N/Astatic void pager_open_if_enabled(void) {
1689N/A if (arg_no_pager)
1689N/A pager_open(false);
1689N/Astatic void ask_password_agent_open_if_enabled(void) {
1689N/A if (!arg_ask_password)
1689N/A#ifdef HAVE_LOGIND
1689N/Astatic void polkit_agent_open_if_enabled(void) {
1689N/A if (!arg_ask_password)
1689N/A return EXIT_NOPERMISSION;
1689N/A return EXIT_NOTINSTALLED;
1689N/A return EXIT_NOTIMPLEMENTED;
1689N/A return EXIT_NOTCONFIGURED;
1689N/A return EXIT_FAILURE;
1689N/A if (arg_no_wall)
1689N/A _cleanup_free_ char *p;
1689N/A if (running_in_chroot() > 0)
1689N/Astatic int compare_unit_info(const void *a, const void *b) {
1689N/A if (!output_show_unit(u))
3840N/A if (!output_show_unit(u))
1689N/A if (!arg_no_legend) {
1689N/Astatic int get_unit_list(
3853N/A "org.freedesktop.systemd1",
1689N/A "org.freedesktop.systemd1.Manager",
1689N/A return bus_log_parse_error(r);
2086N/A unit_infos[c++] = u;
1689N/A return bus_log_parse_error(r);
1689N/A return bus_log_parse_error(r);
1689N/Astatic int get_triggered_units(
1689N/A "org.freedesktop.systemd1",
1689N/A "org.freedesktop.systemd1.Unit",
1689N/Astatic int get_listening(
1689N/A "org.freedesktop.systemd1",
1689N/A "org.freedesktop.systemd1.Socket",
1689N/A return bus_log_parse_error(r);
1689N/A return bus_log_parse_error(r);
1689N/A return bus_log_parse_error(r);
1689N/Astruct socket_info {
1689N/A bool own_triggered;
1689N/A struct socket_info *s;
1689N/A if (arg_show_types)
1689N/A if (!arg_no_legend)
1689N/A if (arg_show_types)
1689N/A if (!arg_no_legend)
1689N/A if (!arg_no_legend) {
1689N/A struct socket_info *s;
1689N/A if (!output_show_unit(u))
1689N/A .own_triggered = i==0,
3352N/A if (s->own_triggered)
1689N/Astatic int compare_unit_file_list(const void *a, const void *b) {
1689N/A const UnitFileList *u = a, *v = b;
3352N/A const UnitFileList *u;
3352N/A if (!output_show_unit_file(u))
5154N/A unsigned basic_cols;
3352N/A if (!arg_no_legend)
1881N/A if (!output_show_unit_file(u))
1881N/A if (!arg_no_legend)
1881N/A UnitFileList *u;
1689N/A HASHMAP_FOREACH(u, h, i) {
3004N/A hashmap_free(h);
1689N/A "org.freedesktop.systemd1",
3004N/A "org.freedesktop.systemd1.Manager",
1689N/A return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
if (!arg_plain) {
if (arg_full){
return log_oom();
static const char *dependencies[] = {
if (!path)
return log_oom();
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
path,
&error,
&reply,
return bus_log_parse_error(r);
const char *prop;
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return strcasecmp(*a, *b);
static int list_dependencies_one(
const char *name,
int level,
char ***units,
unsigned int branches) {
return log_oom();
if (strv_contains(u, *c)) {
if (!arg_plain) {
if (arg_plain) {
*units = u;
u = NULL;
if (!unit)
return log_oom();
u = unit;
puts(u);
const char *path;
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
&reply,
NULL);
return bus_log_parse_error(r);
if (path)
struct job_info {
const struct job_info *j;
bool shorten = false;
shorten = true;
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
&reply,
NULL);
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(reply, "(usssoo)", &id, &name, &type, &state, &job_path, &unit_path)) > 0) {
return log_oom();
id,
name,
type,
return bus_log_parse_error(r);
return bus_log_parse_error(r);
char **name;
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
NULL,
const char *path;
return -ENOMEM;
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
NULL,
&reply,
bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Unit",
NULL,
typedef struct WaitData {
char *name;
char *result;
} WaitData;
assert(m);
assert(d);
char *ret;
if (!ret)
#ifndef NOLEGACY
if (!ret)
if (*result)
r = sd_bus_add_match(
bus,
"sender='org.freedesktop.systemd1',"
"interface='org.freedesktop.systemd1.Manager',"
"path='/org/freedesktop/systemd1'",
return -EIO;
assert(s);
return log_oom();
while (!set_isempty(s)) {
if (!d.result)
goto free_name;
if (!arg_quiet) {
log_error("Job for %s failed. See 'systemctl status %s' and 'journalctl -xn' for details.", strna(d.name), strna(d.name));
r = -ETIME;
r = -ECANCELED;
r = -EIO;
const char *path;
return log_oom();
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
NULL,
&reply,
if (!quiet)
return bus_log_parse_error(r);
bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Unit",
NULL,
&state);
if (!quiet)
if (!quiet)
static int check_triggering_units(
const char *name) {
bool print_warning_label = true;
return log_oom();
if (!path)
return log_oom();
bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Unit",
&error,
&state);
bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Unit",
&error,
&triggered_by);
if (print_warning_label) {
print_warning_label = false;
static int start_unit_one(
const char *method,
const char *name,
const char *mode,
Set *s) {
_cleanup_free_ char *n;
const char *path;
return log_oom();
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&reply,
return -EADDRNOTAVAIL;
return bus_log_parse_error(r);
return log_oom();
r = set_consume(s, p);
return log_oom();
const char *target;
const char *verb;
const char *mode;
enum action i;
return _ACTION_INVALID;
char **name;
method =
if (!arg_no_block) {
return log_oom();
if (one_name) {
if (!arg_no_block) {
if (one_name)
#ifdef HAVE_LOGIND
const char *method;
if (!bus)
return -EIO;
case ACTION_REBOOT:
case ACTION_POWEROFF:
case ACTION_SUSPEND:
case ACTION_HIBERNATE:
case ACTION_HYBRID_SLEEP:
return -EINVAL;
r = sd_bus_call_method(
bus,
"/org/freedesktop/login1",
&error,
NULL,
return -ENOSYS;
#ifdef HAVE_LOGIND
if (!bus)
if (arg_when > 0)
if (geteuid() == 0)
if (!on_tty())
r = sd_bus_call_method(
bus,
"/org/freedesktop/login1",
NULL,
&reply,
NULL);
return bus_log_parse_error(r);
if (!sv)
return log_oom();
a == ACTION_HALT ||
a == ACTION_POWEROFF ||
a == ACTION_REBOOT ||
return bus_log_parse_error(r);
return bus_log_parse_error(r);
_cleanup_free_ char *type = NULL, *tty = NULL, *seat = NULL, *user = NULL, *service = NULL, *class = NULL;
log_warning("User %s is logged in on %s.", strna(user), isempty(tty) ? (isempty(seat) ? strna(service) : seat) : tty);
log_error("Please retry operation after closing inhibitors and logging out other users.\nAlternatively, ignore inhibitors and users with 'systemctl %s -i'.",
return -EPERM;
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 ||
a == ACTION_HYBRID_SLEEP)) {
if (r == EXIT_SUCCESS)
warn_wall(a);
char **name;
int state;
if (state < 0)
return state;
if (state > 0)
char **name;
int state;
if (state < 0)
return state;
if (state > 0)
char **name;
if (!arg_kill_who)
return log_oom();
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
NULL,
typedef struct ExecStatusInfo {
char *name;
char *path;
char **argv;
bool ignore;
int code;
int status;
assert(i);
free(i);
const char *path;
int ignore, r;
assert(m);
assert(i);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
if (!i->path)
return log_oom();
return bus_log_parse_error(r);
r = sd_bus_message_read(m,
&ignore,
&pid,
return bus_log_parse_error(r);
r = sd_bus_message_exit_container(m);
return bus_log_parse_error(r);
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;
char **documentation;
const char *fragment_path;
const char *source_path;
const char *control_group;
char **dropin_paths;
const char *load_error;
const char *result;
bool need_daemon_reload;
const char *status_text;
const char *pid_file;
bool condition_result;
bool failed_condition_trigger;
bool failed_condition_negate;
const char *failed_condition;
const char *failed_condition_param;
unsigned n_accepted;
unsigned n_connections;
bool accept;
char **listen;
const char *sysfs_path;
const char *where;
const char *what;
static void print_status_info(
UnitStatusInfo *i,
bool *ellipsized) {
ExecStatusInfo *p;
const char *path;
int flags =
char **t, **t2;
assert(i);
if (i->following)
if (i->load_error)
else if (path)
bool last = false;
char ** dropin;
log_oom();
if (ss)
if (s1)
else if (s2)
if (i->failed_condition_trigger)
else if (i->failed_condition)
i->failed_condition,
if (i->sysfs_path)
if (i->where)
if (i->what)
if (i->accept)
bool good;
if (p->code == 0)
if (!good) {
i->main_pid = 0;
i->control_pid = 0;
if (i->main_pid > 0) {
if (i->running) {
if (comm)
} else if (i->exit_code > 0) {
if (i->control_pid > 0)
if (i->control_pid > 0) {
if (i->status_text)
if (i->control_group &&
(i->main_pid > 0 || i->control_pid > 0 || cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, i->control_group, false) == 0)) {
c = columns();
if (i->main_pid > 0)
if (i->control_pid > 0)
i->id,
getuid(),
if (i->need_daemon_reload)
assert(i);
if (!i->documentation) {
char *e = NULL;
size_t k;
k = strlen(*p);
log_oom();
if (pid < 0) {
if (pid == 0) {
static int status_property(const char *name, sd_bus_message *m, UnitStatusInfo *i, const char *contents) {
assert(m);
assert(i);
switch (contents[0]) {
case SD_BUS_TYPE_STRING: {
return bus_log_parse_error(r);
if (!isempty(s)) {
i->id = s;
i->load_state = s;
i->active_state = s;
i->sub_state = s;
i->description = s;
i->fragment_path = s;
i->source_path = s;
#ifndef NOLEGACY
i->control_group = e;
i->control_group = s;
i->status_text = s;
i->pid_file = s;
i->sysfs_path = s;
i->where = s;
i->what = s;
i->following = s;
i->unit_file_state = s;
i->result = s;
case SD_BUS_TYPE_BOOLEAN: {
return bus_log_parse_error(r);
i->accept = b;
i->need_daemon_reload = b;
i->condition_result = b;
case SD_BUS_TYPE_UINT32: {
uint32_t u;
return bus_log_parse_error(r);
i->running = true;
i->n_accepted = u;
i->n_connections = u;
case SD_BUS_TYPE_INT32: {
int32_t j;
return bus_log_parse_error(r);
i->exit_code = (int) j;
i->exit_status = (int) j;
case SD_BUS_TYPE_UINT64: {
uint64_t u;
return bus_log_parse_error(r);
case SD_BUS_TYPE_ARRAY:
return bus_log_parse_error(r);
if (!info)
return log_oom();
log_oom();
if (!info)
log_oom();
return bus_log_parse_error(r);
r = sd_bus_message_exit_container(m);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
r = sd_bus_message_exit_container(m);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
r = sd_bus_message_exit_container(m);
return bus_log_parse_error(r);
goto skip;
case SD_BUS_TYPE_STRUCT_BEGIN:
const char *n, *message;
return bus_log_parse_error(r);
goto skip;
goto skip;
skip:
return bus_log_parse_error(r);
assert(m);
switch (contents[0]) {
case SD_BUS_TYPE_STRUCT_BEGIN:
uint32_t u;
return bus_log_parse_error(r);
else if (arg_all)
return bus_log_parse_error(r);
return bus_log_parse_error(r);
case SD_BUS_TYPE_ARRAY:
const char *path;
int ignore;
return bus_log_parse_error(r);
return bus_log_parse_error(r);
r = sd_bus_message_exit_container(m);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
r = sd_bus_message_exit_container(m);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
r = sd_bus_message_exit_container(m);
return bus_log_parse_error(r);
const char *base;
return bus_log_parse_error(r);
base,
return bus_log_parse_error(r);
r = sd_bus_message_exit_container(m);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
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,
r = sd_bus_message_exit_container(m);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
r = sd_bus_message_exit_container(m);
return bus_log_parse_error(r);
const char *path;
return bus_log_parse_error(r);
return bus_log_parse_error(r);
r = sd_bus_message_exit_container(m);
return bus_log_parse_error(r);
} else if (contents[1] == SD_BUS_TYPE_STRUCT_BEGIN && (streq(name, "BlockIOReadBandwidth") || streq(name, "BlockIOWriteBandwidth"))) {
const char *path;
return bus_log_parse_error(r);
return bus_log_parse_error(r);
r = sd_bus_message_exit_container(m);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
if (arg_all)
static int show_one(
const char *verb,
const char *path,
bool show_properties,
bool *new_line,
bool *ellipsized) {
ExecStatusInfo *p;
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
path,
&error,
&reply,
return bus_log_parse_error(r);
if (*new_line)
*new_line = true;
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
if (show_properties)
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
if (!show_properties) {
static int show_one_by_pid(
const char *verb,
bool *new_line,
bool *ellipsized) {
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
&reply,
return bus_log_parse_error(r);
static int show_all(
const char* verb,
bool show_properties,
bool *new_line,
bool *ellipsized) {
const UnitInfo *u;
if (!output_show_unit(u))
return log_oom();
int r, ret = 0;
char **name;
bool ellipsized = false;
if (show_properties)
return show_one(args[0], bus, "/org/freedesktop/systemd1", show_properties, &new_line, &ellipsized);
return log_oom();
p = unit_dbus_path_from_name(n);
return log_oom();
ret = r;
} else if (show_properties) {
return log_oom();
ret = r;
ret = r;
return ret;
const char *eq;
char *field;
assert(m);
if (!eq) {
return -EINVAL;
eq ++;
return bus_log_create_error(r);
return -EINVAL;
return -EINVAL;
uint64_t u;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
uint64_t u;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return bus_log_create_error(r);
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
return bus_log_create_error(r);
return log_oom();
return bus_log_create_error(r);
return bus_log_create_error(r);
return bus_log_create_error(r);
r = append_assignment(m, *i);
r = sd_bus_message_close_container(m);
return bus_log_create_error(r);
r = sd_bus_message_close_container(m);
return bus_log_create_error(r);
const char *path;
return log_oom();
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
&reply,
return bus_log_parse_error(r);
bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Unit",
&error,
&id);
if (!arg_quiet)
char **name;
return log_oom();
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
NULL,
const char *method;
method =
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
NULL,
NULL);
r = -EADDRNOTAVAIL;
char **name;
_cleanup_free_ char *n;
return log_oom();
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
NULL,
const char *text;
r = sd_bus_get_property(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
&reply,
return bus_log_parse_error(r);
return bus_log_parse_error(r);
return bus_log_parse_error(r);
const char *root;
return -EINVAL;
NULL);
if (!init)
if (!init)
return log_oom();
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
NULL,
const char *method;
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
return bus_log_create_error(r);
return bus_log_create_error(r);
for (f = 0; args[f]; f++) {
const char *name;
r = log_oom();
goto finish;
free(p);
p = NULL;
if (found_native)
if (found_native)
r = log_oom();
goto finish;
if (!found_sysv)
argv[c++] =
r = log_oom();
goto finish;
free(l);
if (pid < 0) {
r = -errno;
goto finish;
} else if (pid == 0) {
goto finish;
if (!arg_quiet)
if (!arg_quiet)
r = -EINVAL;
goto finish;
r = -EPROTO;
goto finish;
for (f = 0, t = 0; args[f]; f++) {
char **i, **l, **name;
return log_oom();
strv_free(l);
return log_oom();
*i = NULL;
*mangled_names = l;
unsigned n_changes = 0, i;
r = unit_file_enable(arg_scope, arg_runtime, arg_root, mangled_names, arg_force, &changes, &n_changes);
carries_install_info = r;
r = unit_file_reenable(arg_scope, arg_runtime, arg_root, mangled_names, arg_force, &changes, &n_changes);
carries_install_info = r;
r = unit_file_link(arg_scope, arg_runtime, arg_root, mangled_names, arg_force, &changes, &n_changes);
r = unit_file_preset(arg_scope, arg_runtime, arg_root, mangled_names, arg_force, &changes, &n_changes);
carries_install_info = r;
r = unit_file_mask(arg_scope, arg_runtime, arg_root, mangled_names, arg_force, &changes, &n_changes);
goto finish;
if (!arg_quiet) {
for (i = 0; i < n_changes; i++) {
int expect_carries_install_info = false;
bool send_force = true;
expect_carries_install_info = true;
send_force = false;
expect_carries_install_info = true;
expect_carries_install_info = true;
send_force = false;
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
return bus_log_create_error(r);
return bus_log_create_error(r);
return bus_log_create_error(r);
if (send_force) {
return bus_log_create_error(r);
if (expect_carries_install_info) {
return bus_log_parse_error(r);
return bus_log_parse_error(r);
if (!arg_quiet) {
return bus_log_parse_error(r);
return bus_log_parse_error(r);
if (!arg_no_reload)
if (carries_install_info == 0)
bool enabled;
char **name;
enabled = r > 0;
if (state < 0) {
return state;
enabled = true;
if (!arg_quiet)
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
&reply,
return bus_log_parse_error(r);
enabled = true;
if (!arg_quiet)
puts(s);
return !enabled;
static int systemctl_help(void) {
" -a --all Show all loaded units/properties, including dead/empty\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) {
static int help_types(void) {
for(i = 0; i < _UNIT_TYPE_MAX; i++) {
t = unit_type_to_string(i);
puts(t);
return systemctl_help();
case ARG_VERSION:
if (!type)
return -ENOMEM;
help_types();
return log_oom();
return log_oom();
return -EINVAL;
if (!arg_properties)
return log_oom();
char *prop;
if (!prop)
return log_oom();
return log_oom();
arg_all = true;
arg_all = true;
case ARG_REVERSE:
case ARG_AFTER:
case ARG_BEFORE:
case ARG_SHOW_TYPES:
arg_show_types = true;
case ARG_FAIL:
case ARG_IRREVERSIBLE:
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_ROOT:
arg_full = true;
case ARG_FAILED:
return log_oom();
arg_quiet = true;
case ARG_FORCE:
arg_force ++;
arg_force ++;
case ARG_NO_RELOAD:
arg_no_reload = true;
case ARG_KILL_WHO:
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;
arg_ignore_inhibitors = true;
case ARG_PLAIN:
arg_plain = true;
case ARG_STATE: {
return log_oom();
free(s);
return log_oom();
return -EINVAL;
return -EINVAL;
int c, r, runlevel;
case ARG_HELP:
return halt_help();
case ARG_HALT:
case ARG_REBOOT:
arg_dry = true;
arg_no_wtmp = true;
case ARG_NO_WALL:
arg_no_wall = true;
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:
return shutdown_help();
if (kexec_loaded())
arg_dry = true;
case ARG_NO_WALL:
arg_no_wall = true;
return -EINVAL;
char from;
} table[] = {
case ARG_HELP:
return telinit_help();
case ARG_NO_WALL:
arg_no_wall = true;
return -EINVAL;
telinit_help();
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
optind ++;
case ARG_HELP:
return runlevel_help();
return -EINVAL;
return -EINVAL;
if (kexec_loaded())
if (sd_booted() > 0) {
return -EIO;
static int talk_initctl(void) {
.sleeptime = 0,
char rl;
if (!rl)
if (fd < 0) {
return -errno;
errno = 0;
const char* verb;
MORE,
LESS,
} argc_cmp;
const int argc;
} verbs[] = {
int left;
if (left <= 0)
return -EINVAL;
return -EINVAL;
case EQUAL:
return -EINVAL;
case MORE:
return -EINVAL;
case LESS:
return -EINVAL;
if (running_in_chroot() > 0) {
return -EIO;
return -EIO;
struct sd_shutdown_command c = {
.usec = t,
.iov_base = (char*) &c,
if (fd < 0)
return -errno;
return -errno;
if (bus) {
return -errno;
if (bus) {
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 <= 0 &&
return -EPERM;
if (arg_when > 0) {
_cleanup_free_ char *m;
return log_oom();
if (!arg_no_wtmp) {
if (sd_booted() > 0)
r = utmp_put_shutdown();
if (arg_dry)
return -ENOSYS;
static int runlevel_main(void) {
log_open();
goto finish;
r = runlevel_main();
goto finish;
goto finish;
if (!avoid_bus()) {
goto finish;
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: {
if (arg_wall) {
r = log_oom();
goto finish;
case ACTION_RUNLEVEL:
case _ACTION_INVALID:
pager_close();
return r < 0 ? EXIT_FAILURE : r;