static char **arg_wall = NULL;
static const char *arg_kill_who = NULL;
static const char *arg_kill_mode = NULL;
-static const char *arg_root = NULL;
static int arg_signal = SIGTERM;
+static const char *arg_root = NULL;
static usec_t arg_when = 0;
static enum action {
ACTION_INVALID,
static int daemon_reload(DBusConnection *bus, char **args, unsigned n);
-static void pager_open_if_enabled(void) {
- if (!arg_no_pager)
- pager_open();
-}
-
static bool on_tty(void) {
static int t = -1;
return t;
}
+static void pager_open_if_enabled(void) {
+ on_tty();
+
+ if (!arg_no_pager)
+ pager_open();
+}
+
static void spawn_ask_password_agent(void) {
pid_t parent;
" red = Conflicts\n"
" green = After\n");
- if (isatty(fileno(stdout)))
+ if (on_tty())
log_notice("-- You probably want to process this output with graphviz' dot tool.\n"
"-- Try a shell pipeline like 'systemctl dot | dot -Tsvg > systemd.svg'!\n");
dbus_message_iter_recurse(&iter, &sub);
- if (isatty(STDOUT_FILENO))
+ if (on_tty())
printf("%4s %-25s %-15s %-7s\n", "JOB", "UNIT", "TYPE", "STATE");
while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
dbus_message_iter_next(&sub);
}
- if (isatty(STDOUT_FILENO))
+ if (on_tty())
printf("\n%u jobs listed.\n", k);
r = 0;
static int status_property(const char *name, DBusMessageIter *iter, UnitStatusInfo *i) {
+ assert(name);
+ assert(iter);
+ assert(i);
+
switch (dbus_message_iter_get_arg_type(iter)) {
case DBUS_TYPE_STRING: {
dbus_message_iter_get_basic(iter, &s);
- if (s[0]) {
+ if (!isempty(s)) {
if (streq(name, "Id"))
i->id = s;
else if (streq(name, "LoadState"))
switch (dbus_message_iter_get_arg_type(iter)) {
- case DBUS_TYPE_STRING: {
- const char *s;
- dbus_message_iter_get_basic(iter, &s);
-
- if (arg_all || s[0])
- printf("%s=%s\n", name, s);
-
- return 0;
- }
-
- case DBUS_TYPE_BOOLEAN: {
- dbus_bool_t b;
- dbus_message_iter_get_basic(iter, &b);
- printf("%s=%s\n", name, yes_no(b));
-
- return 0;
- }
-
- case DBUS_TYPE_UINT64: {
- uint64_t u;
- dbus_message_iter_get_basic(iter, &u);
-
- /* Yes, heuristics! But we can change this check
- * should it turn out to not be sufficient */
-
- if (endswith(name, "Timestamp")) {
- char timestamp[FORMAT_TIMESTAMP_MAX], *t;
-
- if ((t = format_timestamp(timestamp, sizeof(timestamp), u)) || arg_all)
- printf("%s=%s\n", name, strempty(t));
- } else if (strstr(name, "USec")) {
- char timespan[FORMAT_TIMESPAN_MAX];
-
- printf("%s=%s\n", name, format_timespan(timespan, sizeof(timespan), u));
- } else
- printf("%s=%llu\n", name, (unsigned long long) u);
-
- return 0;
- }
-
- case DBUS_TYPE_UINT32: {
- uint32_t u;
- dbus_message_iter_get_basic(iter, &u);
-
- if (strstr(name, "UMask") || strstr(name, "Mode"))
- printf("%s=%04o\n", name, u);
- else
- printf("%s=%u\n", name, (unsigned) u);
-
- return 0;
- }
-
- case DBUS_TYPE_INT32: {
- int32_t i;
- dbus_message_iter_get_basic(iter, &i);
-
- printf("%s=%i\n", name, (int) i);
- return 0;
- }
-
- case DBUS_TYPE_DOUBLE: {
- double d;
- dbus_message_iter_get_basic(iter, &d);
-
- printf("%s=%g\n", name, d);
- return 0;
- }
-
case DBUS_TYPE_STRUCT: {
DBusMessageIter sub;
dbus_message_iter_recurse(iter, &sub);
case DBUS_TYPE_ARRAY:
- if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRING) {
- DBusMessageIter sub;
- bool space = false;
-
- dbus_message_iter_recurse(iter, &sub);
- if (arg_all ||
- dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
- printf("%s=", name);
-
- while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
- const char *s;
-
- assert(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING);
- dbus_message_iter_get_basic(&sub, &s);
- printf("%s%s", space ? " " : "", s);
-
- space = true;
- dbus_message_iter_next(&sub);
- }
-
- puts("");
- }
-
- return 0;
-
- } else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_BYTE) {
- DBusMessageIter sub;
-
- dbus_message_iter_recurse(iter, &sub);
- if (arg_all ||
- dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
- printf("%s=", name);
-
- while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
- uint8_t u;
-
- assert(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_BYTE);
- dbus_message_iter_get_basic(&sub, &u);
- printf("%02x", u);
-
- dbus_message_iter_next(&sub);
- }
-
- puts("");
- }
-
- return 0;
-
- } else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRUCT && streq(name, "EnvironmentFiles")) {
+ if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRUCT && streq(name, "EnvironmentFiles")) {
DBusMessageIter sub, sub2;
dbus_message_iter_recurse(iter, &sub);
break;
}
+ if (generic_print_property(name, iter, arg_all) > 0)
+ return 0;
+
if (arg_all)
printf("%s=[unprintable]\n", name);
return ret;
}
-static DBusHandlerResult monitor_filter(DBusConnection *connection, DBusMessage *message, void *data) {
- DBusError error;
- DBusMessage *m = NULL, *reply = NULL;
-
- assert(connection);
- assert(message);
-
- dbus_error_init(&error);
-
- log_debug("Got D-Bus request: %s.%s() on %s",
- dbus_message_get_interface(message),
- dbus_message_get_member(message),
- dbus_message_get_path(message));
-
- if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
- log_error("Warning! D-Bus connection terminated.");
- dbus_connection_close(connection);
-
- } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "UnitNew") ||
- dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "UnitRemoved")) {
- const char *id, *path;
-
- if (!dbus_message_get_args(message, &error,
- DBUS_TYPE_STRING, &id,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID))
- log_error("Failed to parse message: %s", bus_error_message(&error));
- else if (streq(dbus_message_get_member(message), "UnitNew"))
- printf("Unit %s added.\n", id);
- else
- printf("Unit %s removed.\n", id);
-
- } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "JobNew")) {
- uint32_t id;
- const char *path;
-
- if (!dbus_message_get_args(message, &error,
- DBUS_TYPE_UINT32, &id,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID))
- log_error("Failed to parse message: %s", bus_error_message(&error));
- else
- printf("Job %u added.\n", id);
-
-
- } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "JobRemoved")) {
- uint32_t id;
- const char *path, *result;
-
- if (!dbus_message_get_args(message, &error,
- DBUS_TYPE_UINT32, &id,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_STRING, &result,
- DBUS_TYPE_INVALID))
- log_error("Failed to parse message: %s", bus_error_message(&error));
- else
- printf("Job %u removed (result=%s).\n", id, result);
-
-
- } else if (dbus_message_is_signal(message, "org.freedesktop.DBus.Properties", "PropertiesChanged")) {
-
- const char *path, *interface, *property = "Id";
- DBusMessageIter iter, sub;
-
- path = dbus_message_get_path(message);
-
- if (!dbus_message_get_args(message, &error,
- DBUS_TYPE_STRING, &interface,
- DBUS_TYPE_INVALID)) {
- log_error("Failed to parse message: %s", bus_error_message(&error));
- goto finish;
- }
-
- if (!streq(interface, "org.freedesktop.systemd1.Job") &&
- !streq(interface, "org.freedesktop.systemd1.Unit"))
- goto finish;
-
- if (!(m = dbus_message_new_method_call(
- "org.freedesktop.systemd1",
- path,
- "org.freedesktop.DBus.Properties",
- "Get"))) {
- log_error("Could not allocate message.");
- goto oom;
- }
-
- if (!dbus_message_append_args(m,
- DBUS_TYPE_STRING, &interface,
- DBUS_TYPE_STRING, &property,
- DBUS_TYPE_INVALID)) {
- log_error("Could not append arguments to message.");
- goto finish;
- }
-
- if (!(reply = dbus_connection_send_with_reply_and_block(connection, m, -1, &error))) {
- log_error("Failed to issue method call: %s", bus_error_message(&error));
- goto finish;
- }
-
- if (!dbus_message_iter_init(reply, &iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) {
- log_error("Failed to parse reply.");
- goto finish;
- }
-
- dbus_message_iter_recurse(&iter, &sub);
-
- if (streq(interface, "org.freedesktop.systemd1.Unit")) {
- const char *id;
-
- if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING) {
- log_error("Failed to parse reply.");
- goto finish;
- }
-
- dbus_message_iter_get_basic(&sub, &id);
- printf("Unit %s changed.\n", id);
- } else {
- uint32_t id;
-
- if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_UINT32) {
- log_error("Failed to parse reply.");
- goto finish;
- }
-
- dbus_message_iter_get_basic(&sub, &id);
- printf("Job %u changed.\n", id);
- }
- }
-
-finish:
- if (m)
- dbus_message_unref(m);
-
- if (reply)
- dbus_message_unref(reply);
-
- dbus_error_free(&error);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-oom:
- if (m)
- dbus_message_unref(m);
-
- if (reply)
- dbus_message_unref(reply);
-
- dbus_error_free(&error);
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
-}
-
-static int monitor(DBusConnection *bus, char **args, unsigned n) {
- DBusMessage *m = NULL, *reply = NULL;
- DBusError error;
- int r;
-
- dbus_error_init(&error);
-
- if (!private_bus) {
- dbus_bus_add_match(bus,
- "type='signal',"
- "sender='org.freedesktop.systemd1',"
- "interface='org.freedesktop.systemd1.Manager',"
- "path='/org/freedesktop/systemd1'",
- &error);
-
- if (dbus_error_is_set(&error)) {
- log_error("Failed to add match: %s", bus_error_message(&error));
- r = -EIO;
- goto finish;
- }
-
- dbus_bus_add_match(bus,
- "type='signal',"
- "sender='org.freedesktop.systemd1',"
- "interface='org.freedesktop.DBus.Properties',"
- "member='PropertiesChanged'",
- &error);
-
- if (dbus_error_is_set(&error)) {
- log_error("Failed to add match: %s", bus_error_message(&error));
- r = -EIO;
- goto finish;
- }
- }
-
- if (!dbus_connection_add_filter(bus, monitor_filter, NULL, NULL)) {
- log_error("Failed to add filter.");
- r = -ENOMEM;
- goto finish;
- }
-
- if (!(m = dbus_message_new_method_call(
- "org.freedesktop.systemd1",
- "/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Manager",
- "Subscribe"))) {
- log_error("Could not allocate message.");
- r = -ENOMEM;
- goto finish;
- }
-
- if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) {
- log_error("Failed to issue method call: %s", bus_error_message(&error));
- r = -EIO;
- goto finish;
- }
-
- while (dbus_connection_read_write_dispatch(bus, -1))
- ;
-
- r = 0;
-
-finish:
-
- /* This is slightly dirty, since we don't undo the filter or the matches. */
-
- if (m)
- dbus_message_unref(m);
-
- if (reply)
- dbus_message_unref(reply);
-
- dbus_error_free(&error);
-
- return r;
-}
-
static int dump(DBusConnection *bus, char **args, unsigned n) {
DBusMessage *m = NULL, *reply = NULL;
DBusError error;
static int create_symlink(const char *verb, const char *orig_old_path, const char *new_path) {
int r;
- const char *old_path;
+ const char *old_path;
- if (arg_root)
- old_path = orig_old_path+strlen(arg_root);
- else
- old_path = orig_old_path;
+ if (arg_root)
+ old_path = orig_old_path+strlen(arg_root);
+ else
+ old_path = orig_old_path;
assert(old_path);
assert(new_path);
STRV_FOREACH(p, paths->unit_path) {
int fd;
- char *path, *should_free;
+ char *path, *should_free;
- if (arg_root)
- should_free = path = strappend(arg_root, *p);
- else {
- should_free = NULL;
- path = *p;
- }
+ if (arg_root)
+ should_free = path = strappend(arg_root, *p);
+ else {
+ should_free = NULL;
+ path = *p;
+ }
if (!(filename = path_make_absolute(i->name, path))) {
log_error("Out of memory");
return -ENOMEM;
}
- if (should_free)
- free(should_free);
+ if (should_free)
+ free(should_free);
/* Ensure that we don't follow symlinks */
if ((fd = open(filename, O_RDONLY|O_CLOEXEC|O_NOFOLLOW|O_NOCTTY)) >= 0)
tmp_path = strappend (arg_root, sysv);
exists = access (tmp_path, F_OK) >= 0;
free (tmp_path);
- } else
+ } else
exists = access(sysv, F_OK) >= 0;
if (exists) {
if (arg_root)
argv[3] = strappend("--root=", arg_root);
- log_info("Executing %s %s %s %s", argv[0], argv[1], strempty(argv[2]), strempty(argv[3]));
+ log_info("Executing %s %s %s %s", argv[0], argv[1], strempty(argv[2]), strempty(argv[3]));
if ((pid = fork()) < 0) {
log_error("Failed to fork: %m");
dbus_error_init(&error);
zero(paths);
- if ((r = lookup_paths_init(&paths, arg_user ? MANAGER_USER : MANAGER_SYSTEM)) < 0) {
+ if ((r = lookup_paths_init(&paths, arg_user ? MANAGER_USER : MANAGER_SYSTEM, true)) < 0) {
log_error("Failed to determine lookup paths: %s", strerror(-r));
goto finish;
}
" pending\n"
" --ignore-dependencies\n"
" When queueing a new job, ignore all its dependencies\n"
- " --kill-mode=MODE How to send signal\n"
" --kill-who=WHO Who to send signal to\n"
" -s --signal=SIGNAL Which signal to send\n"
- " -H --host=[user@]host\n"
+ " -H --host=[USER@]HOST\n"
" Show information for remote host\n"
" -P --privileged Acquire privileges before execution\n"
" -q --quiet Suppress output\n"
" --no-wall Don't send wall message before halt/power-off/reboot\n"
" --no-reload When enabling/disabling unit files, don't reload daemon\n"
" configuration\n"
- " --no-pager Do not pipe output into a pager.\n"
+ " --no-pager Do not pipe output into a pager\n"
" --no-ask-password\n"
" Do not ask for system passwords\n"
" --order When generating graph for dot, show only order\n"
" -f --force When enabling unit files, override existing symlinks\n"
" When shutting down, execute action immediately\n"
" --defaults When disabling unit files, remove default symlinks only\n\n"
- "Commands:\n"
+ "Unit Commands:\n"
" list-units List units\n"
" start [NAME...] Start (activate) one or more units\n"
" stop [NAME...] Stop (deactivate) one or more units\n"
" units/jobs or the manager\n"
" reset-failed [NAME...] Reset failed state for all, one, or more\n"
" units\n"
+ " load [NAME...] Load one or more units\n\n"
+ "Unit File Commands:\n"
" enable [NAME...] Enable one or more unit files\n"
" disable [NAME...] Disable one or more unit files\n"
- " is-enabled [NAME...] Check whether unit files are enabled\n"
- " load [NAME...] Load one or more units\n"
+ " is-enabled [NAME...] Check whether unit files are enabled\n\n"
+ "Job Commands:\n"
" list-jobs List jobs\n"
- " cancel [JOB...] Cancel all, one, or more jobs\n"
- " monitor Monitor unit/job changes\n"
+ " cancel [JOB...] Cancel all, one, or more jobs\n\n"
+ "Status Commands:\n"
" dump Dump server status\n"
- " dot Dump dependency graph for dot(1)\n"
+ " dot Dump dependency graph for dot(1)\n\n"
+ "Snapshot Commands:\n"
" snapshot [NAME] Create a snapshot\n"
- " delete [NAME...] Remove one or more snapshots\n"
- " daemon-reload Reload systemd manager configuration\n"
- " daemon-reexec Reexecute systemd manager\n"
+ " delete [NAME...] Remove one or more snapshots\n\n"
+ "Environment Commands:\n"
" show-environment Dump environment\n"
" set-environment [NAME=VALUE...] Set one or more environment variables\n"
- " unset-environment [NAME...] Unset one or more environment variables\n"
+ " unset-environment [NAME...] Unset one or more environment variables\n\n"
+ "Manager Lifecycle Commands:\n"
+ " daemon-reload Reload systemd manager configuration\n"
+ " daemon-reexec Reexecute systemd manager\n\n"
+ "System Commands:\n"
" default Enter system default mode\n"
" rescue Enter system rescue mode\n"
" emergency Enter system emergency mode\n"
{ "force", no_argument, NULL, 'f' },
{ "no-reload", no_argument, NULL, ARG_NO_RELOAD },
{ "defaults", no_argument, NULL, ARG_DEFAULTS },
- { "kill-mode", required_argument, NULL, ARG_KILL_MODE },
+ { "kill-mode", required_argument, NULL, ARG_KILL_MODE }, /* undocumented on purpose */
{ "kill-who", required_argument, NULL, ARG_KILL_WHO },
{ "signal", required_argument, NULL, 's' },
{ "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
goto finish;
}
- r = 0;
+ r = 1;
finish:
if (m)
{ "check", MORE, 2, check_unit },
{ "show", MORE, 1, show },
{ "status", MORE, 2, show },
- { "monitor", EQUAL, 1, monitor },
{ "dump", EQUAL, 1, dump },
{ "dot", EQUAL, 1, dot },
{ "snapshot", LESS, 2, snapshot },