chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
move /usr/bin/systemd to /usr/lib/systemd/systemd
[elogind.git]
/
src
/
systemctl.c
diff --git
a/src/systemctl.c
b/src/systemctl.c
index 2f11d6bc1d09bd2bffeb914d3c9c6d8d8eaa3e38..12264f8ba7c709b1231a220ed2602722ba68954e 100644
(file)
--- a/
src/systemctl.c
+++ b/
src/systemctl.c
@@
-35,6
+35,8
@@
#include <sys/prctl.h>
#include <dbus/dbus.h>
#include <sys/prctl.h>
#include <dbus/dbus.h>
+#include <systemd/sd-daemon.h>
+
#include "log.h"
#include "util.h"
#include "macro.h"
#include "log.h"
#include "util.h"
#include "macro.h"
@@
-49,7
+51,6
@@
#include "list.h"
#include "path-lookup.h"
#include "conf-parser.h"
#include "list.h"
#include "path-lookup.h"
#include "conf-parser.h"
-#include "sd-daemon.h"
#include "shutdownd.h"
#include "exit-status.h"
#include "bus-errors.h"
#include "shutdownd.h"
#include "exit-status.h"
#include "bus-errors.h"
@@
-58,6
+59,7
@@
#include "pager.h"
#include "spawn-agent.h"
#include "install.h"
#include "pager.h"
#include "spawn-agent.h"
#include "install.h"
+#include "logs-show.h"
static const char *arg_type = NULL;
static char **arg_property = NULL;
static const char *arg_type = NULL;
static char **arg_property = NULL;
@@
-117,6
+119,9
@@
static enum transport {
TRANSPORT_POLKIT
} arg_transport = TRANSPORT_NORMAL;
static const char *arg_host = NULL;
TRANSPORT_POLKIT
} arg_transport = TRANSPORT_NORMAL;
static const char *arg_host = NULL;
+static bool arg_follow = false;
+static unsigned arg_lines = 10;
+static OutputMode arg_output = OUTPUT_SHORT;
static bool private_bus = false;
static bool private_bus = false;
@@
-161,12
+166,12
@@
static void agent_open_if_enabled(void) {
agent_open();
}
agent_open();
}
-static const char *ansi_highlight(bool b) {
+static const char *ansi_highlight
_red
(bool b) {
if (!on_tty())
return "";
if (!on_tty())
return "";
- return b ? ANSI_HIGHLIGHT_ON : ANSI_HIGHLIGHT_OFF;
+ return b ? ANSI_HIGHLIGHT_
RED_
ON : ANSI_HIGHLIGHT_OFF;
}
static const char *ansi_highlight_green(bool b) {
}
static const char *ansi_highlight_green(bool b) {
@@
-378,14
+383,14
@@
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
n_shown++;
if (streq(u->load_state, "error")) {
n_shown++;
if (streq(u->load_state, "error")) {
- on_loaded = ansi_highlight(true);
- off_loaded = ansi_highlight(false);
+ on_loaded = ansi_highlight
_red
(true);
+ off_loaded = ansi_highlight
_red
(false);
} else
on_loaded = off_loaded = "";
if (streq(u->active_state, "failed")) {
} else
on_loaded = off_loaded = "";
if (streq(u->active_state, "failed")) {
- on_active = ansi_highlight(true);
- off_active = ansi_highlight(false);
+ on_active = ansi_highlight
_red
(true);
+ off_active = ansi_highlight
_red
(false);
} else
on_active = off_active = "";
} else
on_active = off_active = "";
@@
-588,8
+593,8
@@
static void output_unit_file_list(const UnitFileList *units, unsigned c) {
if (u->state == UNIT_FILE_MASKED ||
u->state == UNIT_FILE_MASKED_RUNTIME ||
u->state == UNIT_FILE_DISABLED) {
if (u->state == UNIT_FILE_MASKED ||
u->state == UNIT_FILE_MASKED_RUNTIME ||
u->state == UNIT_FILE_DISABLED) {
- on = ansi_highlight(true);
- off = ansi_highlight(false);
+ on = ansi_highlight
_red
(true);
+ off = ansi_highlight
_red
(false);
} else if (u->state == UNIT_FILE_ENABLED) {
on = ansi_highlight_green(true);
off = ansi_highlight_green(false);
} else if (u->state == UNIT_FILE_ENABLED) {
on = ansi_highlight_green(true);
off = ansi_highlight_green(false);
@@
-1432,9
+1437,9
@@
static int wait_for_jobs(DBusConnection *bus, Set *s) {
else if (streq(d.result, "canceled"))
log_error("Job canceled.");
else if (streq(d.result, "dependency"))
else if (streq(d.result, "canceled"))
log_error("Job canceled.");
else if (streq(d.result, "dependency"))
- log_error("A dependency job failed. See system
logs
for details.");
+ log_error("A dependency job failed. See system
journal
for details.");
else if (!streq(d.result, "done") && !streq(d.result, "skipped"))
else if (!streq(d.result, "done") && !streq(d.result, "skipped"))
- log_error("Job failed. See system
logs
and 'systemctl status' for details.");
+ log_error("Job failed. See system
journal
and 'systemctl status' for details.");
}
if (streq_ptr(d.result, "timeout"))
}
if (streq_ptr(d.result, "timeout"))
@@
-1998,8
+2003,10
@@
typedef struct UnitStatusInfo {
const char *default_control_group;
const char *load_error;
const char *default_control_group;
const char *load_error;
+ const char *result;
usec_t inactive_exit_timestamp;
usec_t inactive_exit_timestamp;
+ usec_t inactive_exit_timestamp_monotonic;
usec_t active_enter_timestamp;
usec_t active_exit_timestamp;
usec_t inactive_enter_timestamp;
usec_t active_enter_timestamp;
usec_t active_exit_timestamp;
usec_t inactive_enter_timestamp;
@@
-2063,8
+2070,8
@@
static void print_status_info(UnitStatusInfo *i) {
printf("\t Follow: unit currently follows state of %s\n", i->following);
if (streq_ptr(i->load_state, "error")) {
printf("\t Follow: unit currently follows state of %s\n", i->following);
if (streq_ptr(i->load_state, "error")) {
- on = ansi_highlight(true);
- off = ansi_highlight(false);
+ on = ansi_highlight
_red
(true);
+ off = ansi_highlight
_red
(false);
} else
on = off = "";
} else
on = off = "";
@@
-2080,8
+2087,8
@@
static void print_status_info(UnitStatusInfo *i) {
ss = streq_ptr(i->active_state, i->sub_state) ? NULL : i->sub_state;
if (streq_ptr(i->active_state, "failed")) {
ss = streq_ptr(i->active_state, i->sub_state) ? NULL : i->sub_state;
if (streq_ptr(i->active_state, "failed")) {
- on = ansi_highlight(true);
- off = ansi_highlight(false);
+ on = ansi_highlight
_red
(true);
+ off = ansi_highlight
_red
(false);
} else if (streq_ptr(i->active_state, "active") || streq_ptr(i->active_state, "reloading")) {
on = ansi_highlight_green(true);
off = ansi_highlight_green(false);
} else if (streq_ptr(i->active_state, "active") || streq_ptr(i->active_state, "reloading")) {
on = ansi_highlight_green(true);
off = ansi_highlight_green(false);
@@
-2100,6
+2107,9
@@
static void print_status_info(UnitStatusInfo *i) {
strna(i->active_state),
off);
strna(i->active_state),
off);
+ if (!isempty(i->result) && !streq(i->result, "success"))
+ printf(" (Result: %s)", i->result);
+
timestamp = (streq_ptr(i->active_state, "active") ||
streq_ptr(i->active_state, "reloading")) ? i->active_enter_timestamp :
(streq_ptr(i->active_state, "inactive") ||
timestamp = (streq_ptr(i->active_state, "active") ||
streq_ptr(i->active_state, "reloading")) ? i->active_enter_timestamp :
(streq_ptr(i->active_state, "inactive") ||
@@
-2157,8
+2167,8
@@
static void print_status_info(UnitStatusInfo *i) {
good = is_clean_exit(p->code, p->status);
if (!good) {
good = is_clean_exit(p->code, p->status);
if (!good) {
- on = ansi_highlight(true);
- off = ansi_highlight(false);
+ on = ansi_highlight
_red
(true);
+ off = ansi_highlight
_red
(false);
} else
on = off = "";
} else
on = off = "";
@@
-2199,7
+2209,7
@@
static void print_status_info(UnitStatusInfo *i) {
if (i->running) {
char *t = NULL;
if (i->running) {
char *t = NULL;
- get_process_
name
(i->main_pid, &t);
+ get_process_
comm
(i->main_pid, &t);
if (t) {
printf(" (%s)", t);
free(t);
if (t) {
printf(" (%s)", t);
free(t);
@@
-2233,7
+2243,7
@@
static void print_status_info(UnitStatusInfo *i) {
printf(" Control: %u", (unsigned) i->control_pid);
printf(" Control: %u", (unsigned) i->control_pid);
- get_process_
name
(i->control_pid, &t);
+ get_process_
comm
(i->control_pid, &t);
if (t) {
printf(" (%s)", t);
free(t);
if (t) {
printf(" (%s)", t);
free(t);
@@
-2257,14
+2267,19
@@
static void print_status_info(UnitStatusInfo *i) {
else
c = 0;
else
c = 0;
- show_cgroup_by_path(i->default_control_group, "\t\t ", c);
+ show_cgroup_by_path(i->default_control_group, "\t\t ", c
, false
);
}
}
}
}
+ if (i->id && arg_transport != TRANSPORT_SSH) {
+ printf("\n");
+ show_journal_by_unit(i->id, arg_output, NULL, 0, i->inactive_exit_timestamp_monotonic, arg_lines, arg_all, arg_follow);
+ }
+
if (i->need_daemon_reload)
printf("\n%sWarning:%s Unit file changed on disk, 'systemctl %s daemon-reload' recommended.\n",
if (i->need_daemon_reload)
printf("\n%sWarning:%s Unit file changed on disk, 'systemctl %s daemon-reload' recommended.\n",
- ansi_highlight(true),
- ansi_highlight(false),
+ ansi_highlight
_red
(true),
+ ansi_highlight
_red
(false),
arg_scope == UNIT_FILE_SYSTEM ? "--system" : "--user");
}
arg_scope == UNIT_FILE_SYSTEM ? "--system" : "--user");
}
@@
-2314,6
+2329,8
@@
static int status_property(const char *name, DBusMessageIter *iter, UnitStatusIn
i->following = s;
else if (streq(name, "UnitFileState"))
i->unit_file_state = s;
i->following = s;
else if (streq(name, "UnitFileState"))
i->unit_file_state = s;
+ else if (streq(name, "Result"))
+ i->result = s;
}
break;
}
break;
@@
-2385,6
+2402,8
@@
static int status_property(const char *name, DBusMessageIter *iter, UnitStatusIn
i->inactive_enter_timestamp = (usec_t) u;
else if (streq(name, "InactiveExitTimestamp"))
i->inactive_exit_timestamp = (usec_t) u;
i->inactive_enter_timestamp = (usec_t) u;
else if (streq(name, "InactiveExitTimestamp"))
i->inactive_exit_timestamp = (usec_t) u;
+ else if (streq(name, "InactiveExitTimestampMonotonic"))
+ i->inactive_exit_timestamp_monotonic = (usec_t) u;
else if (streq(name, "ActiveExitTimestamp"))
i->active_exit_timestamp = (usec_t) u;
else if (streq(name, "ConditionTimestamp"))
else if (streq(name, "ActiveExitTimestamp"))
i->active_exit_timestamp = (usec_t) u;
else if (streq(name, "ConditionTimestamp"))
@@
-3675,11
+3694,13
@@
static int enable_unit(DBusConnection *bus, char **args) {
goto finish;
}
goto finish;
}
- for (i = 0; i < n_changes; i++) {
- if (changes[i].type == UNIT_FILE_SYMLINK)
- log_info("ln -s '%s' '%s'", changes[i].source, changes[i].path);
- else
- log_info("rm '%s'", changes[i].path);
+ if (!arg_quiet) {
+ for (i = 0; i < n_changes; i++) {
+ if (changes[i].type == UNIT_FILE_SYMLINK)
+ log_info("ln -s '%s' '%s'", changes[i].source, changes[i].path);
+ else
+ log_info("rm '%s'", changes[i].path);
+ }
}
} else {
}
} else {
@@
-3795,10
+3816,12
@@
static int enable_unit(DBusConnection *bus, char **args) {
goto finish;
}
goto finish;
}
- if (streq(type, "symlink"))
- log_info("ln -s '%s' '%s'", source, path);
- else
- log_info("rm '%s'", path);
+ if (!arg_quiet) {
+ if (streq(type, "symlink"))
+ log_info("ln -s '%s' '%s'", source, path);
+ else
+ log_info("rm '%s'", path);
+ }
dbus_message_iter_next(&sub);
}
dbus_message_iter_next(&sub);
}
@@
-3963,7
+3986,11
@@
static int systemctl_help(void) {
" -f --force When enabling unit files, override existing symlinks\n"
" When shutting down, execute action immediately\n"
" --root=PATH Enable unit files in the specified root directory\n"
" -f --force When enabling unit files, override existing symlinks\n"
" When shutting down, execute action immediately\n"
" --root=PATH Enable unit files in the specified root directory\n"
- " --runtime Enable unit files only temporarily until next reboot\n\n"
+ " --runtime Enable unit files only temporarily until next reboot\n"
+ " -n --lines=INTEGER Journal entries to show\n"
+ " --follow Follow journal\n"
+ " -o --output=STRING Change journal output mode (short, short-monotonic,\n"
+ " verbose, export, json, cat)\n\n"
"Unit Commands:\n"
" list-units List loaded units\n"
" start [NAME...] Start (activate) one or more units\n"
"Unit Commands:\n"
" list-units List loaded units\n"
" start [NAME...] Start (activate) one or more units\n"
@@
-4114,7
+4141,8
@@
static int systemctl_parse_argv(int argc, char *argv[]) {
ARG_KILL_WHO,
ARG_NO_ASK_PASSWORD,
ARG_FAILED,
ARG_KILL_WHO,
ARG_NO_ASK_PASSWORD,
ARG_FAILED,
- ARG_RUNTIME
+ ARG_RUNTIME,
+ ARG_FOLLOW
};
static const struct option options[] = {
};
static const struct option options[] = {
@@
-4147,6
+4175,9
@@
static int systemctl_parse_argv(int argc, char *argv[]) {
{ "host", required_argument, NULL, 'H' },
{ "privileged",no_argument, NULL, 'P' },
{ "runtime", no_argument, NULL, ARG_RUNTIME },
{ "host", required_argument, NULL, 'H' },
{ "privileged",no_argument, NULL, 'P' },
{ "runtime", no_argument, NULL, ARG_RUNTIME },
+ { "lines", required_argument, NULL, 'n' },
+ { "follow", no_argument, NULL, ARG_FOLLOW },
+ { "output", required_argument, NULL, 'o' },
{ NULL, 0, NULL, 0 }
};
{ NULL, 0, NULL, 0 }
};
@@
-4158,7
+4189,7
@@
static int systemctl_parse_argv(int argc, char *argv[]) {
/* Only when running as systemctl we ask for passwords */
arg_ask_password = true;
/* Only when running as systemctl we ask for passwords */
arg_ask_password = true;
- while ((c = getopt_long(argc, argv, "ht:p:aqfs:H:P", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "ht:p:aqfs:H:P
n:o:
", options, NULL)) >= 0) {
switch (c) {
switch (c) {
@@
-4296,6
+4327,25
@@
static int systemctl_parse_argv(int argc, char *argv[]) {
arg_runtime = true;
break;
arg_runtime = true;
break;
+ case 'n':
+ if (safe_atou(optarg, &arg_lines) < 0) {
+ log_error("Failed to parse lines '%s'", optarg);
+ return -EINVAL;
+ }
+ break;
+
+ case ARG_FOLLOW:
+ arg_follow = true;
+ break;
+
+ case 'o':
+ arg_output = output_mode_from_string(optarg);
+ if (arg_output < 0) {
+ log_error("Unknown output '%s'.", optarg);
+ return -EINVAL;
+ }
+ break;
+
case '?':
return -EINVAL;
case '?':
return -EINVAL;