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 A733B5A0262 for ; Thu, 6 Apr 2023 12:41:04 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PsdMJ32Pnz4x5c; Thu, 6 Apr 2023 20:41:00 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1680777660; bh=UeBAXLViKyGJDH+CVzMD+jF2sIChEejZecACtGKA3NI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jX/dRmr9TkNVBTg2w1anoG+nuRhzbGUNz6GXe96xWW9eaUFL2/c2D0jY6G1epcken 8wbFmoozwPfxyi5ImjELdPwFDnSSQdiaTEnNa9aU10XlecMTzEBFnZYC3dsuvl1d2e ACvFTMpT3w7ZYqO+aXdjIm2hPtd8yx4ICd+O0AqI= Date: Thu, 6 Apr 2023 20:35:32 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 04/14] nstool: Split some command line parsing and socket setup to subcommands Message-ID: References: <20230404014638.3225556-1-david@gibson.dropbear.id.au> <20230404014638.3225556-5-david@gibson.dropbear.id.au> <20230405135800.1c3705ca@elisabeth> <20230406084748.5812c233@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="kZhz7hMeJ7D/J3hg" Content-Disposition: inline In-Reply-To: <20230406084748.5812c233@elisabeth> Message-ID-Hash: AMGECOTDK73MP4TVDWFE4YQGSMMY5QBM X-Message-ID-Hash: AMGECOTDK73MP4TVDWFE4YQGSMMY5QBM 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: --kZhz7hMeJ7D/J3hg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Apr 06, 2023 at 08:47:48AM +0200, Stefano Brivio wrote: > On Thu, 6 Apr 2023 12:31:55 +1000 > David Gibson wrote: >=20 > > On Wed, Apr 05, 2023 at 01:58:00PM +0200, Stefano Brivio wrote: > > > > [...] > > > > > I didn't spot this earlier, but... does it really make sense to wait = in > > > cmd_pid(), also on ENOENT, rather than making 'hold' return only once > > > the socket is ready? =20 > >=20 > > So, this is a consequence of the fact that the holder doesn't move > > into the background itself - it just sits in the foreground until > > terminated. That means that the typical usecase puts it into the > > background from the shell with &, which in turn means that when we > > reach the next shell command the socket may not be ready - or not even > > created. > >=20 > > One of the things I had in mind for a hypothetical "nstool unshare" > > would be to avoid this and have it background itself once the socket > > is ready. >=20 > Ah, sure, it makes sense now. >=20 > > > I don't think it would be outrageous to have > > > 'nstool pid' failing if the holding process doesn't exist. > > >=20 > > > Admittely, I'm biased by the few hundreds of times I needed to > > > 'killall -9 nsholder' in the past months. :) =20 > >=20 > > So... I agree that's irritating, I've done it a similar number of > > times. However, I don't think that's really related to the question > > above - in my experience it's always been the holder process that's > > hung around, not something waiting on a holder. >=20 > Yes, same here, but it's something I file under the same category (I > don't remember why nsholder would hang, you probably explained at some > point...). I believe the main reason is because of the holders which are PID 1 within their pid namespaces. That means that if you interrupt the tests, the SIGINT or SIGHUP they'll get from tmux etc. shutting down won't be sufficient to kill them. >=20 > > > > rc =3D getsockopt(fd, SOL_SOCKET, SO_PEERCRED, > > > > &peercred, &optlen); > > > > if (rc < 0) > > > > - die("getsockopet(SO_PEERCRED): %s\n", strerror(errno)); > > > > + die("getsockopet(SO_PEERCRED) %s: %s\n", > > > > + sockpath, strerror(errno)); > > > > =20 > > > > close(fd); > > > > =20 > > > > printf("%d\n", peercred.pid); > > > > } > > > > =20 > > > > -static void stop(int fd, const struct sockaddr_un *addr) > > > > +static void cmd_stop(int argc, char *argv[]) > > > > { > > > > - int rc; > > > > + const char *sockpath =3D argv[1]; > > > > + int fd, rc; > > > > char buf =3D 'Q'; > > > > =20 > > > > - rc =3D connect(fd, (struct sockaddr *)addr, sizeof(*addr)); > > > > - if (rc < 0) > > > > - die("connect(): %s\n", strerror(errno)); > > > > + if (argc !=3D 2) > > > > + usage(); > > > > + > > > > + fd =3D connect_ctl(sockpath, false); > > > > =20 > > > > rc =3D write(fd, &buf, sizeof(buf)); =20 > > >=20 > > > Unrelated: a compound literal would make this more readable. =20 > >=20 > > Uh.. I don't see where a compound literal would even go here. >=20 > I meant: >=20 > rc =3D write(fd, &(char){ 'Q' }, 1); >=20 > ...so that one doesn't need to look at 'buf'. nstool is C99 anyway. Oh, ok. On the other hand it means not using sizeof() to get the length, which isn't ideal. --=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 --kZhz7hMeJ7D/J3hg Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmQuoEEACgkQzQJF27ox 2Gestw//Z8h9uIpQy1Ekt3gS39PNYcVf/J6+8xawRqZFCSgKSwgD47HtHH7YjbSn NrN/WWBqAg9jE4/zMbmbytICbm8w0jGnCz/y3bZtl3txdCeILG7lb7hiJIGPpNpI jx7X/XAhU5DZj+0GjQlRTtrYN1eNk5/SagSoH14T92h9jk3HCyQ2f7Rn3mjRetYr vAyukc62tr5/lOjdUAwYS9drCdIsULEZHeshXTqzlB4EgxaLSo1FLifnYW3ZsYcQ zC5KJ1jPz3i5s4HYEnlRia9B1FvjqkkoFT2m9RfVBew1HfawS1pXeuVkbgJtW0fm 9+mBsYT69whzEFAzRE9yriYHTXPO0mTiZ5urWo1N+Ou1K82ZSAMwfEqaNarf8TRS qrDZA3KhUJ2aEc24dM3yTMUP6OTvy4T8O7QT1FJAQE9wcoiuBM08E+BJdLGAWWfx ZflhCM05XlINpRlSXANzX5BefmppM2vLPGINq4ynQHYFYle+EXIEF8pS5aCx2axL wUvJHbWVmdG5O9EFSI8xH7wVAsMD46ZOYx5a0TxIYPuOl3pb5O4JsV1ojRdu0a9E Pp5R/zgu4aslzpliLMll3Rx7mTqfUMRDZ+n+7lEHU1JsaBJZiGemsNZ4U2dhN6Zk R+kngHN26NUH4wQRGwInQgQb4I3hB+850Dg3XOsdvgFgpRyNQbA= =EtSI -----END PGP SIGNATURE----- --kZhz7hMeJ7D/J3hg--