From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id CC61C5A0262 for ; Thu, 6 Apr 2023 08:47:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680763672; 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=Sx4C4he9j0X7MWGlXnUT0w5QgprIZF2mA/ofg5ANokc=; b=DpEVLDfhRZOemwhvjk4zZ32q5NU52ClRV6fnj+H8t5ZIavwJ9VUiDPlyZhbosBCqso63tF ssPdSq+Gr5uKzA9K0r7JA6XGlBvrwJHNYr/Th8CsmYfcnwyAVTikmE+LYyD6wA7wrOlBYy hLEGLkz3dqjFP8/SQ9hvlhjw5GiHbq0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-187-ZSPewKV4OqOy2RgwFtrffA-1; Thu, 06 Apr 2023 02:47:51 -0400 X-MC-Unique: ZSPewKV4OqOy2RgwFtrffA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D2AB4884EC1; Thu, 6 Apr 2023 06:47:50 +0000 (UTC) Received: from maya.cloud.tilaa.com (unknown [10.33.32.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B25C5492C3E; Thu, 6 Apr 2023 06:47:50 +0000 (UTC) Date: Thu, 6 Apr 2023 08:47:48 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 04/14] nstool: Split some command line parsing and socket setup to subcommands Message-ID: <20230406084748.5812c233@elisabeth> In-Reply-To: References: <20230404014638.3225556-1-david@gibson.dropbear.id.au> <20230404014638.3225556-5-david@gibson.dropbear.id.au> <20230405135800.1c3705ca@elisabeth> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 6SY2LMIBEDNZDFIBTA6236LX4L4WVVXO X-Message-ID-Hash: 6SY2LMIBEDNZDFIBTA6236LX4L4WVVXO 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 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 Thu, 6 Apr 2023 12:31:55 +1000 David Gibson wrote: > 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? > > 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. > > 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. Ah, sure, it makes sense now. > > I don't think it would be outrageous to have > > 'nstool pid' failing if the holding process doesn't exist. > > > > Admittely, I'm biased by the few hundreds of times I needed to > > 'killall -9 nsholder' in the past months. :) > > 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. 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...). > > > rc = 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)); > > > > > > close(fd); > > > > > > printf("%d\n", peercred.pid); > > > } > > > > > > -static void stop(int fd, const struct sockaddr_un *addr) > > > +static void cmd_stop(int argc, char *argv[]) > > > { > > > - int rc; > > > + const char *sockpath = argv[1]; > > > + int fd, rc; > > > char buf = 'Q'; > > > > > > - rc = connect(fd, (struct sockaddr *)addr, sizeof(*addr)); > > > - if (rc < 0) > > > - die("connect(): %s\n", strerror(errno)); > > > + if (argc != 2) > > > + usage(); > > > + > > > + fd = connect_ctl(sockpath, false); > > > > > > rc = write(fd, &buf, sizeof(buf)); > > > > Unrelated: a compound literal would make this more readable. > > Uh.. I don't see where a compound literal would even go here. I meant: rc = write(fd, &(char){ 'Q' }, 1); ...so that one doesn't need to look at 'buf'. nstool is C99 anyway. -- Stefano