From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=X1MMAWiy; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id D87A15A0265 for ; Mon, 04 May 2026 11:49:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777888151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=SkMXZwcn5sBi0bZnSLF+PXVCrDmgEkD73uHfDQVJ0NE=; b=X1MMAWiyXCb2nHnGog4dMLhNjenXsq2pkXNiLvycxsIIJy8yEomZQgibs/IwDVRowvMfn4 iRf+XmKAbhRUBllIXw0k+MToV+9FcCMy27+Wfva1Y40Nw7sbJ65RoAOAQz3/fv8/BoLZas BfFr2A5GQ1ULQ/GA3kp09cJ6zpzURZ8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-483-oHyUn7eyMUiuiP2NgqmueA-1; Mon, 04 May 2026 05:49:09 -0400 X-MC-Unique: oHyUn7eyMUiuiP2NgqmueA-1 X-Mimecast-MFC-AGG-ID: oHyUn7eyMUiuiP2NgqmueA_1777888148 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-488dcaf2f2fso28670805e9.0 for ; Mon, 04 May 2026 02:49:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777888148; x=1778492948; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SkMXZwcn5sBi0bZnSLF+PXVCrDmgEkD73uHfDQVJ0NE=; b=Xj3XLfJ4qwJelsN+kGnyZQ86vTN6XqGcUHGpBVE6PIGbT4U7gDgW37ib5C4Gb2AaAy MUPL7n3nhZFe+Rj1C6nANz6vEJrnsHqnZiyXkAS2astLh9mC792U8S/me/Wow/btM24+ XIOl7i0Jah3ZecOKVFvu3sUhyQQxhg3p8Hv6zCozyq0sDd2JW/L3ziSRjXKGXZMgfO+9 7ezoxi0VDu9iuGkRevPyUarpnDDo1SWAMTGj7na51XAHgJv+8rYnEwgdif3tt4PtlK7T BBiiq+z/T3+PEz+ECdEzo5qMGX5kJaFqg3OfEDrcyPeLCnCPLatLpoKnJyW7wVuevHVW 4niQ== X-Forwarded-Encrypted: i=1; AFNElJ8O8gCrwVYJTCCb0XLAp/Uyzv3Bz6iG8eM0eMAxXrirEDWDDC1aBdglIdFv8ivgkCZagx57H3OY5CE=@passt.top X-Gm-Message-State: AOJu0YwgEl/+eNjMgeC55LPM6ys3TEb9zxN5bG6NCa0thWlSclGLaQnZ W52dWbwCkgePiWkH6bdzes97cL+vauN+N/pCVynGF/1ReT3rN1sexYhKp/O7sMFtmMQo8DW9LfB w2t78Md43pnuy612y7bdZlbeYM3nuSZMi6dWt2FN3QiozI5ZTMrtHvw== X-Gm-Gg: AeBDiesw9Hb0KQSw622LsJ48uEYzPi+CvbtQUDglRrvLIkDFTwC4v3in10N3L4RyLF0 R8FfMPZT4SjaR9fyO4sJc3OlnZkTzKLDkRripvehnZ/32YQzgMN/twPiLZIC2KPcoYfa5lk+aPi TpSA/6Rr5KSt7M2HjLCx/gYomOgIDrBYWpF3g1MgpOweLG0uXmnjkOJXZmtDMELRGKYN3O2eE4k UpfXXN6hFBFa2qvADvTzMyqhnRpzp1By7Iu5Pila94m9NYPHFMub+7FuwXfPaiehVQAGaz6dups Rrhy2RBbH/hN+fQnj6K2H/xnDhrMK6oF2jNJklDKkxW6oxPS5wWChSP+N1gaKxhURRosctJFO65 TpmoHB7RDDCJTufXg/7shQgLqWG+LdQdDHOhOEi7S3R1Flojzh183IXscxvCDwjlDtA== X-Received: by 2002:a05:600c:4e11:b0:489:1a3a:9e45 with SMTP id 5b1f17b1804b1-48a98673549mr144588455e9.26.1777888148307; Mon, 04 May 2026 02:49:08 -0700 (PDT) X-Received: by 2002:a05:600c:4e11:b0:489:1a3a:9e45 with SMTP id 5b1f17b1804b1-48a98673549mr144587825e9.26.1777888147733; Mon, 04 May 2026 02:49:07 -0700 (PDT) Received: from [192.168.100.100] (82-64-211-94.subs.proxad.net. [82.64.211.94]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a81b99127sm309282525e9.0.2026.05.04.02.49.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 May 2026 02:49:07 -0700 (PDT) Message-ID: Date: Mon, 4 May 2026 11:49:06 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 09/18] pesto, log: Share log.h (but not log.c) with pesto tool To: Stefano Brivio , passt-dev@passt.top References: <20260503215601.823029-1-sbrivio@redhat.com> <20260503215601.823029-10-sbrivio@redhat.com> From: Laurent Vivier Autocrypt: addr=lvivier@redhat.com; keydata= xsFNBFYFJhkBEAC2me7w2+RizYOKZM+vZCx69GTewOwqzHrrHSG07MUAxJ6AY29/+HYf6EY2 WoeuLWDmXE7A3oJoIsRecD6BXHTb0OYS20lS608anr3B0xn5g0BX7es9Mw+hV/pL+63EOCVm SUVTEQwbGQN62guOKnJJJfphbbv82glIC/Ei4Ky8BwZkUuXd7d5NFJKC9/GDrbWdj75cDNQx UZ9XXbXEKY9MHX83Uy7JFoiFDMOVHn55HnncflUncO0zDzY7CxFeQFwYRbsCXOUL9yBtqLer Ky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KrM1fzzb8JtAuSbuzZSQPDwQEI5CKKxp7zf76J21YeRrEW4WDznPyVcDTa+tz++q2S/Bp P4W98bXCBIuQgs2m+OflERv5c3Ojldp04/S4NEjXEYRWdiCxN7ca5iPml5gLtuvhJMSy36gl U6IW9kn30IWuSoBpTkgV7rLUEhh9Ms82VWW/h2TxL8enfx40PrfbDtWwqRID3WY8jLrjKfTd R3LW8BnUDNkG+c4FzvvGUs8AvuqxxyHbXAfDx9o/jXfPHVRmJVhSmd+hC3mcQ+4iX5bBPBPM oDqSoLt5w9GoQQ6gDVP2ZjTWqwSRMLzNr37rJjZ1pt0DCMMTbiYIUcrhX8eveCJtY7NGWNyx FCRkhxRuGcpwPmRVDwOl39MB3iTsRighiMnijkbLXiKoJ5CDVvX5yicNqYJPKh5MFXN1bvsB kmYiStMRbrD0HoY1kx5/VozBtc70OU0EB8Wrv9hZD+Ofp0T3KOr1RUHvCZoLURfFhSQ= In-Reply-To: <20260503215601.823029-10-sbrivio@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 2bVLKLInPgZNzFokgGPfgLC-4WqyZER3M2lOUyN2D28_1777888148 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: KBLJU76H5Y2G5F74YUCA6V7NLBK2CDAO X-Message-ID-Hash: KBLJU76H5Y2G5F74YUCA6V7NLBK2CDAO X-MailFrom: lvivier@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Jon Maloy , David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 5/3/26 23:55, Stefano Brivio wrote: > From: David Gibson > > In pesto we're going to want several levels of error/warning messages, much > like passt itself. Particularly as we start to share mode code between > passt and pesto, we want to use a similar interface to emit those. However > we don't want to use the same implementation - logging to a file or syslog > doesn't make sense for the command line tool. > > To accomplish this loosely share log.h, but not log.c between pesto and > passt. In fact, an #ifdef means even most of log.h isn't actually shared, > but we do provide similar warn(), die() etc. macros. > > This includes the *_perror() variants, which need strerror(). However, > we want to avoid allocations for pesto as we do for passt, and strerror() > allocates in some libc versions. Therefore, also move our workaround for > this to be shared with pesto. > > Signed-off-by: Stefano Brivio > [dwg: Based on changes part of a larger patch by Stefano] > Signed-off-by: David Gibson Reviewed-by: Laurent Vivier One little nit below > --- > Makefile | 6 +++++- > common.h | 32 ++++++++++++++++++++++++++++++ > log.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- > pesto.c | 14 ++++---------- > util.h | 32 ------------------------------ > 5 files changed, 99 insertions(+), 44 deletions(-) > > diff --git a/Makefile b/Makefile > index 030681b..f6cec8a 100644 > --- a/Makefile > +++ b/Makefile > @@ -61,7 +61,7 @@ PASST_HEADERS = arch.h arp.h bitmap.h checksum.h common.h conf.h dhcp.h \ > vhost_user.h virtio.h vu_common.h > QRAP_HEADERS = arp.h ip.h passt.h util.h > PASST_REPAIR_HEADERS = linux_dep.h > -PESTO_HEADERS = common.h pesto.h > +PESTO_HEADERS = common.h pesto.h log.h > > C := \#include \nint main(){int a=getrandom(0, 0, 0);} > ifeq ($(shell printf "$(C)" | $(CC) -S -xc - -o - >/dev/null 2>&1; echo $$?),0) > @@ -121,6 +121,7 @@ qrap: $(QRAP_SRCS) $(QRAP_HEADERS) > > passt-repair: $(PASST_REPAIR_SRCS) $(PASST_REPAIR_HEADERS) seccomp_repair.h > > +pesto: BASE_CPPFLAGS += -DPESTO > pesto: $(PESTO_SRCS) $(PESTO_HEADERS) seccomp_pesto.h > > valgrind: EXTRA_SYSCALLS += rt_sigprocmask rt_sigtimedwait rt_sigaction \ > @@ -221,9 +222,12 @@ cppcheck: passt.cppcheck passt-repair.cppcheck pesto.cppcheck qrap.cppcheck > %.cppcheck: > $(CPPCHECK) $(CPPCHECK_FLAGS) $(BASE_CPPFLAGS) $^ > > +passt.cppcheck: BASE_CPPFLAGS += -UPESTO > passt.cppcheck: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h > + > passt-repair.cppcheck: $(PASST_REPAIR_SRCS) $(PASST_REPAIR_HEADERS) seccomp_repair.h > > +pesto.cppcheck: BASE_CPPFLAGS += -DPESTO > pesto.cppcheck: CPPCHECK_FLAGS += --suppress=unmatchedSuppression > pesto.cppcheck: $(PESTO_SRCS) $(PESTO_HEADERS) seccomp_pesto.h > > diff --git a/common.h b/common.h > index a9c115a..2f2e6f1 100644 > --- a/common.h > +++ b/common.h > @@ -21,4 +21,36 @@ > /* FPRINTF() intentionally silences cert-err33-c clang-tidy warnings */ > #define FPRINTF(f, ...) (void)fprintf(f, __VA_ARGS__) > > +/* > + * Starting from glibc 2.40.9000 and commit 25a5eb4010df ("string: strerror, > + * strsignal cannot use buffer after dlmopen (bug 32026)"), strerror() needs > + * getrandom(2) and brk(2) as it allocates memory for the locale-translated > + * error description, but our seccomp profiles forbid both. > + * > + * Use the strerror_() wrapper instead, calling into strerrordesc_np() to get > + * a static untranslated string. It's a GNU implementation, but also defined by > + * bionic. > + * > + * If strerrordesc_np() is not defined (e.g. musl), call strerror(). C libraries > + * not defining strerrordesc_np() are expected to provide strerror() > + * implementations that are simple enough for us to call. > + */ > +__attribute__ ((weak)) const char *strerrordesc_np(int errnum); > + > +/** > + * strerror_() - strerror() wrapper calling strerrordesc_np() if available > + * @errnum: Error code > + * > + * Return: error description string > + */ > +static inline const char *strerror_(int errnum) > +{ > + if (strerrordesc_np) > + return strerrordesc_np(errnum); > + > + return strerror(errnum); > +} > + > +#define strerror(x) @ "Don't call strerror() directly, use strerror_() instead" > + > #endif /* _COMMON_H */ > diff --git a/log.h b/log.h > index dbab006..1058ca5 100644 > --- a/log.h > +++ b/log.h > @@ -6,8 +6,63 @@ > #ifndef LOG_H > #define LOG_H > > -#include > #include > +#include > +#include > + > +#ifdef PESTO > + > +#include > + > +#include "common.h" > + > +extern bool debug_flag; > + > +#define msg(...) \ > + do { \ > + FPRINTF(stderr, __VA_ARGS__); \ > + FPRINTF(stderr, "\n"); \ > + } while (0) > + > +#define msg_perror(...) \ > + do { \ > + int errno_ = errno; \ > + FPRINTF(stderr, __VA_ARGS__); \ > + FPRINTF(stderr, ": %s\n", strerror_(errno_)); \ > + } while (0) > + > +#define die(...) \ > + do { \ > + msg(__VA_ARGS__); \ > + exit(EXIT_FAILURE); \ > + } while (0) > + > +#define die_perror(...) \ > + do { \ > + msg_perror(__VA_ARGS__); \ > + exit(EXIT_FAILURE); \ > + } while (0) > + > +#define warn(...) msg(__VA_ARGS__) > +#define warn_perror(...) msg_perror(__VA_ARGS__) > +#define info(...) msg(__VA_ARGS__) > +#define info_perror(...) msg_perror(__VA_ARGS__) > + > +#define debug(...) \ > + do { \ > + if (debug_flag) \ > + msg(__VA_ARGS__); \ > + } while (0) > + > +#define debug_perror_(...) \ Why is this "debug_perror_()" and not "debug_perror()"? > + do { \ > + if (debug_flag) \ > + msg_perror(__VA_ARGS__); \ > + } while (0) > + > +#else /* !PESTO */ > + > +#include > #include > #include > > @@ -109,4 +164,6 @@ void __openlog(const char *ident, int option, int facility); > void logfile_init(const char *name, const char *path, size_t size); > void __setlogmask(int mask); > > +#endif /* !PESTO */ > + > #endif /* LOG_H */ > diff --git a/pesto.c b/pesto.c > index 9f2fa5d..f0916e8 100644 > --- a/pesto.c > +++ b/pesto.c > @@ -34,18 +34,12 @@ > #include "common.h" > #include "seccomp_pesto.h" > #include "pesto.h" > +#include "log.h" > > -static bool debug_flag = false; > +bool debug_flag = false; > > static char stdout_buf[BUFSIZ]; > > -#define die(...) \ > - do { \ > - FPRINTF(stderr, __VA_ARGS__); \ > - FPRINTF(stderr, "\n"); \ > - exit(EXIT_FAILURE); \ > - } while (0) > - > /** > * usage() - Print usage, exit with given status code > * @name: Executable name > @@ -99,7 +93,7 @@ int main(int argc, char **argv) > * breaking our seccomp profile. > */ > if (setvbuf(stdout, stdout_buf, _IOFBF, sizeof(stdout_buf))) > - die("Failed to set stdout buffer"); > + die_perror("Failed to set stdout buffer"); > > do { > optname = getopt_long(argc, argv, optstring, options, NULL); > @@ -126,7 +120,7 @@ int main(int argc, char **argv) > if (argc - optind != 1) > usage(argv[0], stderr, EXIT_FAILURE); > > - printf("debug_flag=%d, path=\"%s\"\n", debug_flag, argv[optind]); > + debug("debug_flag=%d, path=\"%s\"", debug_flag, argv[optind]); > > die("pesto is not implemented yet"); > } > diff --git a/util.h b/util.h > index 770ff93..e90be47 100644 > --- a/util.h > +++ b/util.h > @@ -302,38 +302,6 @@ static inline bool mod_between(unsigned x, unsigned i, unsigned j, unsigned m) > > void raw_random(void *buf, size_t buflen); > > -/* > - * Starting from glibc 2.40.9000 and commit 25a5eb4010df ("string: strerror, > - * strsignal cannot use buffer after dlmopen (bug 32026)"), strerror() needs > - * getrandom(2) and brk(2) as it allocates memory for the locale-translated > - * error description, but our seccomp profiles forbid both. > - * > - * Use the strerror_() wrapper instead, calling into strerrordesc_np() to get > - * a static untranslated string. It's a GNU implementation, but also defined by > - * bionic. > - * > - * If strerrordesc_np() is not defined (e.g. musl), call strerror(). C libraries > - * not defining strerrordesc_np() are expected to provide strerror() > - * implementations that are simple enough for us to call. > - */ > -__attribute__ ((weak)) const char *strerrordesc_np(int errnum); > - > -/** > - * strerror_() - strerror() wrapper calling strerrordesc_np() if available > - * @errnum: Error code > - * > - * Return: error description string > - */ > -static inline const char *strerror_(int errnum) > -{ > - if (strerrordesc_np) > - return strerrordesc_np(errnum); > - > - return strerror(errnum); > -} > - > -#define strerror(x) @ "Don't call strerror() directly, use strerror_() instead" > - > /* > * Workarounds for https://github.com/llvm/llvm-project/issues/58992 > *