From 82bfcc37e2677394ccb075cdb64e5873ec5e906d Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Wed, 25 Mar 2026 16:45:27 +0100 Subject: [PATCH 1/4] cleanup-util: include assert-fundamental.h instead of -util The split was initially done to reduce transitive includes, and for assert() only the former is needed. --- src/basic/cleanup-util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/cleanup-util.h b/src/basic/cleanup-util.h index 068696d977..041c37530a 100644 --- a/src/basic/cleanup-util.h +++ b/src/basic/cleanup-util.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "assert-util.h" +#include "assert-fundamental.h" #include "cleanup-fundamental.h" /* IWYU pragma: export */ typedef void (*free_func_t)(void *p); From 1060f82611be352bf77ec1eb82ec8e536849174a Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Wed, 25 Mar 2026 15:39:26 +0100 Subject: [PATCH 2/4] creds: use parse_tristate_argument_with_auto() where appropriate --- src/creds/creds.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/creds/creds.c b/src/creds/creds.c index 5f60f781f6..9e1b2cfbcc 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -940,15 +940,9 @@ static int parse_argv(int argc, char *argv[]) { break; case ARG_NEWLINE: - if (isempty(optarg) || streq(optarg, "auto")) - arg_newline = -1; - else { - r = parse_boolean_argument("--newline=", optarg, NULL); - if (r < 0) - return r; - - arg_newline = r; - } + r = parse_tristate_argument_with_auto("--newline=", optarg, &arg_newline); + if (r < 0) + return r; break; case 'p': From 64d1c102ad3af9ce5f640b2fbffb8113697fd0e3 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Wed, 25 Mar 2026 16:00:14 +0100 Subject: [PATCH 3/4] creds: if newline is explicitly requested, skip tty check Before this commit, the > 0 state of arg_newline tristate is simply ignored. Yes, this is a minor compat break, but I'd argue the previous behavior was not useful as "yes" is treated the same as "auto". An issue also reported that it was quite surprising. Fixes #41348 --- src/creds/creds.c | 12 ++++++------ test/units/TEST-54-CREDS.sh | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/creds/creds.c b/src/creds/creds.c index 9e1b2cfbcc..3103686a9f 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -398,8 +398,6 @@ static int transcode( } static int print_newline(FILE *f, const char *data, size_t l) { - int fd; - assert(f); assert(data || l == 0); @@ -411,10 +409,12 @@ static int print_newline(FILE *f, const char *data, size_t l) { if (l > 0 && data[l-1] == '\n') return 0; - /* Don't bother unless this is a tty */ - fd = fileno(f); - if (fd >= 0 && !isatty_safe(fd)) - return 0; + /* If not explicitly requested, don't bother if the output is not a tty */ + if (arg_newline < 0) { + int fd = fileno(f); + if (fd >= 0 && !isatty_safe(fd)) + return 0; + } if (fputc('\n', f) != '\n') return log_error_errno(errno, "Failed to write trailing newline: %m"); diff --git a/test/units/TEST-54-CREDS.sh b/test/units/TEST-54-CREDS.sh index 0eaf8a2dfb..523046ec76 100755 --- a/test/units/TEST-54-CREDS.sh +++ b/test/units/TEST-54-CREDS.sh @@ -114,10 +114,9 @@ run_with_cred_compare "mycred:" "" cat mycred run_with_cred_compare "mycred:\n" "\n" cat mycred run_with_cred_compare "mycred:foo" "foo" cat mycred run_with_cred_compare "mycred:foo" "foofoofoo" cat mycred mycred mycred -# Note: --newline= does nothing when stdout is not a tty, which is the case here -run_with_cred_compare "mycred:foo" "foo" --newline=yes cat mycred -run_with_cred_compare "mycred:foo" "foo" --newline=no cat mycred run_with_cred_compare "mycred:foo" "foo" --newline=auto cat mycred +run_with_cred_compare "mycred:foo" "foo" --newline=no cat mycred +run_with_cred_compare "mycred:foo" "foo\n" --newline=yes cat mycred run_with_cred_compare "mycred:foo" "foo" --transcode=no cat mycred run_with_cred_compare "mycred:foo" "foo" --transcode=0 cat mycred run_with_cred_compare "mycred:foo" "foo" --transcode=false cat mycred From 734af2908a803c17ad587da7db334fc225f18dde Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Wed, 25 Mar 2026 16:03:07 +0100 Subject: [PATCH 4/4] creds: minor tweak for fputc() error handling Let's do not assume errno is set for return values other than EOF, following what we do in fileio.c. --- src/creds/creds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/creds/creds.c b/src/creds/creds.c index 3103686a9f..3b1cc8e86b 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -416,7 +416,7 @@ static int print_newline(FILE *f, const char *data, size_t l) { return 0; } - if (fputc('\n', f) != '\n') + if (fputc('\n', f) == EOF) return log_error_errno(errno, "Failed to write trailing newline: %m"); return 1;