From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 700A55A0270 for ; Mon, 27 Feb 2023 14:30:01 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PQLvg5hPGz4xDq; Tue, 28 Feb 2023 00:29:51 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1677504591; bh=DiNbWWn7R3hQSSOS1aJu72ZwnFyuQAkzHEMe5oobgME=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gLpNIeEPDAi9jVW9+vBmRlS4n563B+6eSeW7YdzUJ+KWZBGcX57mjwwMDBdx23NkA W6ev1kLBlmbBuo6JfY03PAb8Gm5NezBSmK846QEYuGyKQ8sGyFARHgJuRdH7gu+1MI WcRFfdRBPkKhJ4r4Q0EgR515mBtTWiYjGVKQM/Ac= Date: Mon, 27 Feb 2023 21:56:01 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] log, conf, tap: Define die() as err() plus exit(), drop cppcheck workarounds Message-ID: References: <20230227100054.225924-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pr89gQvHrLnWmjjv" Content-Disposition: inline In-Reply-To: <20230227100054.225924-1-sbrivio@redhat.com> Message-ID-Hash: SKS34BRLRUJVVQN4N6WFXAEYAH6Q33KO X-Message-ID-Hash: SKS34BRLRUJVVQN4N6WFXAEYAH6Q33KO X-MailFrom: dgibson@gandalf.ozlabs.org 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, Laine Stump 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: --pr89gQvHrLnWmjjv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Feb 27, 2023 at 11:00:54AM +0100, Stefano Brivio wrote: > If we define die() as a variadic macro, passing __VA_ARGS__ to err(), > and calling exit() outside err() itself, we can drop the workarounds > introduced in commit 36f0199f6ef4 ("conf, tap: Silence two false > positive invalidFunctionArg from cppcheck"). >=20 > Suggested-by: David Gibson > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > conf.c | 3 --- > log.c | 14 +++++--------- > log.h | 7 ++++++- > tap.c | 6 +----- > 4 files changed, 12 insertions(+), 18 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index 37f25d6..0e512f4 100644 > --- a/conf.c > +++ b/conf.c > @@ -1064,9 +1064,6 @@ static void conf_ugid(char *runas, uid_t *uid, gid_= t *gid) > if ((fd =3D open("/proc/self/uid_map", O_RDONLY | O_CLOEXEC)) < 0) { > die("Can't determine if we're in init namespace: %s", > strerror(errno)); > - > - /* Silence cppcheck's invalidFunctionArg for 'fd' in read() */ > - return; > } > =20 > if (read(fd, buf, BUFSIZ) !=3D sizeof(root_uid_map) || > diff --git a/log.c b/log.c > index bfde6ce..d2f08fa 100644 > --- a/log.c > +++ b/log.c > @@ -46,7 +46,7 @@ int log_trace; /* --trace mode enabled */ > =20 > #define BEFORE_DAEMON (setlogmask(0) =3D=3D LOG_MASK(LOG_EMERG)) > =20 > -#define logfn(name, level, doexit) \ > +#define logfn(name, level) \ > void name(const char *format, ...) { \ > struct timespec tp; \ > va_list args; \ > @@ -75,9 +75,6 @@ void name(const char *format, ...) { \ > if (format[strlen(format)] !=3D '\n') \ > fprintf(stderr, "\n"); \ > } \ > - \ > - if (doexit) \ > - exit(EXIT_FAILURE); \ > } > =20 > /* Prefixes for log file messages, indexed by priority */ > @@ -90,11 +87,10 @@ const char *logfile_prefix[] =3D { > " ", /* LOG_DEBUG */ > }; > =20 > -logfn(die, LOG_ERR, 1) > -logfn(err, LOG_ERR, 0) > -logfn(warn, LOG_WARNING, 0) > -logfn(info, LOG_INFO, 0) > -logfn(debug,LOG_DEBUG, 0) > +logfn(err, LOG_ERR) > +logfn(warn, LOG_WARNING) > +logfn(info, LOG_INFO) > +logfn(debug,LOG_DEBUG) > =20 > /** > * trace_init() - Set log_trace depending on trace (debug) mode > diff --git a/log.h b/log.h > index d4e9d85..d4ea141 100644 > --- a/log.h > +++ b/log.h > @@ -10,12 +10,17 @@ > #define LOGFILE_CUT_RATIO 30 /* When full, cut ~30% size */ > #define LOGFILE_SIZE_MIN (5UL * MAX(BUFSIZ, PAGE_SIZE)) > =20 > -void die(const char *format, ...); > void err(const char *format, ...); > void warn(const char *format, ...); > void info(const char *format, ...); > void debug(const char *format, ...); > =20 > +#define die(...) \ > + do { \ > + err(__VA_ARGS__); \ > + exit(EXIT_FAILURE); \ > + } while (0) > + > extern int log_trace; > void trace_init(int enable); > #define trace(...) \ > diff --git a/tap.c b/tap.c > index d6f962e..88eed88 100644 > --- a/tap.c > +++ b/tap.c > @@ -1037,13 +1037,9 @@ static void tap_sock_unix_init(struct ctx *c) > snprintf(path, UNIX_PATH_MAX - 1, UNIX_SOCK_PATH, i); > =20 > ex =3D socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0); > - if (ex < 0) { > + if (ex < 0) > die("UNIX domain socket check: %s", strerror(errno)); > =20 > - /* Silence cppcheck's invalidFunctionArg for 'ex' */ > - return; > - } > - > ret =3D connect(ex, (const struct sockaddr *)&addr, sizeof(addr)); > if (!ret || (errno !=3D ENOENT && errno !=3D ECONNREFUSED && > errno !=3D EACCES)) { --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --pr89gQvHrLnWmjjv Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmP8jDoACgkQzQJF27ox 2GfEmA/6A7jS0MSXDMKiDLFYg+IWoK1ASQhhoNelWG712w7A+wriv5HrD3W7lq09 MJM7AOt0I1GF5QVilSr+xFBvPI7l9MOF8CYzCR2p88di8zBa1eCJCxmeDblI5xEt lngF05oMVHr+Q15qcKm98dR/l2/eHn/PXW5ny9f7KXI5Z+kRn/hWcQEb1s5DPp3o qb6jeaq7zYMse5SIraCuhYNZAnPRH3Vp0EqdtSvyvQkX1RpIMss1B3u7PVrScszw d2/Dk58+FnXqFDHOhr7o+yGs4gMmXA+dcTRBvw6mYIC9lS2w9JpXwi9Q+/Gt2MNN gbf/+/momsBqVuJXqsI8d6aRfLrj5SewVg9yT++lZMl/v51Hfxq/XsZaMqcgUKXj 7dxseZPt9/mDPnCoZiLa3+hO5aKaItfojcvv7QxyhsZmvFaXxwKjHUbOEzOQUKoZ /Zkg18CEfvww7bPNSkCmBdYWvCKldxyppKsD1MgwXtcothDganC0IPhg21OVQF83 +94dTdbz87hFcmIUvque8WTRqC4wjqeIaE2Cpju2TlqvtB4SJtNntEF6GQbFzOTK 5rJJeancQSUSQtUOD0hzmnJPYv37a4OGe5pXqx7f0b7hkMR4UDbHHUlTTFgfgU60 2oQo2cIDhexKy4gTrg42kHMGlyaHZsxwhAczY/qHXgRqPewf9II= =vpUc -----END PGP SIGNATURE----- --pr89gQvHrLnWmjjv--