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.133.124]) by passt.top (Postfix) with ESMTP id F36455A0272 for ; Thu, 3 Aug 2023 00:48:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691016483; 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=dnhOA2vDty+cie8NHuP9htg52g8JXGxYd+fSYe/Qqb8=; b=doXbCcpLN8Zyh3vFJdQktY/A4wj9crcBVGiB0pl7iNh0CBLWni9woDwyHdv90cg5lLgrhN 3OyQvbDxvT/dermoTAsnMP5hpARPGlWfGvh87RId2nhIamlAh0c2taEt0yXJYYHuDQH4U0 gSMq0f3zU5U4Wtw5u6LhM6Hl+bgIk90= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-324-QaYLRQzGN42EZXfmLD58Mw-1; Wed, 02 Aug 2023 18:48:02 -0400 X-MC-Unique: QaYLRQzGN42EZXfmLD58Mw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0807A38008B5; Wed, 2 Aug 2023 22:48:02 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 55E282166B26; Wed, 2 Aug 2023 22:48:01 +0000 (UTC) Date: Thu, 3 Aug 2023 00:47:59 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 08/17] netlink: Treat send() or recv() errors as fatal Message-ID: <20230803004759.099a99a7@elisabeth> In-Reply-To: <20230724060936.952659-9-david@gibson.dropbear.id.au> References: <20230724060936.952659-1-david@gibson.dropbear.id.au> <20230724060936.952659-9-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: IY6675URPFKJ2VW6JSJ3RCOMFO5WTUUN X-Message-ID-Hash: IY6675URPFKJ2VW6JSJ3RCOMFO5WTUUN 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 Mon, 24 Jul 2023 16:09:27 +1000 David Gibson wrote: > Errors on send() or recv() calls on a netlink socket don't indicate errors > with the netlink operations we're attempting, but rather that something's > gone wrong with the mechanics of netlink itself. We don't really expect > this to ever happen, and if it does, it's not clear what we could to to > recover. > > So, treat errors from these calls as fatal, rather than returning the error > up the stack. This makes handling failures in the callers of nl_req() > simpler. > > Signed-off-by: David Gibson > --- > netlink.c | 36 +++++++++++++++++------------------- > 1 file changed, 17 insertions(+), 19 deletions(-) > > diff --git a/netlink.c b/netlink.c > index 3620fd6..826c926 100644 > --- a/netlink.c > +++ b/netlink.c > @@ -103,9 +103,9 @@ fail: > * @req: Request with netlink header > * @len: Request length > * > - * Return: received length on success, negative error code on failure > + * Return: received length on success, terminates on error > */ > -static int nl_req(int s, char *buf, const void *req, ssize_t len) > +static ssize_t nl_req(int s, char *buf, const void *req, ssize_t len) > { > char flush[NLBUFSIZ]; > int done = 0; > @@ -124,11 +124,17 @@ static int nl_req(int s, char *buf, const void *req, ssize_t len) > } > } > > - if ((send(s, req, len, 0) < len) || > - (len = recv(s, buf, NLBUFSIZ, 0)) < 0) > - return -errno; > + n = send(s, req, len, 0); > + if (n < 0) > + die("netlink: Failed to send(): %s", strerror(errno)); > + else if (n < len) > + die("netlink: Short send"); If you respin, probably worth doing: die("netlink: Short send (%li out of %li bytes)", n, len); -- Stefano