From f692c4a6cf41b95b083df17c38ba883eb67d1710 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 8 Jul 2023 16:21:37 +0100 Subject: [PATCH 1/4] Print ssize_t as %zd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On some architectures (x32) ssize_t is int, not long int. ../src/basic/confidential-virt.c: In function ‘msr’: ../src/basic/confidential-virt.c:133:27: error: format ‘%ld’ expects argument of type ‘long int’, but argument 7 has type ‘ssize_t’ {aka ‘int’} [-Werror=format=] 133 | log_debug("Short read %ld bytes from MSR device %s (index %" PRIu64 "), ignoring", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 134 | rv, | ~~ | | | ssize_t {aka int} ../src/basic/log.h:214:86: note: in definition of macro ‘log_full_errno_zerook’ 214 | ? log_internal(_level, _e, PROJECT_FILE, __LINE__, __func__, __VA_ARGS__) \ | ^~~~~~~~~~~ ../src/basic/log.h:242:28: note: in expansion of macro ‘log_full’ 242 | #define log_debug(...) log_full(LOG_DEBUG, __VA_ARGS__) | ^~~~~~~~ ../src/basic/confidential-virt.c:133:17: note: in expansion of macro ‘log_debug’ 133 | log_debug("Short read %ld bytes from MSR device %s (index %" PRIu64 "), ignoring", | ^~~~~~~~~ ../src/basic/confidential-virt.c:133:41: note: format string is defined here 133 | log_debug("Short read %ld bytes from MSR device %s (index %" PRIu64 "), ignoring", | ~~^ | | | long int | %d --- src/basic/confidential-virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/confidential-virt.c b/src/basic/confidential-virt.c index 3d4e9eac33..e00576a713 100644 --- a/src/basic/confidential-virt.c +++ b/src/basic/confidential-virt.c @@ -130,7 +130,7 @@ static uint64_t msr(uint64_t index) { index); return 0; } else if (rv != sizeof(ret)) { - log_debug("Short read %ld bytes from MSR device %s (index %" PRIu64 "), ignoring", + log_debug("Short read %zd bytes from MSR device %s (index %" PRIu64 "), ignoring", rv, MSR_DEVICE, index); From 5bf36ce52452052b4d910c122af562c2236ce89d Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 8 Jul 2023 16:35:00 +0100 Subject: [PATCH 2/4] Cast st_dev to dev_t when printing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit st_dev is not the same as dev_t, and on O32 architectures like mipsel it's an unsigned long, but dev_t is still unsigned long long, so they don't match and compilation fails: ../src/journal/cat.c: In function ‘run’: ../src/basic/format-util.h:46:19: error: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘long unsigned int’ [-Werror=format=] 46 | # define DEV_FMT "%" PRIu64 | ^~~ ../src/journal/cat.c:168:34: note: in expansion of macro ‘DEV_FMT’ 168 | if (asprintf(&s, DEV_FMT ":" INO_FMT, st.st_dev, st.st_ino) < 0) | ^~~~~~~ In file included from ../src/systemd/sd-journal.h:20, from ../src/journal/cat.c:11: /usr/include/inttypes.h:105:41: note: format string is defined here 105 | # define PRIu64 __PRI64_PREFIX "u" --- src/journal/cat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/journal/cat.c b/src/journal/cat.c index d3f7785ad3..609ddbaf6b 100644 --- a/src/journal/cat.c +++ b/src/journal/cat.c @@ -165,7 +165,7 @@ static int run(int argc, char *argv[]) { "Failed to fstat(%s): %m", FORMAT_PROC_FD_PATH(STDERR_FILENO)); - if (asprintf(&s, DEV_FMT ":" INO_FMT, st.st_dev, st.st_ino) < 0) + if (asprintf(&s, DEV_FMT ":" INO_FMT, (dev_t)st.st_dev, st.st_ino) < 0) return log_oom(); if (setenv("JOURNAL_STREAM", s, /* overwrite = */ true) < 0) From 840ac5cd1abbcee0c8def620bdabfb66d0707ebf Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 8 Jul 2023 16:43:28 +0100 Subject: [PATCH 3/4] process-util: use clone2 on ia64 glibc does not provide clone() on ia64, only clone2. But only as a symbol in the shared library, there's no prototype in the gblic headers, so we have to define it, copied from the manpage. --- src/basic/missing_syscall.h | 14 ++++++++++++++ src/basic/process-util.c | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index 062decaff6..ddee457f44 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -654,3 +654,17 @@ static inline ssize_t missing_getdents64(int fd, void *buffer, size_t length) { # define getdents64 missing_getdents64 #endif + +/* ======================================================================= */ + +/* glibc does not provide clone() on ia64, only clone2(). Not only that, but it also doesn't provide a + * prototype, only the symbol in the shared library (it provides a prototype for clone(), but not the + * symbol in the shared library). */ +#if defined(__ia64__) +int __clone2(int (*fn)(void *), void *stack_base, size_t stack_size, int flags, void *arg); +#define HAVE_CLONE 0 +#else +/* We know that everywhere else clone() is available, so we don't bother with a meson check (that takes time + * at build time) and just define it. Once the kernel drops ia64 support, we can drop this too. */ +#define HAVE_CLONE 1 +#endif diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 6cf882866f..7182e15b61 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -1177,7 +1177,11 @@ pid_t clone_with_nested_stack(int (*fn)(void *), int flags, void *userdata) { mystack = (uint8_t*) mystack + ps; /* move pointer one page ahead since stacks usually grow backwards */ mystack = (void*) ALIGN_TO((uintptr_t) mystack, ps); /* align to page size (moving things further ahead) */ +#if HAVE_CLONE pid = clone(fn, mystack, flags, userdata); +#else + pid = __clone2(fn, mystack, ps, flags, userdata); +#endif if (pid < 0) return -errno; From 03b70f060fa520d0ed7adc3099b9e1b3acafa075 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sun, 9 Jul 2023 13:03:44 +0100 Subject: [PATCH 4/4] sleep: fix unused variable warning log_level_ignored is used only inside the ifdef, so declare it there too --- src/sleep/sleep.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index dd860d2858..30e53f3a36 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -53,8 +53,7 @@ static SleepOperation arg_operation = _SLEEP_OPERATION_INVALID; static int write_efi_hibernate_location(const HibernateLocation *hibernate_location, bool required) { - int log_level = required ? LOG_ERR : LOG_DEBUG, - log_level_ignore = required ? LOG_WARNING : LOG_DEBUG; + int log_level = required ? LOG_ERR : LOG_DEBUG; #if ENABLE_EFI _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; @@ -64,7 +63,7 @@ static int write_efi_hibernate_location(const HibernateLocation *hibernate_locat const char *uuid_str; sd_id128_t uuid; struct utsname uts = {}; - int r; + int r, log_level_ignore = required ? LOG_WARNING : LOG_DEBUG; assert(hibernate_location); assert(hibernate_location->swap);