summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-08-03 19:38:13 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-08-11 18:10:34 -0400
commit94e0bd7db1d7ca8ab7f738cdab1d014241f5b225 (patch)
tree0f670f29e0717d887c4abbbfbab730cfdedefcd8 /src
parentf535088ef72a92533f2c4270d06289c89737fa2a (diff)
systemctl: show hint about --full when lines don't fit
Diffstat (limited to 'src')
-rw-r--r--src/journal/journal-gatewayd.c2
-rw-r--r--src/journal/journalctl.c3
-rw-r--r--src/shared/logs-show.c37
-rw-r--r--src/shared/logs-show.h6
-rw-r--r--src/systemctl/systemctl.c97
5 files changed, 89 insertions, 56 deletions
diff --git a/src/journal/journal-gatewayd.c b/src/journal/journal-gatewayd.c
index 10224a1ac1..06a236df6b 100644
--- a/src/journal/journal-gatewayd.c
+++ b/src/journal/journal-gatewayd.c
@@ -248,7 +248,7 @@ static ssize_t request_reader_entries(
}
}
- r = output_journal(m->tmp, m->journal, m->mode, 0, OUTPUT_FULL_WIDTH);
+ r = output_journal(m->tmp, m->journal, m->mode, 0, OUTPUT_FULL_WIDTH, NULL);
if (r < 0) {
log_error("Failed to serialize item: %s", strerror(-r));
return MHD_CONTENT_READER_END_WITH_ERROR;
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index feea6bf19e..5cf9390249 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1305,6 +1305,7 @@ int main(int argc, char *argv[]) {
sd_id128_t previous_boot_id;
bool previous_boot_id_valid = false, first_line = true;
int n_shown = 0;
+ bool ellipsized = false;
setlocale(LC_ALL, "");
log_parse_environment();
@@ -1624,7 +1625,7 @@ int main(int argc, char *argv[]) {
on_tty() * OUTPUT_COLOR |
arg_catalog * OUTPUT_CATALOG;
- r = output_journal(stdout, j, arg_output, 0, flags);
+ r = output_journal(stdout, j, arg_output, 0, flags, &ellipsized);
need_seek = true;
if (r == -EADDRNOTAVAIL)
break;
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index bd7363aa82..51cd7d51c5 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -101,10 +101,11 @@ static bool shall_print(const char *p, size_t l, OutputFlags flags) {
return true;
}
-static void print_multiline(FILE *f, unsigned prefix, unsigned n_columns, OutputMode flags, int priority, const char* message, size_t message_len) {
+static bool print_multiline(FILE *f, unsigned prefix, unsigned n_columns, OutputMode flags, int priority, const char* message, size_t message_len) {
const char *color_on = "", *color_off = "";
const char *pos, *end;
bool continuation = false;
+ bool ellipsized = false;
if (flags & OUTPUT_COLOR) {
if (priority <= LOG_ERR) {
@@ -130,17 +131,22 @@ static void print_multiline(FILE *f, unsigned prefix, unsigned n_columns, Output
else if (prefix < n_columns && n_columns - prefix >= 3) {
_cleanup_free_ char *e;
+ ellipsized = true;
e = ellipsize_mem(pos, len, n_columns - prefix, 90);
if (!e)
fprintf(f, "%s%.*s%s\n", color_on, len, pos, color_off);
else
fprintf(f, "%s%s%s\n", color_on, e, color_off);
- } else
+ } else {
+ ellipsized = true;
fputs("...\n", f);
+ }
continuation = true;
}
+
+ return ellipsized;
}
static int output_short(
@@ -157,6 +163,7 @@ static int output_short(
_cleanup_free_ char *hostname = NULL, *identifier = NULL, *comm = NULL, *pid = NULL, *fake_pid = NULL, *message = NULL, *realtime = NULL, *monotonic = NULL, *priority = NULL;
size_t hostname_len = 0, identifier_len = 0, comm_len = 0, pid_len = 0, fake_pid_len = 0, message_len = 0, realtime_len = 0, monotonic_len = 0, priority_len = 0;
int p = LOG_INFO;
+ bool ellipsized = false;
assert(f);
assert(j);
@@ -314,13 +321,14 @@ static int output_short(
fprintf(f, ": [%s blob data]\n", format_bytes(bytes, sizeof(bytes), message_len));
} else {
fputs(": ", f);
- print_multiline(f, n + 2, n_columns, flags, p, message, message_len);
+ ellipsized |=
+ print_multiline(f, n + 2, n_columns, flags, p, message, message_len);
}
if (flags & OUTPUT_CATALOG)
print_catalog(f, j);
- return 0;
+ return ellipsized;
}
static int output_verbose(
@@ -817,7 +825,8 @@ int output_journal(
sd_journal *j,
OutputMode mode,
unsigned n_columns,
- OutputFlags flags) {
+ OutputFlags flags,
+ bool *ellipsized) {
int ret;
assert(mode >= 0);
@@ -828,6 +837,10 @@ int output_journal(
ret = output_funcs[mode](f, j, mode, n_columns, flags);
fflush(stdout);
+
+ if (ellipsized && ret > 0)
+ *ellipsized = true;
+
return ret;
}
@@ -837,7 +850,8 @@ static int show_journal(FILE *f,
unsigned n_columns,
usec_t not_before,
unsigned how_many,
- OutputFlags flags) {
+ OutputFlags flags,
+ bool *ellipsized) {
int r;
unsigned line = 0;
@@ -888,7 +902,7 @@ static int show_journal(FILE *f,
line ++;
- r = output_journal(f, j, mode, n_columns, flags);
+ r = output_journal(f, j, mode, n_columns, flags, ellipsized);
if (r < 0)
goto finish;
}
@@ -1037,7 +1051,8 @@ int show_journal_by_unit(
unsigned how_many,
uid_t uid,
OutputFlags flags,
- bool system) {
+ bool system,
+ bool *ellipsized) {
_cleanup_journal_close_ sd_journal*j = NULL;
int r;
@@ -1072,11 +1087,7 @@ int show_journal_by_unit(
log_debug("Journal filter: %s", filter);
}
- r = show_journal(f, j, mode, n_columns, not_before, how_many, flags);
- if (r < 0)
- return r;
-
- return 0;
+ return show_journal(f, j, mode, n_columns, not_before, how_many, flags, ellipsized);
}
static const char *const output_mode_table[_OUTPUT_MODE_MAX] = {
diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h
index c9a9ad3e91..11b3b59b7b 100644
--- a/src/shared/logs-show.h
+++ b/src/shared/logs-show.h
@@ -35,7 +35,8 @@ int output_journal(
sd_journal *j,
OutputMode mode,
unsigned n_columns,
- OutputFlags flags);
+ OutputFlags flags,
+ bool *ellipsized);
int add_match_this_boot(sd_journal *j);
@@ -57,7 +58,8 @@ int show_journal_by_unit(
unsigned how_many,
uid_t uid,
OutputFlags flags,
- bool system);
+ bool system,
+ bool *ellipsized);
void json_escape(
FILE *f,
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 3dd74c2694..a635891bc0 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2503,7 +2503,8 @@ typedef struct UnitStatusInfo {
LIST_HEAD(ExecStatusInfo, exec);
} UnitStatusInfo;
-static void print_status_info(UnitStatusInfo *i) {
+static void print_status_info(UnitStatusInfo *i,
+ bool *ellipsized) {
ExecStatusInfo *p;
const char *on, *off, *ss;
usec_t timestamp;
@@ -2779,7 +2780,8 @@ static void print_status_info(UnitStatusInfo *i) {
arg_lines,
getuid(),
flags,
- arg_scope == UNIT_FILE_SYSTEM);
+ arg_scope == UNIT_FILE_SYSTEM,
+ ellipsized);
}
if (i->need_daemon_reload)
@@ -3345,7 +3347,12 @@ static int print_property(const char *name, DBusMessageIter *iter) {
return 0;
}
-static int show_one(const char *verb, DBusConnection *bus, const char *path, bool show_properties, bool *new_line) {
+static int show_one(const char *verb,
+ DBusConnection *bus,
+ const char *path,
+ bool show_properties,
+ bool *new_line,
+ bool *ellipsized) {
_cleanup_free_ DBusMessage *reply = NULL;
const char *interface = "";
int r;
@@ -3415,7 +3422,7 @@ static int show_one(const char *verb, DBusConnection *bus, const char *path, boo
if (streq(verb, "help"))
show_unit_help(&info);
else
- print_status_info(&info);
+ print_status_info(&info, ellipsized);
}
strv_free(info.documentation);
@@ -3446,7 +3453,11 @@ static int show_one(const char *verb, DBusConnection *bus, const char *path, boo
return r;
}
-static int show_one_by_pid(const char *verb, DBusConnection *bus, uint32_t pid, bool *new_line) {
+static int show_one_by_pid(const char *verb,
+ DBusConnection *bus,
+ uint32_t pid,
+ bool *new_line,
+ bool *ellipsized) {
_cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
const char *path = NULL;
_cleanup_dbus_error_free_ DBusError error;
@@ -3474,11 +3485,15 @@ static int show_one_by_pid(const char *verb, DBusConnection *bus, uint32_t pid,
return -EIO;
}
- r = show_one(verb, bus, path, false, new_line);
+ r = show_one(verb, bus, path, false, new_line, ellipsized);
return r;
}
-static int show_all(const char* verb, DBusConnection *bus, bool show_properties, bool *new_line) {
+static int show_all(const char* verb,
+ DBusConnection *bus,
+ bool show_properties,
+ bool *new_line,
+ bool *ellipsized) {
_cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
_cleanup_free_ struct unit_info *unit_infos = NULL;
unsigned c = 0;
@@ -3503,7 +3518,7 @@ static int show_all(const char* verb, DBusConnection *bus, bool show_properties,
printf("%s -> '%s'\n", u->id, p);
- r = show_one(verb, bus, p, show_properties, new_line);
+ r = show_one(verb, bus, p, show_properties, new_line, ellipsized);
if (r != 0)
return r;
}
@@ -3515,6 +3530,7 @@ static int show(DBusConnection *bus, char **args) {
int r, ret = 0;
bool show_properties, show_status, new_line = false;
char **name;
+ bool ellipsized = false;
assert(bus);
assert(args);
@@ -3528,48 +3544,51 @@ static int show(DBusConnection *bus, char **args) {
/* If no argument is specified inspect the manager itself */
if (show_properties && strv_length(args) <= 1)
- return show_one(args[0], bus, "/org/freedesktop/systemd1", show_properties, &new_line);
+ return show_one(args[0], bus, "/org/freedesktop/systemd1", show_properties, &new_line, &ellipsized);
if (show_status && strv_length(args) <= 1)
- return show_all(args[0], bus, false, &new_line);
-
- STRV_FOREACH(name, args+1) {
- uint32_t id;
+ ret = show_all(args[0], bus, false, &new_line, &ellipsized);
+ else
+ STRV_FOREACH(name, args+1) {
+ uint32_t id;
- if (safe_atou32(*name, &id) < 0) {
- _cleanup_free_ char *p = NULL, *n = NULL;
- /* Interpret as unit name */
+ if (safe_atou32(*name, &id) < 0) {
+ _cleanup_free_ char *p = NULL, *n = NULL;
+ /* Interpret as unit name */
- n = unit_name_mangle(*name);
- if (!n)
- return log_oom();
+ n = unit_name_mangle(*name);
+ if (!n)
+ return log_oom();
- p = unit_dbus_path_from_name(n);
- if (!p)
- return log_oom();
+ p = unit_dbus_path_from_name(n);
+ if (!p)
+ return log_oom();
- r = show_one(args[0], bus, p, show_properties, &new_line);
- if (r != 0)
- ret = r;
+ r = show_one(args[0], bus, p, show_properties, &new_line, &ellipsized);
+ if (r != 0)
+ ret = r;
- } else if (show_properties) {
- _cleanup_free_ char *p = NULL;
+ } else if (show_properties) {
+ _cleanup_free_ char *p = NULL;
- /* Interpret as job id */
- if (asprintf(&p, "/org/freedesktop/systemd1/job/%u", id) < 0)
- return log_oom();
+ /* Interpret as job id */
+ if (asprintf(&p, "/org/freedesktop/systemd1/job/%u", id) < 0)
+ return log_oom();
- r = show_one(args[0], bus, p, show_properties, &new_line);
- if (r != 0)
- ret = r;
+ r = show_one(args[0], bus, p, show_properties, &new_line, &ellipsized);
+ if (r != 0)
+ ret = r;
- } else {
- /* Interpret as PID */
- r = show_one_by_pid(args[0], bus, id, &new_line);
- if (r != 0)
- ret = r;
+ } else {
+ /* Interpret as PID */
+ r = show_one_by_pid(args[0], bus, id, &new_line, &ellipsized);
+ if (r != 0)
+ ret = r;
+ }
}
- }
+
+ if (ellipsized && !arg_quiet)
+ printf("Hint: Some lines were ellipsized, use -l to show in full.\n");
return ret;
}