From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202410 header.b=N1o8lMxs; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 7E3E15A061A for ; Fri, 08 Nov 2024 03:24:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1731032623; bh=+yzTmPBcXo2j7uR0WOaTk/szQqH65taGnkuJwNAOUfs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=N1o8lMxsN2xpLVGK4WzTPs0vQVC6l6nIKXGgbv1SVoBUbQhL3IKTf43TBUuFoV/5N iLwrg1CQJ90hZdaAR0bK9aAH1CNprGoDNajH90oZy8cj5sRIdxCbztS7pb7nrI8yo0 B8Fyy0QgdsQuRNZbprSDJnUYvR3Z4O/bJRzq08Tj6GT+YKC/dxx1l4jxh0/0nOEMkf qfAbg4s62sQ+NeFYzCihSs2GJv4QMIG7orHFgSafnq9txb17c9dVYZXT26OlJChlce U2OggcVByC6swhrw2PpuosxavSpphK6wDWOai9TDW8DqUQ4xBow+ZUwBbDBGsWF2ot za7efRTUxqMVg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Xl2mv2bB2z4x8H; Fri, 8 Nov 2024 13:23:43 +1100 (AEDT) Date: Fri, 8 Nov 2024 11:31:35 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 6/6] tap, tcp, util: Add some missing SOCK_CLOEXEC flags Message-ID: References: <20241107184331.3164784-1-sbrivio@redhat.com> <20241107184331.3164784-7-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="qu3e+o0bR464CQkJ" Content-Disposition: inline In-Reply-To: <20241107184331.3164784-7-sbrivio@redhat.com> Message-ID-Hash: ISWBRZ42X3BLUD2RU3WHJFPBTFUF47XT X-Message-ID-Hash: ISWBRZ42X3BLUD2RU3WHJFPBTFUF47XT 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 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: --qu3e+o0bR464CQkJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 07, 2024 at 07:43:31PM +0100, Stefano Brivio wrote: > I have no idea why, but these are reported by clang-tidy (19.2.1) on > Alpine (x86) only: >=20 > /home/sbrivio/passt/tap.c:1139:38: error: 'socket' should use SOCK_CLOEXE= C where possible [android-cloexec-socket,-warnings-as-errors] > 1139 | int fd =3D socket(AF_UNIX, SOCK_STREAM, 0); > | ^ > | | SOCK_CLOEXEC > /home/sbrivio/passt/tap.c:1158:51: error: 'socket' should use SOCK_CLOEXE= C where possible [android-cloexec-socket,-warnings-as-errors] > 1158 | ex =3D socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOC= K, 0); > | ^ > | = | SOCK_CLOEXEC > /home/sbrivio/passt/tcp.c:1413:44: error: 'socket' should use SOCK_CLOEXE= C where possible [android-cloexec-socket,-warnings-as-errors] > 1413 | s =3D socket(af, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP= ); > | ^ > | | SOCK_CLOEXEC > /home/sbrivio/passt/util.c:188:38: error: 'socket' should use SOCK_CLOEXE= C where possible [android-cloexec-socket,-warnings-as-errors] > 188 | if ((s =3D socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0= ) { > | ^ > | | SOCK_CLOEXEC >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > tap.c | 5 +++-- > tcp.c | 2 +- > util.c | 3 ++- > 3 files changed, 6 insertions(+), 4 deletions(-) >=20 > diff --git a/tap.c b/tap.c > index a3ba958..14d9b3d 100644 > --- a/tap.c > +++ b/tap.c > @@ -1136,7 +1136,7 @@ void tap_handler_pasta(struct ctx *c, uint32_t even= ts, > */ > int tap_sock_unix_open(char *sock_path) > { > - int fd =3D socket(AF_UNIX, SOCK_STREAM, 0); > + int fd =3D socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); > struct sockaddr_un addr =3D { > .sun_family =3D AF_UNIX, > }; > @@ -1155,7 +1155,8 @@ int tap_sock_unix_open(char *sock_path) > UNIX_SOCK_PATH, i)) > die_perror("Can't build UNIX domain socket path"); > =20 > - ex =3D socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0); > + ex =3D socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, > + 0); > if (ex < 0) > die_perror("Failed to check for UNIX domain conflicts"); > =20 > diff --git a/tcp.c b/tcp.c > index a3d48fa..6a98dfa 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1410,7 +1410,7 @@ static int tcp_conn_new_sock(const struct ctx *c, s= a_family_t af) > { > int s; > =20 > - s =3D socket(af, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP); > + s =3D socket(af, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, IPPROTO_TC= P); > =20 > if (s > FD_REF_MAX) { > close(s); > diff --git a/util.c b/util.c > index dddef93..3448f30 100644 > --- a/util.c > +++ b/util.c > @@ -183,7 +183,8 @@ void sock_probe_mem(struct ctx *c) > int v =3D INT_MAX / 2, s; > socklen_t sl; > =20 > - if ((s =3D socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { > + s =3D socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); > + if (s < 0) { > c->low_wmem =3D c->low_rmem =3D 1; > return; > } --=20 David Gibson (he or they) | 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 --qu3e+o0bR464CQkJ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmctW+YACgkQzQJF27ox 2GdujxAAozWGwozduMpa5Kre0/7AFWyyh/XXUMkAzsiUnFXvojuZlxhupIY+uebI LfTRW1dUbBxYWtO4zTD0AJZIO5lAysESC/GBVqAPWgXp371fPhiESXJyVYRW1B2q HwjthKN/ir4mksxiojlr6xhzhWc82p1IOTBV8GLA20KLDcmEeHOT9VH74txmse1d b9ns5nKbyuId4OLugq5IEwhELP7VDik4jqQDT4zcl9azbpQE3LZArlt3RheNNe8l CqbnfBKNLCORK8Dy8TmO5VKYTHQfBqHrmYn8zSl/9+NJYgrX/FlVEgGqjHfYiO8S eiBjiCu867Me8umqSlCj2ZBt9I4dSyv5pD6RNiLEu1A+ivtMF2IRkgQ4t7fqL95S jszISo9Wp4NuFG176x92B+tV5sf7p1gX1zpGSG8NC1fHhIZAgsXe/Lq38KcdYXqW DFHvPcQC44qaEMnrg9NpXYVNVNiAgUdfxeGSFglAQ9Js4J7ybHgYqQreJJO5To6u 6+4WAhWz/PigtlIavPRJnBglezIGMTIukFZI5UJ4cGuX38d4ahFl6G1pnHUn6xtX mOzV5DASGz5v99FmactNg53toElvGmAH6Jh11iDmiUDFNv5TBdoZ4vsk2j9o8jxT FYPaWUV3pvsnlObcZMgadgCkiJyeb+VvvFt6evSaK+K02HxmsmU= =41lU -----END PGP SIGNATURE----- --qu3e+o0bR464CQkJ--