From nobody Fri May 17 11:28:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604310370; cv=none; d=zohomail.com; s=zohoarc; b=Bb8G4dw+Soh+VRdiiXXlzwpozFoYJGBD/Vm0d1veb6gUK8KPUZKU4Xu2Rua5lNsracthLuYdpWMnTQBDe0Sburn2gyFXjQM17oOl48fdVmE/69ScYT2/BL6QVqXFGCewmR1DO4iYV4LnZ3tPL9JutSGDIB4bOiF1B6M0JwSokHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604310370; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IK1UbCDVMNVdRXGYuXV6aSKs+hJPcnWhGBfXyxv74j8=; b=F7X0EyDndZ0di8GBob35TTeA5EZt5ZQcIpIa0PLsXI3YVKx0EyARA2fN7cLI/EQ8ta332eucRfZsu2Vsm7HXXdlN+qVXdUy+tm8RoxDfxnye/xqoAKFiXF8AuA484AcNnA6yrdG9++8u+oECrO8diep9UvKEZprM+Hgp6XmudiI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604310370922385.4206304841649; Mon, 2 Nov 2020 01:46:10 -0800 (PST) Received: from localhost ([::1]:41380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZWPh-00045G-NO for importer@patchew.org; Mon, 02 Nov 2020 04:46:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48234) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWOD-0002Om-Ld for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41055) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZWOB-000574-S6 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:37 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-524-ldMBKgtoPXOVoW3oDdlbIA-1; Mon, 02 Nov 2020 04:44:32 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D87671084C88; Mon, 2 Nov 2020 09:44:31 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 668256EF5A; Mon, 2 Nov 2020 09:44:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DF1BC11329AB; Mon, 2 Nov 2020 10:44:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604310274; 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=IK1UbCDVMNVdRXGYuXV6aSKs+hJPcnWhGBfXyxv74j8=; b=dM+aRuHzPTByDpPpw98ZaaWicf6hr0KaXXOtMWXzqMzR102mmqXvQSZGxDwt73oiQmdXTr YAl0wrGF9anr22E+HXocvJ9OGFlrQcx8eT45m2jzJKnaBGliFLrJePLDWRojq929VTSQGz QHFfq+5B/Dz+3+djVjimJZ6W9vXgQuo= X-MC-Unique: ldMBKgtoPXOVoW3oDdlbIA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 01/11] test-util-sockets: Plug file descriptor leak Date: Mon, 2 Nov 2020 10:44:12 +0100 Message-Id: <20201102094422.173975-2-armbru@redhat.com> In-Reply-To: <20201102094422.173975-1-armbru@redhat.com> References: <20201102094422.173975-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 03:02:24 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, zxq_yx_007@163.com, kraxel@redhat.com, pbonzini@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Fixes: 4d3a329af59ef8acd076f99f05e82531d8129b34 Reviewed-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/test-util-sockets.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index f6336e0f91..15da867b8f 100644 --- a/tests/test-util-sockets.c +++ b/tests/test-util-sockets.c @@ -252,6 +252,7 @@ static gpointer unix_server_thread_func(gpointer user_d= ata) =20 connfd =3D accept(fd, (struct sockaddr *)&un, &len); g_assert_cmpint(connfd, !=3D, -1); + close(connfd); =20 close(fd); =20 --=20 2.26.2 From nobody Fri May 17 11:28:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604310364; cv=none; d=zohomail.com; s=zohoarc; b=hPXY8yVbFaJahD3sm/c8fqYbGXOsalWaTycWbc1GCI8y4osii6432SMm9bf6L5oJsiJbMKUW8ikR1cTqznxXZL3E4z+1XfvWEu6g+UEDGG19lC59+cmFQMwQLiVAU+8xW1/swAT54FM7e3WDVaK/PpNieyTnKvPtMQhj+Iei9yU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604310364; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hY3XoHDJm32PZi7BwJLzO4ic4jZo8hY8HxWuZY+w1x4=; b=bEz2b47Q6pI3rATcv3OVnkv1Rvpm4TG0HuyQ0BwQvD2nRjjr8NwmMLaZtvSPBex1nVtne7/LfrlJZhh/+yA87Erf3seNur9yhfaG40HZ2eoS1BP/8BxH0c3/YReInX18we2tgB/HZknJoyDV1ktqIKZGkLslieGQBOwU7H0LOFY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604310364591919.4377416693608; Mon, 2 Nov 2020 01:46:04 -0800 (PST) Received: from localhost ([::1]:41192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZWPb-00040H-9o for importer@patchew.org; Mon, 02 Nov 2020 04:46:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWOC-0002Oa-Q2 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47573) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZWOA-00056B-Pn for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:35 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-571-99FV2V9uMWmA_TGSzaU8Pw-1; Mon, 02 Nov 2020 04:44:32 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 04870809DC7; Mon, 2 Nov 2020 09:44:31 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6DB22672C0; Mon, 2 Nov 2020 09:44:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E20601132921; Mon, 2 Nov 2020 10:44:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604310273; 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=hY3XoHDJm32PZi7BwJLzO4ic4jZo8hY8HxWuZY+w1x4=; b=AYIrmWtoZtOcUnLshx3/shJ2IqSiychAaCk+5VQGZ0zXyhgSJfXF60QvpcgSXUE2ah4ehI Ri6S8WNFEtxvzfSMMkqO75tGT27Kyl5GJ5i0IP4qXTARF5DqN6cUcXaGOlL2XLykorjhmx 2aaAwKW+PUx+Q7nq4lnROd3pMEI5AZk= X-MC-Unique: 99FV2V9uMWmA_TGSzaU8Pw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 02/11] test-util-sockets: Correct to set has_abstract, has_tight Date: Mon, 2 Nov 2020 10:44:13 +0100 Message-Id: <20201102094422.173975-3-armbru@redhat.com> In-Reply-To: <20201102094422.173975-1-armbru@redhat.com> References: <20201102094422.173975-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 01:33:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, zxq_yx_007@163.com, kraxel@redhat.com, pbonzini@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The code tested doesn't care, which is a bug I will fix shortly. Reviewed-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- tests/test-util-sockets.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index 15da867b8f..9d317e73a6 100644 --- a/tests/test-util-sockets.c +++ b/tests/test-util-sockets.c @@ -243,7 +243,9 @@ static gpointer unix_server_thread_func(gpointer user_d= ata) =20 addr.type =3D SOCKET_ADDRESS_TYPE_UNIX; addr.u.q_unix.path =3D abstract_sock_name; + addr.u.q_unix.has_tight =3D true; addr.u.q_unix.tight =3D user_data !=3D NULL; + addr.u.q_unix.has_abstract =3D true; addr.u.q_unix.abstract =3D true; =20 fd =3D socket_listen(&addr, 1, &err); @@ -267,7 +269,9 @@ static gpointer unix_client_thread_func(gpointer user_d= ata) =20 addr.type =3D SOCKET_ADDRESS_TYPE_UNIX; addr.u.q_unix.path =3D abstract_sock_name; + addr.u.q_unix.has_tight =3D true; addr.u.q_unix.tight =3D user_data !=3D NULL; + addr.u.q_unix.has_abstract =3D true; addr.u.q_unix.abstract =3D true; =20 fd =3D socket_connect(&addr, &err); --=20 2.26.2 From nobody Fri May 17 11:28:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604310548; cv=none; d=zohomail.com; s=zohoarc; b=GBn0MZDjxNan8WeVEml/SohzFj99jdBJ9VNGultxmtoHM+2Zf7W6cf0pNWzkxpvEjs3QsLSj/Bhfwd5ami1fbRvca6Rme84vpfOHnt7itwWRgF5/kV/qvE4bGj+BHIlog+26I9XQtL/Qgb7SnrF0vdmgW73sYAEWEuqM+3zcLjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604310548; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ae27WkkwiXr5ic2lnHTALeNXJ0LRY3hWQtpZOFncLxk=; b=mw9LFFJMPqr/So9AU5QusuWmYBqJSBRKEz+PvfONGdgXhR51Ok/8J2pKwy19nn6CzQy6LV8XYGpP6B4oMJNDVyPOqNenQltAxKZsXh9FaGr35ta9fuQBsXD9ieLjH1VXBD4AoO+reKXFpd6Da6opVBKMwtlBXGHoIBdlhUOCGMs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604310548389810.9334707173387; Mon, 2 Nov 2020 01:49:08 -0800 (PST) Received: from localhost ([::1]:49756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZWSZ-0007Y9-7Z for importer@patchew.org; Mon, 02 Nov 2020 04:49:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWOF-0002Ro-6e for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49071) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZWOB-000571-PJ for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:38 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-583-mwNJzn2_OYiXMneLBC7Txw-1; Mon, 02 Nov 2020 04:44:32 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C6E8802B56; Mon, 2 Nov 2020 09:44:31 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6DB831002C18; Mon, 2 Nov 2020 09:44:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E5BC71132780; Mon, 2 Nov 2020 10:44:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604310274; 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=Ae27WkkwiXr5ic2lnHTALeNXJ0LRY3hWQtpZOFncLxk=; b=PQky8VHAlm3XTkpvhdM8Fu3JqSV85XhR8q+mKeItHJ2u7g8H0yAdQEYZ8TkNxk8BEsicGW 8aPwN7a9xrBSfCPhgzDymhNSVhQmqbbC1AkyoSMPfV7FdEsZT+0rzQ22F7RV3kwsSdiMGg SdFXQtaNE8PRAGWUtetyS9t/fW4gD9Q= X-MC-Unique: mwNJzn2_OYiXMneLBC7Txw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 03/11] test-util-sockets: Clean up SocketAddress construction Date: Mon, 2 Nov 2020 10:44:14 +0100 Message-Id: <20201102094422.173975-4-armbru@redhat.com> In-Reply-To: <20201102094422.173975-1-armbru@redhat.com> References: <20201102094422.173975-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 01:33:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, zxq_yx_007@163.com, kraxel@redhat.com, pbonzini@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The thread functions build the SocketAddress from global variable @abstract_sock_name and the tight flag passed as pointer argument (either NULL or (gpointer)1). There is no need for such hackery; simply pass the SocketAddress instead. While there, dumb down g_rand_int_range() to g_random_int(). Reviewed-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- tests/test-util-sockets.c | 64 ++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index 9d317e73a6..a4792253ba 100644 --- a/tests/test-util-sockets.c +++ b/tests/test-util-sockets.c @@ -230,25 +230,15 @@ static void test_socket_fd_pass_num_nocli(void) #endif =20 #ifdef __linux__ -static gchar *abstract_sock_name; - static gpointer unix_server_thread_func(gpointer user_data) { - SocketAddress addr; - Error *err =3D NULL; - int fd =3D -1; - int connfd =3D -1; + SocketAddress *addr =3D user_data; + int fd; + int connfd; struct sockaddr_un un; socklen_t len =3D sizeof(un); =20 - addr.type =3D SOCKET_ADDRESS_TYPE_UNIX; - addr.u.q_unix.path =3D abstract_sock_name; - addr.u.q_unix.has_tight =3D true; - addr.u.q_unix.tight =3D user_data !=3D NULL; - addr.u.q_unix.has_abstract =3D true; - addr.u.q_unix.abstract =3D true; - - fd =3D socket_listen(&addr, 1, &err); + fd =3D socket_listen(addr, 1, &error_abort); g_assert_cmpint(fd, >=3D, 0); g_assert(fd_is_socket(fd)); =20 @@ -257,69 +247,67 @@ static gpointer unix_server_thread_func(gpointer user= _data) close(connfd); =20 close(fd); - return NULL; } =20 static gpointer unix_client_thread_func(gpointer user_data) { - SocketAddress addr; - Error *err =3D NULL; - int fd =3D -1; - - addr.type =3D SOCKET_ADDRESS_TYPE_UNIX; - addr.u.q_unix.path =3D abstract_sock_name; - addr.u.q_unix.has_tight =3D true; - addr.u.q_unix.tight =3D user_data !=3D NULL; - addr.u.q_unix.has_abstract =3D true; - addr.u.q_unix.abstract =3D true; - - fd =3D socket_connect(&addr, &err); + SocketAddress *addr =3D user_data; + int fd; =20 + fd =3D socket_connect(addr, &error_abort); g_assert_cmpint(fd, >=3D, 0); - close(fd); - return NULL; } =20 static void test_socket_unix_abstract_good(void) { - GRand *r =3D g_rand_new(); + SocketAddress addr; =20 - abstract_sock_name =3D g_strdup_printf("unix-%d-%d", getpid(), - g_rand_int_range(r, 100, 1000)); + addr.type =3D SOCKET_ADDRESS_TYPE_UNIX; + addr.u.q_unix.path =3D g_strdup_printf("unix-%d-%u", + getpid(), g_random_int()); + addr.u.q_unix.has_abstract =3D true; + addr.u.q_unix.abstract =3D true; =20 /* non tight socklen serv and cli */ + + addr.u.q_unix.has_tight =3D false; + addr.u.q_unix.tight =3D false; + GThread *serv =3D g_thread_new("abstract_unix_server", unix_server_thread_func, - NULL); + &addr); =20 sleep(1); =20 GThread *cli =3D g_thread_new("abstract_unix_client", unix_client_thread_func, - NULL); + &addr); =20 g_thread_join(cli); g_thread_join(serv); =20 /* tight socklen serv and cli */ + + addr.u.q_unix.has_tight =3D true; + addr.u.q_unix.tight =3D true; + serv =3D g_thread_new("abstract_unix_server", unix_server_thread_func, - (gpointer)1); + &addr); =20 sleep(1); =20 cli =3D g_thread_new("abstract_unix_client", unix_client_thread_func, - (gpointer)1); + &addr); =20 g_thread_join(cli); g_thread_join(serv); =20 - g_free(abstract_sock_name); - g_rand_free(r); + g_free(addr.u.q_unix.path); } #endif =20 --=20 2.26.2 From nobody Fri May 17 11:28:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604310386; cv=none; d=zohomail.com; s=zohoarc; b=fnkHR+SsORRvQUpCcZL9Bl8CAMg6ULuc1wscfLZko9g5s4sKf9F9QRTuGkkPRSN3QttZPS6H8MGi8tjpKUPNwC8ABYrcUzLFs8x5FKHZci+hEqjV/lbnrfOAGoJhMX6FH6UVYDr/o1ZOl8n3krASHJVS87exSXZsZEbseEIOrYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604310386; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xXuXJxjnqhtxag+DQM4whHUnRMOzZMsKydCxNqulPqU=; b=PKrWxyhNNdwEXznJkOa7iPq4u4Lz/prFBfl0nHF47Z5r+K0H/UP/J9G9NSA+j3SiT9qu8bZW3pC3HIp3E4NWIqHXOvGhFg7WbaESwMgHmr1atHgwReH94t35Qp/RZhldwWWkpYcznZDhYSltNWZc7hNdpK3MLltNnXBxNiPwa7g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604310386186499.93182980283325; Mon, 2 Nov 2020 01:46:26 -0800 (PST) Received: from localhost ([::1]:41772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZWPw-0004HV-Vi for importer@patchew.org; Mon, 02 Nov 2020 04:46:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWOF-0002UY-Oe for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZWOC-00057K-DA for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:39 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-215-BMrEG41CMzix5p9Yp3LrWg-1; Mon, 02 Nov 2020 04:44:34 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 464CD1006C8D; Mon, 2 Nov 2020 09:44:33 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6F66C21E91; Mon, 2 Nov 2020 09:44:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E8DA01129947; Mon, 2 Nov 2020 10:44:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604310275; 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=xXuXJxjnqhtxag+DQM4whHUnRMOzZMsKydCxNqulPqU=; b=EJr3/ZSLWvkKCkTeHLsyBonrX02wRBjQbCfXYv5lB8kG/ElezDXH12FBvOLSLlYQMuOC46 GTEwIV7E315ZV+3hL+v3KIjNj/uBsf1JZ/CGrvod3TG6khC1RWQoOidrZSkOtNhWRAsyra REpTWcxDTk8HzYz7ZzX0HSpuTDbxYCg= X-MC-Unique: BMrEG41CMzix5p9Yp3LrWg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 04/11] test-util-sockets: Factor out test_socket_unix_abstract_one() Date: Mon, 2 Nov 2020 10:44:15 +0100 Message-Id: <20201102094422.173975-5-armbru@redhat.com> In-Reply-To: <20201102094422.173975-1-armbru@redhat.com> References: <20201102094422.173975-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 01:33:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, zxq_yx_007@163.com, kraxel@redhat.com, pbonzini@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Reviewed-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- tests/test-util-sockets.c | 48 ++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index a4792253ba..40ff893e64 100644 --- a/tests/test-util-sockets.c +++ b/tests/test-util-sockets.c @@ -261,6 +261,24 @@ static gpointer unix_client_thread_func(gpointer user_= data) return NULL; } =20 +static void test_socket_unix_abstract_one(SocketAddress *addr) +{ + GThread *serv, *cli; + + serv =3D g_thread_new("abstract_unix_server", + unix_server_thread_func, + addr); + + sleep(1); + + cli =3D g_thread_new("abstract_unix_client", + unix_client_thread_func, + addr); + + g_thread_join(cli); + g_thread_join(serv); +} + static void test_socket_unix_abstract_good(void) { SocketAddress addr; @@ -272,40 +290,14 @@ static void test_socket_unix_abstract_good(void) addr.u.q_unix.abstract =3D true; =20 /* non tight socklen serv and cli */ - addr.u.q_unix.has_tight =3D false; addr.u.q_unix.tight =3D false; - - GThread *serv =3D g_thread_new("abstract_unix_server", - unix_server_thread_func, - &addr); - - sleep(1); - - GThread *cli =3D g_thread_new("abstract_unix_client", - unix_client_thread_func, - &addr); - - g_thread_join(cli); - g_thread_join(serv); + test_socket_unix_abstract_one(&addr); =20 /* tight socklen serv and cli */ - addr.u.q_unix.has_tight =3D true; addr.u.q_unix.tight =3D true; - - serv =3D g_thread_new("abstract_unix_server", - unix_server_thread_func, - &addr); - - sleep(1); - - cli =3D g_thread_new("abstract_unix_client", - unix_client_thread_func, - &addr); - - g_thread_join(cli); - g_thread_join(serv); + test_socket_unix_abstract_one(&addr); =20 g_free(addr.u.q_unix.path); } --=20 2.26.2 From nobody Fri May 17 11:28:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604310546; cv=none; d=zohomail.com; s=zohoarc; b=jpVINtwD06F81i7ra6bgjlXCfvfr2Ntrhli+dd+3KsYGRpFuHB45JxQh6cjcB4Jml9EVPONhebscYCb7TBvPM31K4K4JmPLpIG3Pl/UEHwFJZH9LIbN1SVIS8ojsvT7srWmbAA95k4yOsrZwZyLNFENcmc9ieZlKBke/nx8h6lk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604310546; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=p/OgfYQh8HJzQ0t4tZ94KeAjaQks7kVAngJOMp4dio0=; b=nbjJiCd+EP+o73EdtJ5UyuVB7xz3Y+a63/fpNb5T66tpuxTMBB681yt2g5FBVuANMqX3usfIbWQauzSw0PpiSg+XGyw3HiIb6Sf39eT5DgGQxaXVo9xPAIV3o63nWfAJzF9HC7ISPurpbsTz/e8JbL4EqJQTwmzDs7HdSVpcf7Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160431054677599.60999696246904; Mon, 2 Nov 2020 01:49:06 -0800 (PST) Received: from localhost ([::1]:49630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZWSX-0007VD-Au for importer@patchew.org; Mon, 02 Nov 2020 04:49:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWOK-0002dK-N5 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51422) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZWOI-00059k-8h for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:44 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-295-Vm2UiXZgNcKH1FUzenY-vw-1; Mon, 02 Nov 2020 04:44:39 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 049E457203; Mon, 2 Nov 2020 09:44:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B77955D9DD; Mon, 2 Nov 2020 09:44:31 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id EBF28116B844; Mon, 2 Nov 2020 10:44:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604310280; 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=p/OgfYQh8HJzQ0t4tZ94KeAjaQks7kVAngJOMp4dio0=; b=ap2PHXQPqdNTXwAopPODK09jIES8yGBg1STbQQdu4b6tO55/UjrsWXatzhHJF0SABJzoMg WT/E6Wy0XRsxXcoaNu4NaHABC3hhgHG6/+UK+S9scKYhdl3pLN8vcbBmf3TQHpGoMZ09PP iIVoc1380Hjgrn1OQvQakjjNRpcb7Ew= X-MC-Unique: Vm2UiXZgNcKH1FUzenY-vw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 05/11] test-util-sockets: Synchronize properly, don't sleep(1) Date: Mon, 2 Nov 2020 10:44:16 +0100 Message-Id: <20201102094422.173975-6-armbru@redhat.com> In-Reply-To: <20201102094422.173975-1-armbru@redhat.com> References: <20201102094422.173975-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 01:33:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, zxq_yx_007@163.com, kraxel@redhat.com, pbonzini@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The abstract sockets test spawns a thread to listen and accept, and a second one to connect, with a sleep(1) in between to "ensure" the former is listening when the latter tries to connect. Review fail. Risks spurious test failure, say when a heavily loaded machine doesn't schedule the first thread quickly enough. It's also slow. Listen and accept in the main thread, and start the connect thread in between. Look ma, no sleep! Run time drops from 2s wall clock to a few milliseconds. Reviewed-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- tests/test-util-sockets.c | 40 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index 40ff893e64..4cedf622f0 100644 --- a/tests/test-util-sockets.c +++ b/tests/test-util-sockets.c @@ -230,26 +230,6 @@ static void test_socket_fd_pass_num_nocli(void) #endif =20 #ifdef __linux__ -static gpointer unix_server_thread_func(gpointer user_data) -{ - SocketAddress *addr =3D user_data; - int fd; - int connfd; - struct sockaddr_un un; - socklen_t len =3D sizeof(un); - - fd =3D socket_listen(addr, 1, &error_abort); - g_assert_cmpint(fd, >=3D, 0); - g_assert(fd_is_socket(fd)); - - connfd =3D accept(fd, (struct sockaddr *)&un, &len); - g_assert_cmpint(connfd, !=3D, -1); - close(connfd); - - close(fd); - return NULL; -} - static gpointer unix_client_thread_func(gpointer user_data) { SocketAddress *addr =3D user_data; @@ -263,20 +243,26 @@ static gpointer unix_client_thread_func(gpointer user= _data) =20 static void test_socket_unix_abstract_one(SocketAddress *addr) { - GThread *serv, *cli; + int fd, connfd; + GThread *cli; + struct sockaddr_un un; + socklen_t len =3D sizeof(un); =20 - serv =3D g_thread_new("abstract_unix_server", - unix_server_thread_func, - addr); - - sleep(1); + fd =3D socket_listen(addr, 1, &error_abort); + g_assert_cmpint(fd, >=3D, 0); + g_assert(fd_is_socket(fd)); =20 cli =3D g_thread_new("abstract_unix_client", unix_client_thread_func, addr); =20 + connfd =3D accept(fd, (struct sockaddr *)&un, &len); + g_assert_cmpint(connfd, !=3D, -1); + close(connfd); + + close(fd); + g_thread_join(cli); - g_thread_join(serv); } =20 static void test_socket_unix_abstract_good(void) --=20 2.26.2 From nobody Fri May 17 11:28:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604310547; cv=none; d=zohomail.com; s=zohoarc; b=U4vr4nvs0xWnXZpVxBS0D0axUH3VXTcx7ovkSAfTy7HX1OjLw2EpuFP3N+fGtXArbPMNQJEvbN0fNHGr0SCsJYq3Td6RI+J4XXVrsV60VZbx3MGMaiZdzrhjQuOud90bveEIg7vNtSmIS59B6DgAdWIAR487F+8TjGbWXjWtWhs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604310547; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lXnQT5h2UgcAD43AxZjNT4Zw1mh8mjKq2nquGQWvbVg=; b=G1szx2rMdkuV8shEJTMymra/waMVtimCMxjABUEGw5+B0hKolctfc92Lb+nGNS4+maYix5xnATyhkmkL2GgZGKuOTFhRseyF2FisJcZovj2jvJEPl//q4iayRh5k9InvQYNZ5jIRRRrpkOVEExD2rRdnjJJHt0YvlSvVC20fuZI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604310547426929.06193402882; Mon, 2 Nov 2020 01:49:07 -0800 (PST) Received: from localhost ([::1]:49648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZWSY-0007VS-2R for importer@patchew.org; Mon, 02 Nov 2020 04:49:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWOD-0002P5-Vr for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:53994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZWOB-000578-S1 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:37 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-596-ZTE4UUAHPKCkchONjGQ8iQ-1; Mon, 02 Nov 2020 04:44:33 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B61657208; Mon, 2 Nov 2020 09:44:32 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B76251002C18; Mon, 2 Nov 2020 09:44:31 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id EF48410EE54F; Mon, 2 Nov 2020 10:44:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604310275; 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=lXnQT5h2UgcAD43AxZjNT4Zw1mh8mjKq2nquGQWvbVg=; b=Ru5Rxrt0+8++LkLP8M4lcYq7E99lpLRKIXUNqLTic0IXMZkVL1EheKLAXMf2viCfP88Fjk 3cniRDbIC9Te5rd1Wm66TYpqFCAO9LCdaWyKbuIIMl0B+KdkW9jLyTGi2HtIlQZhxRG7FZ T+1g5YVq1aLzBtK9HT3hb/eh782fHCE= X-MC-Unique: ZTE4UUAHPKCkchONjGQ8iQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 06/11] test-util-sockets: Test the complete abstract socket matrix Date: Mon, 2 Nov 2020 10:44:17 +0100 Message-Id: <20201102094422.173975-7-armbru@redhat.com> In-Reply-To: <20201102094422.173975-1-armbru@redhat.com> References: <20201102094422.173975-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 03:02:24 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, zxq_yx_007@163.com, kraxel@redhat.com, pbonzini@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The test covers only two out of nine combinations. Test all nine. Four turn out to be broken. Marked /* BUG */. Reviewed-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- tests/test-util-sockets.c | 87 ++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 24 deletions(-) diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index 4cedf622f0..f8b6586e70 100644 --- a/tests/test-util-sockets.c +++ b/tests/test-util-sockets.c @@ -230,60 +230,99 @@ static void test_socket_fd_pass_num_nocli(void) #endif =20 #ifdef __linux__ + +#define ABSTRACT_SOCKET_VARIANTS 3 + +typedef struct { + SocketAddress *server, *client[ABSTRACT_SOCKET_VARIANTS]; + bool expect_connect[ABSTRACT_SOCKET_VARIANTS]; +} abstract_socket_matrix_row; + static gpointer unix_client_thread_func(gpointer user_data) { - SocketAddress *addr =3D user_data; - int fd; + abstract_socket_matrix_row *row =3D user_data; + Error *err =3D NULL; + int i, fd; =20 - fd =3D socket_connect(addr, &error_abort); - g_assert_cmpint(fd, >=3D, 0); - close(fd); + for (i =3D 0; i < ABSTRACT_SOCKET_VARIANTS; i++) { + if (row->expect_connect[i]) { + fd =3D socket_connect(row->client[i], &error_abort); + g_assert_cmpint(fd, >=3D, 0); + } else { + fd =3D socket_connect(row->client[i], &err); + g_assert_cmpint(fd, =3D=3D, -1); + error_free_or_abort(&err); + } + close(fd); + } return NULL; } =20 -static void test_socket_unix_abstract_one(SocketAddress *addr) +static void test_socket_unix_abstract_row(abstract_socket_matrix_row *test) { - int fd, connfd; + int fd, connfd, i; GThread *cli; struct sockaddr_un un; socklen_t len =3D sizeof(un); =20 - fd =3D socket_listen(addr, 1, &error_abort); + /* Last one must connect, or else accept() below hangs */ + assert(test->expect_connect[ABSTRACT_SOCKET_VARIANTS - 1]); + + fd =3D socket_listen(test->server, 1, &error_abort); g_assert_cmpint(fd, >=3D, 0); g_assert(fd_is_socket(fd)); =20 cli =3D g_thread_new("abstract_unix_client", unix_client_thread_func, - addr); + test); =20 - connfd =3D accept(fd, (struct sockaddr *)&un, &len); - g_assert_cmpint(connfd, !=3D, -1); - close(connfd); + for (i =3D 0; i < ABSTRACT_SOCKET_VARIANTS; i++) { + if (test->expect_connect[i]) { + connfd =3D accept(fd, (struct sockaddr *)&un, &len); + g_assert_cmpint(connfd, !=3D, -1); + close(connfd); + } + } =20 close(fd); - g_thread_join(cli); } =20 -static void test_socket_unix_abstract_good(void) +static void test_socket_unix_abstract(void) { - SocketAddress addr; + SocketAddress addr, addr_tight, addr_padded; + abstract_socket_matrix_row matrix[ABSTRACT_SOCKET_VARIANTS] =3D { + { &addr, + { &addr_tight, &addr_padded, &addr }, + { false /* BUG */, true /* BUG */, true } }, + { &addr_tight, + { &addr_padded, &addr, &addr_tight }, + { false, false /* BUG */, true } }, + { &addr_padded, + { &addr, &addr_tight, &addr_padded }, + { true /* BUG */, false, true } } + }; + int i; =20 addr.type =3D SOCKET_ADDRESS_TYPE_UNIX; addr.u.q_unix.path =3D g_strdup_printf("unix-%d-%u", getpid(), g_random_int()); addr.u.q_unix.has_abstract =3D true; addr.u.q_unix.abstract =3D true; - - /* non tight socklen serv and cli */ addr.u.q_unix.has_tight =3D false; addr.u.q_unix.tight =3D false; - test_socket_unix_abstract_one(&addr); =20 - /* tight socklen serv and cli */ - addr.u.q_unix.has_tight =3D true; - addr.u.q_unix.tight =3D true; - test_socket_unix_abstract_one(&addr); + addr_tight =3D addr; + addr_tight.u.q_unix.has_tight =3D true; + addr_tight.u.q_unix.tight =3D true; + + addr_padded =3D addr; + addr_padded.u.q_unix.has_tight =3D true; + addr_padded.u.q_unix.tight =3D false; + + for (i =3D 0; i < ABSTRACT_SOCKET_VARIANTS; i++) { + test_socket_unix_abstract_row(&matrix[i]); + } =20 g_free(addr.u.q_unix.path); } @@ -330,8 +369,8 @@ int main(int argc, char **argv) } =20 #ifdef __linux__ - g_test_add_func("/util/socket/unix-abstract/good", - test_socket_unix_abstract_good); + g_test_add_func("/util/socket/unix-abstract", + test_socket_unix_abstract); #endif =20 end: --=20 2.26.2 From nobody Fri May 17 11:28:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604310677; cv=none; d=zohomail.com; s=zohoarc; b=hqTuYKbySCiFGQM/OK8owcZ75EHHtpvItnwGmJ5UYMPrNVXtLytDiuX1qxZDfRT0FSyGuHnAW1nkFmKCSi0RZu9Vkswtku6W1cZHHK5zHOizzemIegVvxayeG2BPRmtteVGVsEVd49TwL47nTyXwurcrna9b3jIeJz1/t45f9Os= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604310677; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RWvryq08NcB4Nl9MnYRr9FOaHhm8prTyZgfoOzlkUMs=; b=jRt0WJNOahe9LBmf4oS/629D/DWcE8O7H13J7p9mdEyXGTFfHqmazCflOKrjbI6fvgOsosz0o8D5kmxT8rNsgi50M4HiptGxYeLeg1dfYnG8jfi2xBSZ0ciBddsshGcZVf6Qix5PuLhLlY4kKZF+OyG6EaYcV2V4tmOif9Dp//0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604310677552489.4649617868231; Mon, 2 Nov 2020 01:51:17 -0800 (PST) Received: from localhost ([::1]:58042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZWUe-0002Vt-Fq for importer@patchew.org; Mon, 02 Nov 2020 04:51:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWOJ-0002d1-Q1 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58740) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZWOI-00059h-2A for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:43 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-523-_S_ZMJYEPoOHFIUQS_IHOA-1; Mon, 02 Nov 2020 04:44:39 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C59331868401; Mon, 2 Nov 2020 09:44:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 431E35B4D6; Mon, 2 Nov 2020 09:44:32 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F27F210EE550; Mon, 2 Nov 2020 10:44:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604310281; 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=RWvryq08NcB4Nl9MnYRr9FOaHhm8prTyZgfoOzlkUMs=; b=KX74oPrskUaMC7JeqQfwPsA7jUEOstaUEOEpUgndmkEL4irZEjLDa8BjGLwlO58Ey8AR6C SgH4/jLSAupFwTn/axd6gegJBpPmB7ViHNO5CBCXtFJA/Fu6Rl+MTTqg4isIebPssDO0Gk NDH5psz5hZuzowHZeU8OIPfHIhej6/0= X-MC-Unique: _S_ZMJYEPoOHFIUQS_IHOA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 07/11] sockets: Fix default of UnixSocketAddress member @tight Date: Mon, 2 Nov 2020 10:44:18 +0100 Message-Id: <20201102094422.173975-8-armbru@redhat.com> In-Reply-To: <20201102094422.173975-1-armbru@redhat.com> References: <20201102094422.173975-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 01:33:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, zxq_yx_007@163.com, kraxel@redhat.com, pbonzini@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" An optional bool member of a QAPI struct can be false, true, or absent. The previous commit demonstrated that socket_listen() and socket_connect() are broken for absent @tight, and indeed QMP chardev- add also defaults absent member @tight to false instead of true. In C, QAPI members are represented by two fields, has_MEMBER and MEMBER. We have: has_MEMBER MEMBER false true false true true true absent false false/ignore When has_MEMBER is false, MEMBER should be set to false on write, and ignored on read. For QMP, the QAPI visitors handle absent @tight by setting both @has_tight and @tight to false. unix_listen_saddr() and unix_connect_saddr() however use @tight only, disregarding @has_tight. This is wrong and means that absent @tight defaults to false whereas it should default to true. The same is true for @has_abstract, though @abstract defaults to false and therefore has the same behavior for all of QMP, HMP and CLI. Fix unix_listen_saddr() and unix_connect_saddr() to check @has_abstract/@has_tight, and to default absent @tight to true. However, this is only half of the story. HMP chardev-add and CLI -chardev so far correctly defaulted @tight to true, but defaults to false again with the above fix for HMP and CLI. In fact, the "tight" and "abstract" options now break completely. Digging deeper, we find that qemu_chr_parse_socket() also ignores @has_tight, leaving it false when it sets @tight. That is also wrong, but the two wrongs cancelled out. Fix qemu_chr_parse_socket() to set @has_tight and @has_abstract; writing testcases for HMP and CLI is left for another day. Fixes: 776b97d3605ed0fc94443048fdf988c7725e38a9 Reported-by: Kevin Wolf Reviewed-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- chardev/char-socket.c | 2 ++ tests/test-util-sockets.c | 6 +++--- util/qemu-sockets.c | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 95e45812d5..1ee5a8c295 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -1439,7 +1439,9 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Cha= rdevBackend *backend, addr->type =3D SOCKET_ADDRESS_LEGACY_KIND_UNIX; q_unix =3D addr->u.q_unix.data =3D g_new0(UnixSocketAddress, 1); q_unix->path =3D g_strdup(path); + q_unix->has_tight =3D true; q_unix->tight =3D tight; + q_unix->has_abstract =3D true; q_unix->abstract =3D abstract; } else if (host) { addr->type =3D SOCKET_ADDRESS_LEGACY_KIND_INET; diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index f8b6586e70..7ecf95579b 100644 --- a/tests/test-util-sockets.c +++ b/tests/test-util-sockets.c @@ -294,13 +294,13 @@ static void test_socket_unix_abstract(void) abstract_socket_matrix_row matrix[ABSTRACT_SOCKET_VARIANTS] =3D { { &addr, { &addr_tight, &addr_padded, &addr }, - { false /* BUG */, true /* BUG */, true } }, + { true, false, true } }, { &addr_tight, { &addr_padded, &addr, &addr_tight }, - { false, false /* BUG */, true } }, + { false, true, true } }, { &addr_padded, { &addr, &addr_tight, &addr_padded }, - { true /* BUG */, false, true } } + { false, false, true } } }; int i; =20 diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 38f82179b0..3ceaa81226 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -925,7 +925,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, if (saddr->abstract) { un.sun_path[0] =3D '\0'; memcpy(&un.sun_path[1], path, pathlen); - if (saddr->tight) { + if (!saddr->has_tight || saddr->tight) { addrlen =3D offsetof(struct sockaddr_un, sun_path) + 1 + pathl= en; } } else { @@ -985,7 +985,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr,= Error **errp) if (saddr->abstract) { un.sun_path[0] =3D '\0'; memcpy(&un.sun_path[1], saddr->path, pathlen); - if (saddr->tight) { + if (!saddr->has_tight || saddr->tight) { addrlen =3D offsetof(struct sockaddr_un, sun_path) + 1 + pathl= en; } } else { --=20 2.26.2 From nobody Fri May 17 11:28:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604310676; cv=none; d=zohomail.com; s=zohoarc; b=MmeSjpvG2DHrdOut/IVS+YNaRVEOKYhVE4FB6hA2Vhr4eAQsHJf47t1UJ6lPyoNiydLOlHt1Wbv6Bz1iwce0ZarRTt1qBAd0VaeJLbBUPTbVKQy3Z19K5/aAJqr7qGf9OHCyKoHJXaK/1XsFRc8BHiGX6Gwx/1ZH75ii9rPzVEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604310676; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rwrmCu8Z+VToUL++7XlQwBDo0tZGAu+UOPIYYneNtSI=; b=RS/qWjg5XQYTNjPpJfLrDT3msfso7zmboTuoUu/sXdFcoDmHUK5R/KN/S724fdiR6fQ98Y3qj+1Rr3yeGUdbVq7fn1r88n9N+FHoNWWI+8vA0wLTH9FW8QiDHhS1xUUrFVS7FxlXWtJY1jFmul887gj8LxrzmNyDeIs5fVgLiME= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160431067671680.60934715026679; Mon, 2 Nov 2020 01:51:16 -0800 (PST) Received: from localhost ([::1]:57976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZWUd-0002TX-7r for importer@patchew.org; Mon, 02 Nov 2020 04:51:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48248) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWOE-0002QF-Gc for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:55705) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZWOC-00057I-Ky for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:38 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-540-63iiw2GlO52-XrIiRSPjhw-1; Mon, 02 Nov 2020 04:44:34 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44135186840E; Mon, 2 Nov 2020 09:44:33 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B47D1A8EC; Mon, 2 Nov 2020 09:44:32 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0170810EE551; Mon, 2 Nov 2020 10:44:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604310275; 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=rwrmCu8Z+VToUL++7XlQwBDo0tZGAu+UOPIYYneNtSI=; b=jVgSHDnZaSJnntjJsv0s11BrS6E9fGRAkxXgh8evrels9J7jygckKU1DZqiRVvkEgYU0Zf sCVIK0cpjji9n1PfAg+xYV0fBPhcupxWEMyysNJxHB/TahfZpUMvTwvUAmYsi5/9xALiDB IgEwHOyLZSguhMGvjEFhtIoVIpLdOtg= X-MC-Unique: 63iiw2GlO52-XrIiRSPjhw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 08/11] sockets: Fix socket_sockaddr_to_address_unix() for abstract sockets Date: Mon, 2 Nov 2020 10:44:19 +0100 Message-Id: <20201102094422.173975-9-armbru@redhat.com> In-Reply-To: <20201102094422.173975-1-armbru@redhat.com> References: <20201102094422.173975-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 03:02:24 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, zxq_yx_007@163.com, kraxel@redhat.com, pbonzini@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Commit 776b97d360 "qemu-sockets: add abstract UNIX domain socket support" neglected to update socket_sockaddr_to_address_unix(). The function returns a non-abstract socket address for abstract sockets (wrong) with a null @path (also wrong; a non-optional QAPI str member must never be null). The null @path is due to confused code going back all the way to commit 17c55decec "sockets: add helpers for creating SocketAddress from a socket". Add the required special case, and simplify the confused code. Fixes: 776b97d3605ed0fc94443048fdf988c7725e38a9 Reviewed-by: Paolo Bonzini Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- util/qemu-sockets.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 3ceaa81226..a578c434c2 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -1270,10 +1270,20 @@ socket_sockaddr_to_address_unix(struct sockaddr_sto= rage *sa, =20 addr =3D g_new0(SocketAddress, 1); addr->type =3D SOCKET_ADDRESS_TYPE_UNIX; - if (su->sun_path[0]) { - addr->u.q_unix.path =3D g_strndup(su->sun_path, sizeof(su->sun_pat= h)); +#ifdef CONFIG_LINUX + if (!su->sun_path[0]) { + /* Linux abstract socket */ + addr->u.q_unix.path =3D g_strndup(su->sun_path + 1, + sizeof(su->sun_path) - 1); + addr->u.q_unix.has_abstract =3D true; + addr->u.q_unix.abstract =3D true; + addr->u.q_unix.has_tight =3D true; + addr->u.q_unix.tight =3D salen < sizeof(*su); + return addr; } +#endif =20 + addr->u.q_unix.path =3D g_strndup(su->sun_path, sizeof(su->sun_path)); return addr; } #endif /* WIN32 */ --=20 2.26.2 From nobody Fri May 17 11:28:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604311039; cv=none; d=zohomail.com; s=zohoarc; b=QpIQHszVeL808vdKPqJmKGAKgIEHPlkA2NGgs9GO556PxSqnQAvM2WRrYVKNipV2hqYZam0Ihu0Dn+smH/RRtQ7ibw2nXIbX2yMJXGmKO2Z3htOR+IjgxtDNC6+x1upLz9g3ekaCHNNs6NKKbg39J7+e3h/ylLIvebfgq0Ueryo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604311039; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MJ+bR0S9I3uUQF4x01Hu0P8NqIp3ZV6fCFjp0WaP0RU=; b=j+fHGy7ckPnMPmovCBbbgJpV4MatNUh8NkXiOX8TafAluJZmxaiU0qQw3CsEic8miA1HRj5wD858OKZIa1HsD25GcOd7JG0/f7amidwGguJGiLBmwB9KP3+zDpSzBQSvxGuKo2Tko3U9vAlOU16aPg5NhJdBz4LSK68XWWSp6R4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604311039454415.18553417118324; Mon, 2 Nov 2020 01:57:19 -0800 (PST) Received: from localhost ([::1]:46608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZWaU-00015V-CY for importer@patchew.org; Mon, 02 Nov 2020 04:57:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWOM-0002gN-Dw for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35705) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZWOK-0005AW-Ph for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:46 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-337-xPbnmzOJOB6E17e7jHfNeg-1; Mon, 02 Nov 2020 04:44:40 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 21ADF809DC7; Mon, 2 Nov 2020 09:44:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DDB8F5C1BB; Mon, 2 Nov 2020 09:44:32 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 047A110EE552; Mon, 2 Nov 2020 10:44:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604310284; 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=MJ+bR0S9I3uUQF4x01Hu0P8NqIp3ZV6fCFjp0WaP0RU=; b=D4ajsf5uY4qgT/t6dem8+oxxEdbc9F5WSN5HU8N2XfcxlAV8LS6zq8YT/PWzQdGpT7MtJs Xo7SdT7QD4xe8bON5+KbystOZMQdlzBPvyvTKtbCb/7fyhBXmuxsOSKCIFVpCIk+SssveZ yw4I9QDs0mS3S5Xmemb2c2eveTW44Uc= X-MC-Unique: xPbnmzOJOB6E17e7jHfNeg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 09/11] char-socket: Fix qemu_chr_socket_address() for abstract sockets Date: Mon, 2 Nov 2020 10:44:20 +0100 Message-Id: <20201102094422.173975-10-armbru@redhat.com> In-Reply-To: <20201102094422.173975-1-armbru@redhat.com> References: <20201102094422.173975-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 01:33:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, zxq_yx_007@163.com, kraxel@redhat.com, pbonzini@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Commit 776b97d360 "qemu-sockets: add abstract UNIX domain socket support" neglected to update qemu_chr_socket_address(). It shows shows neither @abstract nor @tight. Fix that. Reviewed-by: Paolo Bonzini Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- chardev/char-socket.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 1ee5a8c295..dc1cf86ecf 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -443,10 +443,18 @@ static char *qemu_chr_socket_address(SocketChardev *s= , const char *prefix) s->is_listen ? ",server" : ""); break; case SOCKET_ADDRESS_TYPE_UNIX: - return g_strdup_printf("%sunix:%s%s", prefix, + { + UnixSocketAddress *sa =3D &s->addr->u.q_unix; + + return g_strdup_printf("%sunix:%s%s%s%s", prefix, s->addr->u.q_unix.path, + sa->has_abstract && sa->abstract + ? ",abstract" : "", + sa->has_tight && sa->tight + ? ",tight" : "", s->is_listen ? ",server" : ""); break; + } case SOCKET_ADDRESS_TYPE_FD: return g_strdup_printf("%sfd:%s%s", prefix, s->addr->u.fd.str, s->is_listen ? ",server" : ""); --=20 2.26.2 From nobody Fri May 17 11:28:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604310887; cv=none; d=zohomail.com; s=zohoarc; b=ioUBpWJx+/Wa05QnIasaeEV7h2dYIOAtjOpoX96tNHJ0tqJY0HlYyRc4I66NX+jAbDUnprrfwdvTM18ZB3wWI162vJIRO9tH+KQ9a/cUIQSuT7Pk22x8ry+tpLc5RgEaBIkQgQ3I8GBY3kp3vxe3Gz3C85LD/022tHBvT7Jpu14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604310887; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s/iTVRaIzOY/mgJ8/aSKhEmETvJffoG9bGnxnoeikeo=; b=WaXk8ayoChI01tuY0B0lc9lyHvdZpfexrm2ngzwXuD0Kd6ZvzTh2OJX+XVVe1VYfdh2eomd7BDPx3Ow2f1+FBYXHIeUG7MfSmKSTBCRTlrhcDK4GdMDLQc6KK8prtruE0tnmg2ilWwO3pxO9ZijyCjgkM6DGpiHTudLZnKfGg7M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604310887938275.6541627877866; Mon, 2 Nov 2020 01:54:47 -0800 (PST) Received: from localhost ([::1]:38162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZWY2-0005z0-JF for importer@patchew.org; Mon, 02 Nov 2020 04:54:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWOF-0002RM-0n for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59019) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZWOC-00057M-Oa for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:44:38 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-540-4KnofYrAPUyjUfrdBRRgbg-1; Mon, 02 Nov 2020 04:44:34 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 237698030C0; Mon, 2 Nov 2020 09:44:33 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E5A7060CCC; Mon, 2 Nov 2020 09:44:32 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0789210EE553; Mon, 2 Nov 2020 10:44:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604310275; 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=s/iTVRaIzOY/mgJ8/aSKhEmETvJffoG9bGnxnoeikeo=; b=Uar978yC8YojWI0QAAYzV0kljEGk9eaq8kEkjNX1+FCaZCxiDhrAZXkpi8vSSzrBvXzsiu 3CHS5zsqHn0HJhp9Gy7x7Lgjiit58rPqos8yCaN7UBDv0tEg0apIfyC765NpgdBaLZptV4 7U1vrs6UjZOKSibX/X4RIkHfFj4w2lI= X-MC-Unique: 4KnofYrAPUyjUfrdBRRgbg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 10/11] sockets: Bypass "replace empty @path" for abstract unix sockets Date: Mon, 2 Nov 2020 10:44:21 +0100 Message-Id: <20201102094422.173975-11-armbru@redhat.com> In-Reply-To: <20201102094422.173975-1-armbru@redhat.com> References: <20201102094422.173975-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 03:02:24 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, zxq_yx_007@163.com, kraxel@redhat.com, pbonzini@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" unix_listen_saddr() replaces empty @path by unique value. It obtains the value by creating and deleting a unique temporary file with mkstemp(). This is racy, as the comment explains. It's also entirely undocumented as far as I can tell. Goes back to commit d247d25f18 "sockets: helper functions for qemu (Gerd Hoffman)", v0.10.0. Since abstract socket addresses have no connection with filesystem pathnames, making them up with mkstemp() seems inappropriate. Bypass the replacement of empty @path. Reviewed-by: Eric Blake Reviewed-by: Paolo Bonzini Signed-off-by: Markus Armbruster --- util/qemu-sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index a578c434c2..671717499f 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -877,7 +877,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, return -1; } =20 - if (saddr->path && saddr->path[0]) { + if (saddr->path[0] || saddr->abstract) { path =3D saddr->path; } else { const char *tmpdir =3D getenv("TMPDIR"); --=20 2.26.2 From nobody Fri May 17 11:28:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604310688; cv=none; d=zohomail.com; s=zohoarc; b=T4VPcSpjhHmxWjwHbk+WvxG0d2iM5AhvDWJqasz2cUGC1VIdZI5mun3d8e0LfRxu471SyEZhgxLaFl/rwN6/u6k3MKBc8VJqZFSvYMR9sHKP+OYVibyWI/B28a6vTtJCuN/EIlP6WbBgPiqDApDxdueTijWO9r/g5rehPxC6XOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604310688; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lEOqmY0horA8tHnMnTB3VLfYBB5uxXeU66rFKkuaMuw=; b=Q1AgOsfhGTnT33mky11UcWBJCtjeIuT8UUjnSCcayyPvp7ia0DeHJL8LThJy1dH0DLOTKvqFFQIBvzET6yV4i+3F3k7gx7FuDKO/UoINIa7mclDwpfmgQlMVebuHuEj8faZ3Uu12d+zLd/7plM1tcKTxPXy0ZIQKLPkEZRZNaTE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604310688305273.00014705615433; Mon, 2 Nov 2020 01:51:28 -0800 (PST) Received: from localhost ([::1]:58798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZWUp-0002s8-1w for importer@patchew.org; Mon, 02 Nov 2020 04:51:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWOz-0003gA-Vc for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:45:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38028) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZWOx-0005Uf-M9 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 04:45:25 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-48-qcW6FDraMJSL8WnnupMMSg-1; Mon, 02 Nov 2020 04:44:39 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 28E33809DCB; Mon, 2 Nov 2020 09:44:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 242B95DA60; Mon, 2 Nov 2020 09:44:33 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0C17D10EE554; Mon, 2 Nov 2020 10:44:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604310322; 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=lEOqmY0horA8tHnMnTB3VLfYBB5uxXeU66rFKkuaMuw=; b=MsZ8yqzeFAf2M6qX8nPX9KVR40l85OjbI8y4gHgpG2l4NCvS4cEs5JHbu6QJmpSFF/k+xs ZTKnSq3ygC7xDu+f7hPqbl+TT6i0pyDiDFph+ePWvYF6K+Vfv+LF7Zu8sARaCWqgzXJbFh yWzo+3/K+yB46Iizt6hGqDKtRai4kME= X-MC-Unique: qcW6FDraMJSL8WnnupMMSg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 11/11] sockets: Make abstract UnixSocketAddress depend on CONFIG_LINUX Date: Mon, 2 Nov 2020 10:44:22 +0100 Message-Id: <20201102094422.173975-12-armbru@redhat.com> In-Reply-To: <20201102094422.173975-1-armbru@redhat.com> References: <20201102094422.173975-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 03:02:24 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, zxq_yx_007@163.com, kraxel@redhat.com, pbonzini@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The abstract socket namespace is a non-portable Linux extension. An attempt to use it elsewhere should fail with ENOENT (the abstract address looks like a "" pathname, which does not resolve). We report this failure like Failed to connect socket abc: No such file or directory Tolerable, although ENOTSUP would be better. However, introspection lies: it has @abstract regardless of host support. Easy enough to fix: since Linux provides them since 2.2, 'if': 'defined(CONFIG_LINUX)' should do. The above failure becomes Parameter 'backend.data.addr.data.abstract' is unexpected I consider this an improvement. Reviewed-by: Paolo Bonzini Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qapi/sockets.json | 14 ++++++++------ chardev/char-socket.c | 22 +++++++++++++++------ chardev/char.c | 2 ++ tests/test-util-sockets.c | 7 ++++--- util/qemu-sockets.c | 40 +++++++++++++++++++++++++++++---------- 5 files changed, 60 insertions(+), 25 deletions(-) diff --git a/qapi/sockets.json b/qapi/sockets.json index c0c640a5b0..2e83452797 100644 --- a/qapi/sockets.json +++ b/qapi/sockets.json @@ -74,18 +74,20 @@ # Captures a socket address in the local ("Unix socket") namespace. # # @path: filesystem path to use -# @tight: pass a socket address length confined to the minimum length of t= he -# abstract string, rather than the full sockaddr_un record length -# (only matters for abstract sockets, default true). (Since 5.1) -# @abstract: whether this is an abstract address, default false. (Since 5.= 1) +# @abstract: if true, this is a Linux abstract socket address. @path +# will be prefixed by a null byte, and optionally padded +# with null bytes. Defaults to false. (Since 5.1) +# @tight: if false, pad an abstract socket address with enough null +# bytes to make it fill struct sockaddr_un member sun_path. +# Defaults to true. (Since 5.1) # # Since: 1.3 ## { 'struct': 'UnixSocketAddress', 'data': { 'path': 'str', - '*tight': 'bool', - '*abstract': 'bool' } } + '*abstract': { 'type': 'bool', 'if': 'defined(CONFIG_LINUX)' }, + '*tight': { 'type': 'bool', 'if': 'defined(CONFIG_LINUX)' } } } =20 ## # @VsockSocketAddress: diff --git a/chardev/char-socket.c b/chardev/char-socket.c index dc1cf86ecf..213a4c8dd0 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -444,14 +444,20 @@ static char *qemu_chr_socket_address(SocketChardev *s= , const char *prefix) break; case SOCKET_ADDRESS_TYPE_UNIX: { + const char *tight =3D "", *abstract =3D ""; UnixSocketAddress *sa =3D &s->addr->u.q_unix; =20 - return g_strdup_printf("%sunix:%s%s%s%s", prefix, - s->addr->u.q_unix.path, - sa->has_abstract && sa->abstract - ? ",abstract" : "", - sa->has_tight && sa->tight - ? ",tight" : "", +#ifdef CONFIG_LINUX + if (sa->has_abstract && sa->abstract) { + abstract =3D ",abstract"; + if (sa->has_tight && sa->tight) { + tight =3D ",tight"; + } + } +#endif + + return g_strdup_printf("%sunix:%s%s%s%s", prefix, sa->path, + abstract, tight, s->is_listen ? ",server" : ""); break; } @@ -1394,8 +1400,10 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Ch= ardevBackend *backend, const char *host =3D qemu_opt_get(opts, "host"); const char *port =3D qemu_opt_get(opts, "port"); const char *fd =3D qemu_opt_get(opts, "fd"); +#ifdef CONFIG_LINUX bool tight =3D qemu_opt_get_bool(opts, "tight", true); bool abstract =3D qemu_opt_get_bool(opts, "abstract", false); +#endif SocketAddressLegacy *addr; ChardevSocket *sock; =20 @@ -1447,10 +1455,12 @@ static void qemu_chr_parse_socket(QemuOpts *opts, C= hardevBackend *backend, addr->type =3D SOCKET_ADDRESS_LEGACY_KIND_UNIX; q_unix =3D addr->u.q_unix.data =3D g_new0(UnixSocketAddress, 1); q_unix->path =3D g_strdup(path); +#ifdef CONFIG_LINUX q_unix->has_tight =3D true; q_unix->tight =3D tight; q_unix->has_abstract =3D true; q_unix->abstract =3D abstract; +#endif } else if (host) { addr->type =3D SOCKET_ADDRESS_LEGACY_KIND_INET; addr->u.inet.data =3D g_new(InetSocketAddress, 1); diff --git a/chardev/char.c b/chardev/char.c index 78553125d3..aa4282164a 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -928,6 +928,7 @@ QemuOptsList qemu_chardev_opts =3D { },{ .name =3D "logappend", .type =3D QEMU_OPT_BOOL, +#ifdef CONFIG_LINUX },{ .name =3D "tight", .type =3D QEMU_OPT_BOOL, @@ -935,6 +936,7 @@ QemuOptsList qemu_chardev_opts =3D { },{ .name =3D "abstract", .type =3D QEMU_OPT_BOOL, +#endif }, { /* end of list */ } }, diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index 7ecf95579b..67486055ed 100644 --- a/tests/test-util-sockets.c +++ b/tests/test-util-sockets.c @@ -229,7 +229,7 @@ static void test_socket_fd_pass_num_nocli(void) } #endif =20 -#ifdef __linux__ +#ifdef CONFIG_LINUX =20 #define ABSTRACT_SOCKET_VARIANTS 3 =20 @@ -326,7 +326,8 @@ static void test_socket_unix_abstract(void) =20 g_free(addr.u.q_unix.path); } -#endif + +#endif /* CONFIG_LINUX */ =20 int main(int argc, char **argv) { @@ -368,7 +369,7 @@ int main(int argc, char **argv) #endif } =20 -#ifdef __linux__ +#ifdef CONFIG_LINUX g_test_add_func("/util/socket/unix-abstract", test_socket_unix_abstract); #endif diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 671717499f..8af0278f15 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -860,10 +860,29 @@ static int vsock_parse(VsockSocketAddress *addr, cons= t char *str, =20 #ifndef _WIN32 =20 +static bool saddr_is_abstract(UnixSocketAddress *saddr) +{ +#ifdef CONFIG_LINUX + return saddr->abstract; +#else + return false; +#endif +} + +static bool saddr_is_tight(UnixSocketAddress *saddr) +{ +#ifdef CONFIG_LINUX + return !saddr->has_tight || saddr->tight; +#else + return false; +#endif +} + static int unix_listen_saddr(UnixSocketAddress *saddr, int num, Error **errp) { + bool abstract =3D saddr_is_abstract(saddr); struct sockaddr_un un; int sock, fd; char *pathbuf =3D NULL; @@ -877,7 +896,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, return -1; } =20 - if (saddr->path[0] || saddr->abstract) { + if (saddr->path[0] || abstract) { path =3D saddr->path; } else { const char *tmpdir =3D getenv("TMPDIR"); @@ -887,10 +906,10 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, =20 pathlen =3D strlen(path); if (pathlen > sizeof(un.sun_path) || - (saddr->abstract && pathlen > (sizeof(un.sun_path) - 1))) { + (abstract && pathlen > (sizeof(un.sun_path) - 1))) { error_setg(errp, "UNIX socket path '%s' is too long", path); error_append_hint(errp, "Path must be less than %zu bytes\n", - saddr->abstract ? sizeof(un.sun_path) - 1 : + abstract ? sizeof(un.sun_path) - 1 : sizeof(un.sun_path)); goto err; } @@ -912,7 +931,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, close(fd); } =20 - if (!saddr->abstract && unlink(path) < 0 && errno !=3D ENOENT) { + if (!abstract && unlink(path) < 0 && errno !=3D ENOENT) { error_setg_errno(errp, errno, "Failed to unlink socket %s", path); goto err; @@ -922,10 +941,10 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, un.sun_family =3D AF_UNIX; addrlen =3D sizeof(un); =20 - if (saddr->abstract) { + if (abstract) { un.sun_path[0] =3D '\0'; memcpy(&un.sun_path[1], path, pathlen); - if (!saddr->has_tight || saddr->tight) { + if (saddr_is_tight(saddr)) { addrlen =3D offsetof(struct sockaddr_un, sun_path) + 1 + pathl= en; } } else { @@ -952,6 +971,7 @@ err: =20 static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp) { + bool abstract =3D saddr_is_abstract(saddr); struct sockaddr_un un; int sock, rc; size_t pathlen; @@ -970,10 +990,10 @@ static int unix_connect_saddr(UnixSocketAddress *sadd= r, Error **errp) =20 pathlen =3D strlen(saddr->path); if (pathlen > sizeof(un.sun_path) || - (saddr->abstract && pathlen > (sizeof(un.sun_path) - 1))) { + (abstract && pathlen > (sizeof(un.sun_path) - 1))) { error_setg(errp, "UNIX socket path '%s' is too long", saddr->path); error_append_hint(errp, "Path must be less than %zu bytes\n", - saddr->abstract ? sizeof(un.sun_path) - 1 : + abstract ? sizeof(un.sun_path) - 1 : sizeof(un.sun_path)); goto err; } @@ -982,10 +1002,10 @@ static int unix_connect_saddr(UnixSocketAddress *sad= dr, Error **errp) un.sun_family =3D AF_UNIX; addrlen =3D sizeof(un); =20 - if (saddr->abstract) { + if (abstract) { un.sun_path[0] =3D '\0'; memcpy(&un.sun_path[1], saddr->path, pathlen); - if (!saddr->has_tight || saddr->tight) { + if (saddr_is_tight(saddr)) { addrlen =3D offsetof(struct sockaddr_un, sun_path) + 1 + pathl= en; } } else { --=20 2.26.2