loginctl: rework sysfs tree dump, to honour --full and friends

Let's hook up the sysfs tree output with the output flags logic,
already used when dumping log lines or process trees. This way we get
very similar output handling for line breaking/ellipsation in all three
outputs of structured data.

Fixes: #7095
This commit is contained in:
Lennart Poettering 2017-11-10 21:44:29 +01:00
parent ddbc931986
commit 3850319be5
3 changed files with 25 additions and 10 deletions

View file

@ -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;

View file

@ -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)");

View file

@ -19,4 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
int show_sysfs(const char *seat, const char *prefix, unsigned columns);
#include <sys/types.h>
#include "output-mode.h"
int show_sysfs(const char *seat, const char *prefix, unsigned columns, OutputFlags flags);