diff options
author | Anita Zhang <the.anitazha@gmail.com> | 2019-11-05 15:03:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-05 15:03:15 -0800 |
commit | f03378805f23e85f8463913ee92b99d810b61594 (patch) | |
tree | da2f7d131ab7940d24f7981961b5f86f49b5a4ef /src | |
parent | 9087384d392557fdc7cc4a3b07ff3b9b45d11524 (diff) | |
parent | 0db41a8f1f8eda49ce60e7efa23d17a5e24673e3 (diff) | |
download | systemd-f03378805f23e85f8463913ee92b99d810b61594.tar.gz |
Merge pull request #13936 from keszybz/format-table-uninhibited
Output tables at full width if piped
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/signal-util.c | 2 | ||||
-rw-r--r-- | src/shared/format-table.c | 9 | ||||
-rw-r--r-- | src/test/test-format-table.c | 22 |
3 files changed, 23 insertions, 10 deletions
diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c index 21964bb2db..bfb83419c9 100644 --- a/src/basic/signal-util.c +++ b/src/basic/signal-util.c @@ -25,7 +25,7 @@ int reset_all_signal_handlers(void) { /* On Linux the first two RT signals are reserved by * glibc, and sigaction() will return EINVAL for them. */ - if ((sigaction(sig, &sa, NULL) < 0)) + if (sigaction(sig, &sa, NULL) < 0) if (errno != EINVAL && r >= 0) r = -errno; } diff --git a/src/shared/format-table.c b/src/shared/format-table.c index e41cbb1720..4617ae8bad 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -2,6 +2,7 @@ #include <ctype.h> #include <net/if.h> +#include <unistd.h> #include "alloc-util.h" #include "fd-util.h" @@ -1611,10 +1612,12 @@ int table_print(Table *t, FILE *f) { } /* Calculate effective table width */ - if (t->width == (size_t) -1) - table_effective_width = pager_have() ? table_requested_width : MIN(table_requested_width, columns()); - else + if (t->width != (size_t) -1) table_effective_width = t->width; + else if (pager_have() || !isatty(STDOUT_FILENO)) + table_effective_width = table_requested_width; + else + table_effective_width = MIN(table_requested_width, columns()); if (table_maximum_width != (size_t) -1 && table_effective_width > table_maximum_width) table_effective_width = table_maximum_width; diff --git a/src/test/test-format-table.c b/src/test/test-format-table.c index def9cbda2f..96b1d77701 100644 --- a/src/test/test-format-table.c +++ b/src/test/test-format-table.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ +#include <unistd.h> + #include "alloc-util.h" #include "format-table.h" #include "string-util.h" @@ -154,12 +156,20 @@ int main(int argc, char *argv[]) { assert_se(table_format(t, &formatted) >= 0); printf("%s\n", formatted); - assert_se(streq(formatted, - " no a long f… no a long f… a long fi…\n" - " no fäää no fäää fäää \n" - " yes fäää yes fäää fäää \n" - " yes xxx yes xxx xxx \n" - "5min 5min \n")); + if (isatty(STDOUT_FILENO)) + assert_se(streq(formatted, + " no a long f… no a long f… a long fi…\n" + " no fäää no fäää fäää \n" + " yes fäää yes fäää fäää \n" + " yes xxx yes xxx xxx \n" + "5min 5min \n")); + else + assert_se(streq(formatted, + " no a long field no a long field a long field\n" + " no fäää no fäää fäää \n" + " yes fäää yes fäää fäää \n" + " yes xxx yes xxx xxx \n" + "5min 5min \n")); test_issue_9549(); |