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=C2z7yWM1; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 139335A0627 for ; Tue, 05 May 2026 01:11:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777936292; 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; bh=P2NSFxRPrqaagq7q8gD7cDEgPfcoDwxLNLJcAPG+Y9U=; b=C2z7yWM1ZW6PDrNgouN9+hnH8BUKpnP2YwZDIG3lZPvi2lMQIIfcmuqjv/kfdrwp1t7Wh7 ty0IvHe4CkIewOcZYERgcIVXosm+0kM81v8Ujwc0U7MyfBa6JSGldytJVB+WIHHmq3WRLA 8poTia6aD3RziKYcmq3/Y8HDp3R7C1A= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-110-XxpFMl_3P2Gim5cVqXl5EQ-1; Mon, 04 May 2026 19:11:28 -0400 X-MC-Unique: XxpFMl_3P2Gim5cVqXl5EQ-1 X-Mimecast-MFC-AGG-ID: XxpFMl_3P2Gim5cVqXl5EQ_1777936287 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-44cc3c9b2feso1817911f8f.1 for ; Mon, 04 May 2026 16:11:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777936287; x=1778541087; h=date:content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=P2NSFxRPrqaagq7q8gD7cDEgPfcoDwxLNLJcAPG+Y9U=; b=dU0qfAOd3QUFAPs0vMVkFb1oVkXXAJ7LkaStFeMXd07CBhhmNbUiRAHcG04lZJruyt LiKro8Jz8fw+0jtQ6iP/I1d6sLXkJO3L8IgRaCnGyhI38IQT5zDe2SLjSgA8J4wKfWmr rs44okMMDEE0LbZRxCL1tE3eDTfRiXHsUFKYbLnHLgMnlUkWvdzJlgWdbUuVvg2Pmq0H tVANjXPUGl0vBEJUmpygC+IgM1BfsyCB2P+nawmN4HyFILeqQ8KqED14z7Gk29pCxQQq mmutX8GvgglX8DoF7soZkAW3fC88i+BNYtE6JBrSO/c+j84SfyHQ0XkkN8uou22GNCY9 YT+g== X-Gm-Message-State: AOJu0Yxj/sHQvd4SELP82Omp2GwsHXq1OgP4ijK+2rUw11nI6nYGybNd 50ls0HR3h7I5YQXO5mqKIfM8agbGYr2gicxuAw7VRkNLJVPdR4Hc08JJDBWx30sSlCTJbnMIT5v dQImQ+cdabl0RTSiHxXHGEa8IhacaupxhQC9RRfALIrc6f7yTN0ptgg== X-Gm-Gg: AeBDievrAwNcS4sUOMYSH0UoaVlA6gWQqH0QMm7bBRZu37NybRwz9C1JwDQ1/NHtnx7 p2t20TgxSid8UHXf6P1zQYWYdMztUmMqwn1075/8946tbIeExWSyJziKGfak8C72sECb/ZnpI2a 5sXG/31mOZRoFEAEz9qXWJbIS/8F6xU5+wOx1Etljx/t6khxGhJNIB2cqZomw7a6gZhxjWw/BEw WUqjFtvnibbKg410T/h/OJzUpXhjTnjPNnx413kU334E+IbdpXAP/PBIZOV11qufC9QYMJjP3Gg dH5uqZYYeENOKe6i6lnMHLT8jspDYF6hqt8aQfNlpLKhwllE6COrLdI17DqNDgMmmYBJ5cXdYsA 6aMXUX7hvfmcqU/7f8SR5nC34h9W8CnXoEBt0j0ZKBVg6IXCjxt7joXCyw4r2 X-Received: by 2002:a05:600c:a411:b0:48a:7b55:12a6 with SMTP id 5b1f17b1804b1-48a980fc3e7mr138936005e9.0.1777936287124; Mon, 04 May 2026 16:11:27 -0700 (PDT) X-Received: by 2002:a05:600c:a411:b0:48a:7b55:12a6 with SMTP id 5b1f17b1804b1-48a980fc3e7mr138935705e9.0.1777936286677; Mon, 04 May 2026 16:11:26 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a8eb69698sm548898255e9.1.2026.05.04.16.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2026 16:11:26 -0700 (PDT) From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v6 09/18] pesto, log: Share log.h (but not log.c) with pesto tool Message-ID: <20260505011124.14c5ce3d@elisabeth> In-Reply-To: References: <20260503215601.823029-1-sbrivio@redhat.com> <20260503215601.823029-10-sbrivio@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Tue, 05 May 2026 01:11:25 +0200 (CEST) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: D3a3y-mK0MhXKoHKpGWl3dHE9O-HWpFl2Z2iE57pyco_1777936287 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: CXSVQVALYRFDXPLYGWM4HKDJVVEK4RFK X-Message-ID-Hash: CXSVQVALYRFDXPLYGWM4HKDJVVEK4RFK X-MailFrom: sbrivio@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: passt-dev@passt.top, 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 Mon, 4 May 2026 11:49:06 +0200 Laurent Vivier wrote: > 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()"? I'm not sure, but it's not used anyway, so I dropped it altogether in v7. > > + do { \ > > + if (debug_flag) \ > > + msg_perror(__VA_ARGS__); \ > > + } while (0) > > + > > +#else /* !PESTO */ -- Stefano