diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index 3179fba3ba9..6fb4134ae93 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -472,6 +472,10 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne
assert(s);
assert(percent <= 100);
+
+ if (new_length == (size_t) -1)
+ return strndup(s, old_length);
+
assert(new_length >= 3);
/* if no multibyte characters use ascii_ellipsize_mem for speed */
@@ -539,6 +543,10 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne
}
char *ellipsize(const char *s, size_t length, unsigned percent) {
+
+ if (length == (size_t) -1)
+ return strdup(s);
+
return ellipsize_mem(s, strlen(s), length, percent);
}
diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c
index b38d6c7267a..d41ccf30feb 100644
--- a/src/busctl/busctl.c
+++ b/src/busctl/busctl.c
@@ -2010,7 +2010,7 @@ static int busctl_main(sd_bus *bus, int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
- sd_bus *bus = NULL;
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
log_parse_environment();
@@ -2100,7 +2100,6 @@ int main(int argc, char *argv[]) {
r = busctl_main(bus, argc, argv);
finish:
- sd_bus_flush_close_unref(bus);
pager_close();
strv_free(arg_matches);
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index d9b060972d3..2fef7d8c09d 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -594,7 +594,7 @@ static int localectl_main(sd_bus *bus, int argc, char *argv[]) {
}
int main(int argc, char*argv[]) {
- sd_bus *bus = NULL;
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
setlocale(LC_ALL, "");
@@ -614,7 +614,6 @@ int main(int argc, char*argv[]) {
r = localectl_main(bus, argc, argv);
finish:
- sd_bus_flush_close_unref(bus);
pager_close();
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 905003ea872..49624ba7d06 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -37,6 +37,7 @@
#include "pager.h"
#include "parse-util.h"
#include "process-util.h"
+#include "sigbus.h"
#include "signal-util.h"
#include "spawn-polkit-agent.h"
#include "strv.h"
@@ -65,8 +66,7 @@ static OutputFlags get_output_flags(void) {
return
arg_all * OUTPUT_SHOW_ALL |
- arg_full * OUTPUT_FULL_WIDTH |
- (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
+ (arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
colors_enabled() * OUTPUT_COLOR;
}
@@ -714,7 +714,7 @@ static int print_seat_status_info(sd_bus *bus, const char *path, bool *new_line)
printf("\t Devices:\n");
- show_sysfs(i.id, "\t\t ", c);
+ show_sysfs(i.id, "\t\t ", c, get_output_flags());
}
return 0;
@@ -1583,12 +1583,13 @@ static int loginctl_main(int argc, char *argv[], sd_bus *bus) {
}
int main(int argc, char *argv[]) {
- sd_bus *bus = NULL;
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
setlocale(LC_ALL, "");
log_parse_environment();
log_open();
+ sigbus_install();
r = parse_argv(argc, argv);
if (r <= 0)
@@ -1605,8 +1606,6 @@ int main(int argc, char *argv[]) {
r = loginctl_main(argc, argv, bus);
finish:
- sd_bus_flush_close_unref(bus);
-
pager_close();
polkit_agent_close();
diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c
index 29785e2f11d..bf6feaa0d9b 100644
--- a/src/login/sysfs-show.c
+++ b/src/login/sysfs-show.c
@@ -37,13 +37,23 @@ static int show_sysfs_one(
struct udev_list_entry **item,
const char *sub,
const char *prefix,
- unsigned n_columns) {
+ unsigned n_columns,
+ OutputFlags flags) {
+
+ size_t max_width;
assert(udev);
assert(seat);
assert(item);
assert(prefix);
+ if (flags & OUTPUT_FULL_WIDTH)
+ max_width = (size_t) -1;
+ else if (n_columns < 10)
+ max_width = 10;
+ else
+ max_width = n_columns;
+
while (*item) {
_cleanup_udev_device_unref_ struct udev_device *d = NULL;
struct udev_list_entry *next, *lookahead;
@@ -106,7 +116,7 @@ static int show_sysfs_one(
lookahead = udev_list_entry_get_next(lookahead);
}
- k = ellipsize(sysfs, n_columns, 20);
+ k = ellipsize(sysfs, max_width, 20);
if (!k)
return -ENOMEM;
@@ -120,7 +130,7 @@ static int show_sysfs_one(
return -ENOMEM;
free(k);
- k = ellipsize(l, n_columns, 70);
+ k = ellipsize(l, max_width, 70);
if (!k)
return -ENOMEM;
@@ -134,14 +144,16 @@ static int show_sysfs_one(
if (!p)
return -ENOMEM;
- show_sysfs_one(udev, seat, item, sysfs, p, n_columns - 2);
+ show_sysfs_one(udev, seat, item, sysfs, p,
+ n_columns == (unsigned) -1 || n_columns < 2 ? n_columns : n_columns - 2,
+ flags);
}
}
return 0;
}
-int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) {
+int show_sysfs(const char *seat, const char *prefix, unsigned n_columns, OutputFlags flags) {
_cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL;
_cleanup_udev_unref_ struct udev *udev = NULL;
struct udev_list_entry *first = NULL;
@@ -150,8 +162,7 @@ int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) {
if (n_columns <= 0)
n_columns = columns();
- if (!prefix)
- prefix = "";
+ prefix = strempty(prefix);
if (isempty(seat))
seat = "seat0";
@@ -181,7 +192,7 @@ int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) {
first = udev_enumerate_get_list_entry(e);
if (first)
- show_sysfs_one(udev, seat, &first, "/", prefix, n_columns);
+ show_sysfs_one(udev, seat, &first, "/", prefix, n_columns, flags);
else
printf("%s%s%s\n", prefix, special_glyph(TREE_RIGHT), "(none)");
diff --git a/src/login/sysfs-show.h b/src/login/sysfs-show.h
index 3e94bc3ed55..e19af4cd928 100644
--- a/src/login/sysfs-show.h
+++ b/src/login/sysfs-show.h
@@ -19,4 +19,8 @@
along with systemd; If not, see .
***/
-int show_sysfs(const char *seat, const char *prefix, unsigned columns);
+#include
+
+#include "output-mode.h"
+
+int show_sysfs(const char *seat, const char *prefix, unsigned columns, OutputFlags flags);
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index a6542d5a16f..968be322dd3 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -52,15 +52,16 @@
#include "path-util.h"
#include "process-util.h"
#include "ptyfwd.h"
+#include "sigbus.h"
#include "signal-util.h"
#include "spawn-polkit-agent.h"
+#include "stdio-util.h"
#include "strv.h"
#include "terminal-util.h"
#include "unit-name.h"
#include "util.h"
#include "verbs.h"
#include "web-util.h"
-#include "stdio-util.h"
#define ALL_IP_ADDRESSES -1
@@ -92,8 +93,7 @@ static int print_addresses(sd_bus *bus, const char *name, int, const char *pr1,
static OutputFlags get_output_flags(void) {
return
arg_all * OUTPUT_SHOW_ALL |
- arg_full * OUTPUT_FULL_WIDTH |
- (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
+ (arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
colors_enabled() * OUTPUT_COLOR |
!arg_quiet * OUTPUT_WARN_CUTOFF;
}
@@ -3045,12 +3045,13 @@ static int machinectl_main(int argc, char *argv[], sd_bus *bus) {
}
int main(int argc, char*argv[]) {
- sd_bus *bus = NULL;
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
setlocale(LC_ALL, "");
log_parse_environment();
log_open();
+ sigbus_install();
r = parse_argv(argc, argv);
if (r <= 0)
@@ -3067,7 +3068,6 @@ int main(int argc, char*argv[]) {
r = machinectl_main(argc, argv, bus);
finish:
- sd_bus_flush_close_unref(bus);
pager_close();
polkit_agent_close();
diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c
index 599abf093f7..79dab5037a2 100644
--- a/src/mount/mount-tool.c
+++ b/src/mount/mount-tool.c
@@ -1619,8 +1619,6 @@ int main(int argc, char* argv[]) {
}
finish:
- bus = sd_bus_flush_close_unref(bus);
-
pager_close();
free(arg_mount_what);
diff --git a/src/shared/pager.c b/src/shared/pager.c
index 0661ff0bb9b..da49f9a22d4 100644
--- a/src/shared/pager.c
+++ b/src/shared/pager.c
@@ -80,9 +80,10 @@ int pager_open(bool no_pager, bool jump_to_end) {
if (pager && STR_IN_SET(pager, "", "cat"))
return 0;
- /* Determine and cache number of columns before we spawn the
- * pager so that we get the value from the actual tty */
+ /* Determine and cache number of columns/lines before we spawn the pager so that we get the value from the
+ * actual tty */
(void) columns();
+ (void) lines();
if (pipe2(fd, O_CLOEXEC) < 0)
return log_error_errno(errno, "Failed to create pager pipe: %m");
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 7730c06ba24..670bff999c9 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -280,8 +280,7 @@ static void polkit_agent_open_maybe(void) {
static OutputFlags get_output_flags(void) {
return
arg_all * OUTPUT_SHOW_ALL |
- arg_full * OUTPUT_FULL_WIDTH |
- (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
+ (arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
colors_enabled() * OUTPUT_COLOR |
!arg_quiet * OUTPUT_WARN_CUTOFF;
}
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 6fe9422f943..5121dd153a4 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -472,7 +472,7 @@ static int timedatectl_main(sd_bus *bus, int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
- sd_bus *bus = NULL;
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
setlocale(LC_ALL, "");
@@ -492,7 +492,6 @@ int main(int argc, char *argv[]) {
r = timedatectl_main(bus, argc, argv);
finish:
- sd_bus_flush_close_unref(bus);
pager_close();
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;