From patchwork Thu Jun 11 03:29:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11599179 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C55F892A for ; Thu, 11 Jun 2020 03:32:05 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A0E942072E for ; Thu, 11 Jun 2020 03:32:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VVgNS8IT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A0E942072E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDv6-0007yC-1k; Thu, 11 Jun 2020 03:30:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDv4-0007xd-RF for xen-devel@lists.xenproject.org; Thu, 11 Jun 2020 03:30:22 +0000 X-Inumbo-ID: e18f3772-ab93-11ea-bca7-bc764e2007e4 Received: from mail-qt1-x841.google.com (unknown [2607:f8b0:4864:20::841]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e18f3772-ab93-11ea-bca7-bc764e2007e4; Thu, 11 Jun 2020 03:30:22 +0000 (UTC) Received: by mail-qt1-x841.google.com with SMTP id e16so3632004qtg.0 for ; Wed, 10 Jun 2020 20:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HolYNn/5i3ZSFaAEzaxuKG/DWch8bwIGH3CfAGoU3Ss=; b=VVgNS8ITlTpaK8/lkmhim3IFmgZNw7DKAngtT00fCiDnKhyi/PhQ9DLcn2HoOkYlqF /jUWIOX4w26jasKRH8z1urMQ62Y+h5G/tS+xXwDopCSQkqlZo3r62ZeSCKSW+70TUlRZ jn6wZvU8Ca7/MGytIpdvxlvPZv61D88F0Dl4veVoFJ2TlE1bBjRGym1E8DMjskwxmHXS i35LUFJMZ1Cia6HnoLB/Q2WI3i2TMlazb5Cy1fy/bE2+vCyJfQiYayRR2dwQbF8KNKaM YUQJt2l0VGouCXlxveFZ8+GsUM+a8RkhW0JKT8u2GAsG60M11s6Ox3Sp3WUixnrUWFDG y02Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HolYNn/5i3ZSFaAEzaxuKG/DWch8bwIGH3CfAGoU3Ss=; b=ZBl35zuI+i0kF/ffzM+AdfsKf6vW0IazoQ6fyWHtMUTazDc3rbiCty8/g53hDyOMxd vEVXKYvjJZgclgyb4I+tp5gfU8c3tmiR3JFT2bogwD4i/2HcuN8DSXfSVYZt8mqsZQki cD3isk5kAL2NdzQu3L9l6MoqHFhCABo0MfI0FOAd27GWe87b+iOMef9Ma6YlfVTk8k6J KOwgLgrgBfFBHWSR7yx+G+5WIRDvkNXqXUgH65wgJpWRhHwckynA5d2HQPlmOPDWcxQj WCsdQc6t2x/NZCm/isoA28BSfIqwv56D07Npo+zocIOdZK0S7WnZky4TNYu5afCGZmXR pwqw== X-Gm-Message-State: AOAM531utmIPX4vy0hwlQWnUYDsHzx6Rs/ddGq+AJw/naGtl9HTa1Xfl fORPx9mIPlEpjf04qfjhK3TygvP2 X-Google-Smtp-Source: ABdhPJzlKG0E5XXLkreHbFwls+ALN2FyZ0CJj4vDAVLPJ/jsigbpwvPqDo+0W20M3K/N2KbwUEREbw== X-Received: by 2002:ac8:23e3:: with SMTP id r32mr6698656qtr.268.1591846221569; Wed, 10 Jun 2020 20:30:21 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:dd4d:2b5c:f471:f332]) by smtp.gmail.com with ESMTPSA id v3sm1164078qkh.130.2020.06.10.20.30.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 20:30:20 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH v2 01/10] vchan-socket-proxy: Ensure UNIX path NUL terminated Date: Wed, 10 Jun 2020 23:29:27 -0400 Message-Id: <20200611032936.350657-2-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200611032936.350657-1-jandryuk@gmail.com> References: <20200611032936.350657-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Olaf Hering , Ian Jackson , Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Check the socket path length to ensure sun_path is NUL terminated. This was spotted by Citrix's Coverity. Also use strcpy to avoid a warning "'__builtin_strncpy' specified bound 108 equals destination size [-Werror=stringop-truncation]" flagged by gcc 10. Signed-off-by: Jason Andryuk --- CC: Olaf Hering With Ubuntu's gcc-10, which is a pre-release "gcc-10 (Ubuntu 10-20200411-0ubuntu1) 10.0.1 20200411 (experimental)", I couldn't actualy generate the strncpy warning. tools/libvchan/vchan-socket-proxy.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index 13700c5d67..6ae1d84143 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -148,12 +148,18 @@ static int connect_socket(const char *path_or_fd) { return fd; } + if (strlen(path_or_fd) >= sizeof(addr.sun_path)) { + fprintf(stderr, "UNIX socket path \"%s\" too long (%zd >= %zd)\n", + path_or_fd, strlen(path_or_fd), sizeof(addr.sun_path)); + return -1; + } + fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd == -1) return -1; addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, path_or_fd, sizeof(addr.sun_path)); + strcpy(addr.sun_path, path_or_fd); if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == -1) { close(fd); return -1; @@ -174,13 +180,19 @@ static int listen_socket(const char *path_or_fd) { return fd; } + if (strlen(path_or_fd) >= sizeof(addr.sun_path)) { + fprintf(stderr, "UNIX socket path \"%s\" too long (%zd >= %zd)\n", + path_or_fd, strlen(path_or_fd), sizeof(addr.sun_path)); + return -1; + } + /* if not a number, assume a socket path */ fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd == -1) return -1; addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, path_or_fd, sizeof(addr.sun_path)); + strcpy(addr.sun_path, path_or_fd); if (bind(fd, (const struct sockaddr *)&addr, sizeof(addr)) == -1) { close(fd); return -1; From patchwork Thu Jun 11 03:29:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11599183 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E2EAB1392 for ; Thu, 11 Jun 2020 03:32:08 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BE6982072E for ; Thu, 11 Jun 2020 03:32:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f1IGQWYC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE6982072E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvB-0007yd-AA; Thu, 11 Jun 2020 03:30:29 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDv9-0007xd-RQ for xen-devel@lists.xenproject.org; Thu, 11 Jun 2020 03:30:27 +0000 X-Inumbo-ID: e335d77a-ab93-11ea-8496-bc764e2007e4 Received: from mail-qt1-x844.google.com (unknown [2607:f8b0:4864:20::844]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e335d77a-ab93-11ea-8496-bc764e2007e4; Thu, 11 Jun 2020 03:30:24 +0000 (UTC) Received: by mail-qt1-x844.google.com with SMTP id i16so3600419qtr.7 for ; Wed, 10 Jun 2020 20:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xuj1oyeuSUlKPQJS2nl7hDTURFrye9RvexdzOTb7cJ0=; b=f1IGQWYC+vrigx8yJ2oxfZQUfd/70HCG0opTR9Qbko8LYtBPE3qe73aJ3ukY3/+3fG DYUS2JEoIEQErVe2yUc3Jjj21GRTeOLSB7FIViB46I8bnKGImeSrIJjat9Jpk9N6piue 1KVClOUQpySylxyMPEMfEfC0fiHRNb6SXhgK17a//Dy96tdgKphWyIkLzrCuV62eD/V6 Qt3Xqell8qsazRLSJinS29uOw3vHXMvbn59s+BBI/xppkkn6KkjTPuurf6EBTctdPa+n bqvX7vmONfTndckCrJV2dhHM2+ppGkZtWVoJJU+VNXSShsHv/ND55G0LLA+OJsOuH49C Gmyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Xuj1oyeuSUlKPQJS2nl7hDTURFrye9RvexdzOTb7cJ0=; b=qN3z3vTEiFiTQ394YlKfFc+HRac1/qe/JukOrQmOUQho5fsZtrp/4t+HdPVZfPfaqc BAKYdey98UWSO8WByFxZKJFI1fubXVwXPmtHZipSq1txtGPLylTsM/ha3nbdQ51CQYTK RqESlDpjBLL78Ix3Nw8MLxMU36DHR+B6E8e4SKMLefJMyYHRskPCezYIdDNce6uv/vYy B5cYfsHGiOo/cZSQQ8XJkhsNq37vU7VTbbyCfG4SuqaNoeiSwPfVXjX97BTLhpv5Cdcm PEsf7jUI/xexO7pYXTHc3hhH5RF+BIuTTwv2prApL7yWsMEnVeSkn9oiW8CnzBSuKnMb D8gg== X-Gm-Message-State: AOAM530Qeo0P0P/CtdbsVL1+sN5oZmhvmObXUnGNKdKKVB3lFIk59eSb S59jWdufPADOhEj7DL6k43nj6elz X-Google-Smtp-Source: ABdhPJwO3IQ1jhD/t3O/3FRk4P3EWIPbIG10rbuhK9cU3ErZSxtylF1zUqqetUppzSAXRBSUKv+EtA== X-Received: by 2002:ac8:22e5:: with SMTP id g34mr6742379qta.227.1591846224351; Wed, 10 Jun 2020 20:30:24 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:dd4d:2b5c:f471:f332]) by smtp.gmail.com with ESMTPSA id v3sm1164078qkh.130.2020.06.10.20.30.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 20:30:23 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH v2 02/10] vchan-socket-proxy: Move perror() into listen_socket Date: Wed, 10 Jun 2020 23:29:28 -0400 Message-Id: <20200611032936.350657-3-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200611032936.350657-1-jandryuk@gmail.com> References: <20200611032936.350657-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The use of perror on the return from listen_socket can produce misleading results like: UNIX socket path "/tmp/aa....aa" too long (156 >= 108) listen socket: Success errno is reset by subsequent system & library calls, so it may be inaccurate by the time listen_socket returns. Call perror immediately after failing system calls to print the proper message. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index 6ae1d84143..4edc3a44f5 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -188,16 +188,20 @@ static int listen_socket(const char *path_or_fd) { /* if not a number, assume a socket path */ fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (fd == -1) + if (fd == -1) { + perror("socket"); return -1; + } addr.sun_family = AF_UNIX; strcpy(addr.sun_path, path_or_fd); if (bind(fd, (const struct sockaddr *)&addr, sizeof(addr)) == -1) { + perror("bind"); close(fd); return -1; } if (listen(fd, 5) != 0) { + perror("listen"); close(fd); return -1; } @@ -419,7 +423,7 @@ int main(int argc, char **argv) } else { socket_fd = listen_socket(socket_path); if (socket_fd == -1) { - perror("listen socket"); + fprintf(stderr, "listen socket failed\n"); return 1; } } From patchwork Thu Jun 11 03:29:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11599187 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 474371392 for ; Thu, 11 Jun 2020 03:32:22 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 22E5C2072E for ; Thu, 11 Jun 2020 03:32:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EPUSz/BR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22E5C2072E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvF-000805-I2; Thu, 11 Jun 2020 03:30:33 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvE-0007xd-Rk for xen-devel@lists.xenproject.org; Thu, 11 Jun 2020 03:30:32 +0000 X-Inumbo-ID: e450c340-ab93-11ea-bca7-bc764e2007e4 Received: from mail-qt1-x842.google.com (unknown [2607:f8b0:4864:20::842]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e450c340-ab93-11ea-bca7-bc764e2007e4; Thu, 11 Jun 2020 03:30:26 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id w9so3618204qtv.3 for ; Wed, 10 Jun 2020 20:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=s1VW2Vbm9sbX6brqSfDiW+eia7lSqgNEJbMvS1O/20A=; b=EPUSz/BRdjcU7hP3v7u/F8J+qfjEClfVqyZBfTFDr6ebh4j18yhW1QVN03jn/cdCHS rOtnhrFDrDbA7d3NHy4LhhCd3err3yQSKlritxvGKydhtRXXCpqd619CxZsFQS8fv2Rj Yil8DnifXsTnpGhbgepEMi4sozVhkbJZTCW/nZiX98SqfR2t5NfaLX+ChMJa/lbPoSs6 Jp99HPqryyKMKfbGGHG4SRBM1PUiMZWQ34z0SpHoNSn9TO/Oq/9eOHBSuE6OSf6G9pAK 98XxOJ7noVUvVp9n2ZZAptDkCt+nlRXZg6jH+AF83C7Nch/jae2679cnXj+DTAyhRDoH uGfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=s1VW2Vbm9sbX6brqSfDiW+eia7lSqgNEJbMvS1O/20A=; b=lsauzh7vzFnmqLzLeOp5ICTpiglMSHhKq3dz33upJoWNOC3kuxXgCwrZQHe0NOQNYr O9/9SccQVd0spcPeTrA8HpCptg5b+f5YAP87TBzEpefqgilsd+uQfTGlnDmWE74L9ZKx L8JuSUiQGshIaCPbqOvk2XLwxiR+Tp6WomOhAqKo7Cx1mPJAeMfFpeWU9El+uquDoJm2 +pVG5v2Ncp6Z0K/sIf1mNdRa/mO3zS4jFtgH8b6xaz8Gg6KQfmelbHE49p7dJ4Bd9OV3 TM3S25UfzSD3ZBZDrlK5bQYgg+Iltes1pSC7nKW5i6T17fnFAR0SC47vA5Oj52fkRZ3s n01w== X-Gm-Message-State: AOAM533w1dyAKNVpzkGoSE76VuUcCq6WiAxhK9o9HrrhKI5sDUPt+POB lo4RAJZF/WeRUBtVQrHrINVtD54D X-Google-Smtp-Source: ABdhPJwThClwsV971Q6HYvvQGLd5cWakFsLrNXUri9Wvl5vA+lhutV/8hPOFwNn7czZX+S7kCd+0VA== X-Received: by 2002:ac8:6f79:: with SMTP id u25mr6687555qtv.183.1591846226187; Wed, 10 Jun 2020 20:30:26 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:dd4d:2b5c:f471:f332]) by smtp.gmail.com with ESMTPSA id v3sm1164078qkh.130.2020.06.10.20.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 20:30:25 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH v2 03/10] vchan-socket-proxy: Move perror() into connect_socket Date: Wed, 10 Jun 2020 23:29:29 -0400 Message-Id: <20200611032936.350657-4-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200611032936.350657-1-jandryuk@gmail.com> References: <20200611032936.350657-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" errno is reset by subsequent system & library calls, so it may be inaccurate by the time connect_socket returns. Call perror immediately after failing system calls to print the proper message. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index 4edc3a44f5..c6a83e4712 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -155,12 +155,15 @@ static int connect_socket(const char *path_or_fd) { } fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (fd == -1) + if (fd == -1) { + perror("socket"); return -1; + } addr.sun_family = AF_UNIX; strcpy(addr.sun_path, path_or_fd); if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == -1) { + perror("connect"); close(fd); return -1; } @@ -457,7 +460,7 @@ int main(int argc, char **argv) input_fd = output_fd = connect_socket(socket_path); } if (input_fd == -1) { - perror("connect socket"); + fprintf(stderr, "connect_socket failed\n"); return 1; } if (data_loop(ctrl, input_fd, output_fd) != 0) From patchwork Thu Jun 11 03:29:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11599173 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA9AB92A for ; Thu, 11 Jun 2020 03:31:02 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C54AF2072E for ; Thu, 11 Jun 2020 03:31:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a7/hb9vs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C54AF2072E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvK-00081y-RQ; Thu, 11 Jun 2020 03:30:38 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvJ-0007xd-Rk for xen-devel@lists.xenproject.org; Thu, 11 Jun 2020 03:30:37 +0000 X-Inumbo-ID: e561a434-ab93-11ea-bca7-bc764e2007e4 Received: from mail-qt1-x843.google.com (unknown [2607:f8b0:4864:20::843]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e561a434-ab93-11ea-bca7-bc764e2007e4; Thu, 11 Jun 2020 03:30:28 +0000 (UTC) Received: by mail-qt1-x843.google.com with SMTP id y1so3581221qtv.12 for ; Wed, 10 Jun 2020 20:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=laRg1K8C6uMRUlZmD1dge7J/mbvALpacyvB5fuXQU54=; b=a7/hb9vsaW1Ysq7scxsVtU9RpygQmV9LYFn3t6AYoy45E8nA12+ux2ri78VaijfjiN G/Xu+wdZACU2soQYveVkUYkGsaoekaFhZehPn1ZV0zRnIqPeRvOLlchcns07ABG+NVmI NCqY/Yr2cYTUFccsQfhiIfuetj3sGLZ238U6qn/EmvWCw1c7uU7a6Eq8cn5d5WwZVq1X 5wRRyfEJbsS+qnP17JfPU4OkP/hmvMZ/IRtFXzcNTF2/OK0Ho+p9T43QxYETOAKCR12S eGbud4eknYVdJ2nk9DEH6X3LZfSkiJ0Dni1kjRrzk3jycwPRlVhxjjWtGNgICp7WGhJF K51A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=laRg1K8C6uMRUlZmD1dge7J/mbvALpacyvB5fuXQU54=; b=kG51DbajZyGt/tPLz7tGkwXdsuw+BVQ3+YtPiJk24aw4xjvejYiLu/ZlxauePJHvsY DOrGfY27IUl23EZoW0545rcPqamnz94mH4gUsafn9tKXDf+sjrbIzcHqliuE7E/G6fYd mFtMM54MWAo1z8GxqeotjHBIzs4ygn8iTxkaruloDsSwdCp/01tmmYSbsfV8NOS/sHDi aqHKskFQGjkiHoy6/YDLOFd3TYOFXuVq8r5sMw93B6MpXEjWUyzTx1+kUe2tSjgejUEw noYD93qEWos8tjANsL1DgVZ3Y66c9WqXZT9ueodVUxSdli80GqhR4WuEZLI05cu1dcZ0 Ewfg== X-Gm-Message-State: AOAM533PwucgxmwJLW9nh890GRUzQ4Aw767zf5FSMnKTFKZvopnQIucD tiARKG7muCW3Zc0075DvG3klAoXb X-Google-Smtp-Source: ABdhPJx1Kszbf/65QiiO87mphpbrCYAKOz1s5J+KcxRZftbQxetEHhaR2JYIUroKxCwaaZF2CojUFQ== X-Received: by 2002:ac8:3529:: with SMTP id y38mr6314203qtb.315.1591846228003; Wed, 10 Jun 2020 20:30:28 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:dd4d:2b5c:f471:f332]) by smtp.gmail.com with ESMTPSA id v3sm1164078qkh.130.2020.06.10.20.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 20:30:27 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH v2 04/10] vchan-socket-proxy: Check xs_watch return value Date: Wed, 10 Jun 2020 23:29:30 -0400 Message-Id: <20200611032936.350657-5-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200611032936.350657-1-jandryuk@gmail.com> References: <20200611032936.350657-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Check the return value of xs_watch and error out on failure. This was found by Citrix's Coverity. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index c6a83e4712..196f6016b9 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -232,8 +232,15 @@ static struct libxenvchan *connect_vchan(int domid, const char *path) { goto out; } /* wait for vchan server to create *path* */ - xs_watch(xs, path, "path"); - xs_watch(xs, "@releaseDomain", "release"); + if (!xs_watch(xs, path, "path")) { + fprintf(stderr, "xs_watch(%s) failed.\n", path); + goto out; + } + if (!xs_watch(xs, "@releaseDomain", "release")) { + fprintf(stderr, "xs_watch(@releaseDomain failed.\n"); + goto out; + } + while ((watch_ret = xs_read_watch(xs, &watch_num))) { /* don't care about exact which fired the watch */ free(watch_ret); From patchwork Thu Jun 11 03:29:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11599181 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0151E92A for ; Thu, 11 Jun 2020 03:32:08 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D0FBE2072E for ; Thu, 11 Jun 2020 03:32:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FBXUPHho" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D0FBE2072E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvP-00083s-4J; Thu, 11 Jun 2020 03:30:43 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvO-0007xd-Rq for xen-devel@lists.xenproject.org; Thu, 11 Jun 2020 03:30:42 +0000 X-Inumbo-ID: e641f156-ab93-11ea-bca7-bc764e2007e4 Received: from mail-qt1-x844.google.com (unknown [2607:f8b0:4864:20::844]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e641f156-ab93-11ea-bca7-bc764e2007e4; Thu, 11 Jun 2020 03:30:30 +0000 (UTC) Received: by mail-qt1-x844.google.com with SMTP id e16so3632185qtg.0 for ; Wed, 10 Jun 2020 20:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OV7hLic7QdG3BUdt8KJifuAGbNbuFpzMSDCmTGtRTHI=; b=FBXUPHhodN+sKzb9ZEnacuQ+nWFTGfIuss7ws1Hoiz8fCT9W223Py3wYhhm218fYrs hmWfdw5lEdK11CiWNA0E2QeTsoGzq99SC3OeQpUUerJqzzrxsd0DPuBE3WV0C0qPDQY8 D/iZCSEtyU1Oa7XaCRgPPNUTiWghAWVqys8WiIMhH9lpKLuAkf0s1uCiy1wrDu2jye31 xiGN2whoMy5wVaGjXCRF++zxJ0FLMHBLB1tMF+oLG8b52zxmRJ+14lJEeFqc+m8Fl+3e 1u2gS3w0rgaOsVNe6YKfb0VIYqdl88YFZRS5cuaniyNg6mU5DBR+5tuN2SVUW5s2bKMY eI5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OV7hLic7QdG3BUdt8KJifuAGbNbuFpzMSDCmTGtRTHI=; b=FYtcPugEgKPlofIRWvgzRzd94CkpdFegkOuwNiqGHhj0oySQoyaTYvaZwBqEHHqC0c xtMsfuFlb6Qz25Mf5VOk9WUolxgnN6jTPwwbWSKOI7C12N2vT+oYbCiBwlcBBgngHg/u fFEzISx6ABDTbFVMZbSHySTPyZ0MC4kYOfff+Zi45zDeRUkirDC37DSSQ5akGYzOIYhT LB047+lKNTxfeDjnE7TYpujAJh0HZkwj4orDYF8gDqyyXLWsXOz26SYY3DXQtrKL9uW2 sDfEVc9y9dwQTIJBm0t95tf/oyly9UqunDwG9+Xxx4tAsVi2RzyIVIO+J9vMtPg/sFt7 6tUw== X-Gm-Message-State: AOAM532M2mQijyRdgj3okx4APx52kB8w4t2OFWStVRs+/I9YxIoHkMYl CppkBk6SLCB2Kzj025oHocPX6cdC X-Google-Smtp-Source: ABdhPJwJQtwUYbCgitLnSAMDSRlFD+GH7f+0kPhX2hfvFDCiPwSn2oJd1pKiZ9lOLpYWgP6NCVYZrA== X-Received: by 2002:ac8:341a:: with SMTP id u26mr6550830qtb.36.1591846229462; Wed, 10 Jun 2020 20:30:29 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:dd4d:2b5c:f471:f332]) by smtp.gmail.com with ESMTPSA id v3sm1164078qkh.130.2020.06.10.20.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 20:30:28 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH v2 05/10] vchan-socket-proxy: Unify main return value Date: Wed, 10 Jun 2020 23:29:31 -0400 Message-Id: <20200611032936.350657-6-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200611032936.350657-1-jandryuk@gmail.com> References: <20200611032936.350657-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Introduce 'ret' for main's return value and remove direct returns. This is in preparation for a unified exit path with resource cleanup. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index 196f6016b9..36a2fe2cb8 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -388,6 +388,7 @@ int main(int argc, char **argv) const char *vchan_path; const char *state_path = NULL; int opt; + int ret; while ((opt = getopt_long(argc, argv, "m:vs:", options, NULL)) != -1) { switch (opt) { @@ -454,6 +455,8 @@ int main(int argc, char **argv) xs_close(xs); } + ret = 0; + for (;;) { if (is_server) { /* wait for vchan connection */ @@ -468,7 +471,8 @@ int main(int argc, char **argv) } if (input_fd == -1) { fprintf(stderr, "connect_socket failed\n"); - return 1; + ret = 1; + break; } if (data_loop(ctrl, input_fd, output_fd) != 0) break; @@ -481,14 +485,16 @@ int main(int argc, char **argv) input_fd = output_fd = accept(socket_fd, NULL, NULL); if (input_fd == -1) { perror("accept"); - return 1; + ret = 1; + break; } set_nonblocking(input_fd, 1); set_nonblocking(output_fd, 1); ctrl = connect_vchan(domid, vchan_path); if (!ctrl) { perror("vchan client init"); - return 1; + ret = 1; + break; } if (data_loop(ctrl, input_fd, output_fd) != 0) break; @@ -500,5 +506,6 @@ int main(int argc, char **argv) ctrl = NULL; } } - return 0; + + return ret; } From patchwork Thu Jun 11 03:29:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11599185 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E142B1392 for ; Thu, 11 Jun 2020 03:32:16 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BC6662072E for ; Thu, 11 Jun 2020 03:32:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NYja3Uul" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC6662072E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvU-00086a-Ek; Thu, 11 Jun 2020 03:30:48 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvT-0007xd-S4 for xen-devel@lists.xenproject.org; Thu, 11 Jun 2020 03:30:47 +0000 X-Inumbo-ID: e7aaa2cc-ab93-11ea-bb8b-bc764e2007e4 Received: from mail-qk1-x742.google.com (unknown [2607:f8b0:4864:20::742]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e7aaa2cc-ab93-11ea-bb8b-bc764e2007e4; Thu, 11 Jun 2020 03:30:32 +0000 (UTC) Received: by mail-qk1-x742.google.com with SMTP id c185so4357305qke.7 for ; Wed, 10 Jun 2020 20:30:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0QHpnXfDLIU42Ajcn7oe5u4g/H2EWJ6mBd+W546xwxc=; b=NYja3UulW133MDWz7THaPy5RuR9uRLPFZCcavpEeBICBdVNluA3ZqxpDPSIliOyRd5 DNKunBo1ICSU7dvWYlQIK8GVeYywImCazfZOIIsPyUiJajpMj8+6SmV7UHHwnmHARr8j l0rmbWl/rz7QfzSo+l+MSkQQxIH7r6CtEq/ximG7YGnGkLtARyqdx30cnhYK8UtyZTgR /EwEFHWc4Wt4uAF9+VYOCiY/Gmu166QHSuwqeo9WSNDdjmsOs5cRcShgU8wFmYeVnHOA 4OTs9lZ+GnbDX9b9Dis6xbIvvH43vBJb6Z0G8sjGSTmjap5ulZhq1nyu8uwWsu5Uofhg DOfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0QHpnXfDLIU42Ajcn7oe5u4g/H2EWJ6mBd+W546xwxc=; b=miuW/iMVzxqVEYsS2dSLiKoW5nRL8qg1FKaUFtI3ZK7+kZZGxFnHi+/hjLb9jTaJpx jFlhAdJn0PEMpiCWkDi21Rol6sKe8fQerXadTKSPnAFWLCK1u1yEhqalIgjTBwC6LMQS pl6hu+TVZYjQRr5K+5/z9XyMnWBB4Tyyz7OWOPeG4k1vGjrwo+UbrwPrDy54a9bp/wHa toVhRd+yUCFMzqeVdqeupwdr9RaoBaxA75S3Jvspl2scyJ7SN5nc1QJIxxB9ecEZ9Qe0 QYDxRz7YQuJ3qHOJz0C9xlZ10jHjtfEwVOODqCVRnfDS2idAVwEdcLNBTYeOY07krYq2 pG9g== X-Gm-Message-State: AOAM533HucrZdPVvupr+mECX5vxEoPonpNC3PsCSnKMT+xfEgUDT7gvO sR03iPIidoQoHA8FhLlscVRm7EGV X-Google-Smtp-Source: ABdhPJwdhVkHS2DNi9/Nuua9kYv3yXSI9U6EZrJZD0L9oLp14VJMoLqPgvUyonhT8Gg2MqBfLOmlcA== X-Received: by 2002:a37:a64c:: with SMTP id p73mr6240900qke.273.1591846231748; Wed, 10 Jun 2020 20:30:31 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:dd4d:2b5c:f471:f332]) by smtp.gmail.com with ESMTPSA id v3sm1164078qkh.130.2020.06.10.20.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 20:30:31 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH v2 06/10] vchan-socket-proxy: Use a struct to store state Date: Wed, 10 Jun 2020 23:29:32 -0400 Message-Id: <20200611032936.350657-7-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200611032936.350657-1-jandryuk@gmail.com> References: <20200611032936.350657-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Use a struct to group the vchan ctrl and FDs. This will facilite tracking the state of open and closed FDs and ctrl in data_loop(). Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 52 +++++++++++++++++------------ 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index 36a2fe2cb8..a932c94c97 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -89,6 +89,12 @@ int insiz = 0; int outsiz = 0; int verbose = 0; +struct vchan_proxy_state { + struct libxenvchan *ctrl; + int output_fd; + int input_fd; +}; + static void vchan_wr(struct libxenvchan *ctrl) { int ret; @@ -381,8 +387,9 @@ int main(int argc, char **argv) { int is_server = 0; int socket_fd = -1; - int input_fd, output_fd; - struct libxenvchan *ctrl = NULL; + struct vchan_proxy_state state = { .ctrl = NULL, + .input_fd = -1, + .output_fd = -1 }; const char *socket_path; int domid; const char *vchan_path; @@ -422,15 +429,15 @@ int main(int argc, char **argv) socket_path = argv[optind+2]; if (is_server) { - ctrl = libxenvchan_server_init(NULL, domid, vchan_path, 0, 0); - if (!ctrl) { + state.ctrl = libxenvchan_server_init(NULL, domid, vchan_path, 0, 0); + if (!state.ctrl) { perror("libxenvchan_server_init"); exit(1); } } else { if (strcmp(socket_path, "-") == 0) { - input_fd = 0; - output_fd = 1; + state.input_fd = 0; + state.output_fd = 1; } else { socket_fd = listen_socket(socket_path); if (socket_fd == -1) { @@ -460,21 +467,21 @@ int main(int argc, char **argv) for (;;) { if (is_server) { /* wait for vchan connection */ - while (libxenvchan_is_open(ctrl) != 1) - libxenvchan_wait(ctrl); + while (libxenvchan_is_open(state.ctrl) != 1) + libxenvchan_wait(state.ctrl); /* vchan client connected, setup local FD if needed */ if (strcmp(socket_path, "-") == 0) { - input_fd = 0; - output_fd = 1; + state.input_fd = 0; + state.output_fd = 1; } else { - input_fd = output_fd = connect_socket(socket_path); + state.input_fd = state.output_fd = connect_socket(socket_path); } - if (input_fd == -1) { + if (state.input_fd == -1) { fprintf(stderr, "connect_socket failed\n"); ret = 1; break; } - if (data_loop(ctrl, input_fd, output_fd) != 0) + if (data_loop(state.ctrl, state.input_fd, state.output_fd) != 0) break; /* keep it running only when get UNIX socket path */ if (socket_path[0] != '/') @@ -482,28 +489,29 @@ int main(int argc, char **argv) } else { /* wait for local socket connection */ if (strcmp(socket_path, "-") != 0) - input_fd = output_fd = accept(socket_fd, NULL, NULL); - if (input_fd == -1) { + state.input_fd = state.output_fd = accept(socket_fd, + NULL, NULL); + if (state.input_fd == -1) { perror("accept"); ret = 1; break; } - set_nonblocking(input_fd, 1); - set_nonblocking(output_fd, 1); - ctrl = connect_vchan(domid, vchan_path); - if (!ctrl) { + set_nonblocking(state.input_fd, 1); + set_nonblocking(state.output_fd, 1); + state.ctrl = connect_vchan(domid, vchan_path); + if (!state.ctrl) { perror("vchan client init"); ret = 1; break; } - if (data_loop(ctrl, input_fd, output_fd) != 0) + if (data_loop(state.ctrl, state.input_fd, state.output_fd) != 0) break; /* don't reconnect if output was stdout */ if (strcmp(socket_path, "-") == 0) break; - libxenvchan_close(ctrl); - ctrl = NULL; + libxenvchan_close(state.ctrl); + state.ctrl = NULL; } } From patchwork Thu Jun 11 03:29:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11599189 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 080A71392 for ; Thu, 11 Jun 2020 03:32:29 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D4DDA2072E for ; Thu, 11 Jun 2020 03:32:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sRbm1ow6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D4DDA2072E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvZ-0008A2-TT; Thu, 11 Jun 2020 03:30:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvY-0007xd-SQ for xen-devel@lists.xenproject.org; Thu, 11 Jun 2020 03:30:52 +0000 X-Inumbo-ID: e8951ee2-ab93-11ea-bca7-bc764e2007e4 Received: from mail-qk1-x744.google.com (unknown [2607:f8b0:4864:20::744]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e8951ee2-ab93-11ea-bca7-bc764e2007e4; Thu, 11 Jun 2020 03:30:33 +0000 (UTC) Received: by mail-qk1-x744.google.com with SMTP id q8so4321085qkm.12 for ; Wed, 10 Jun 2020 20:30:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=acDEo8MXiNoRRWQ/LKc41cpCF79OTRwWmw6nG02XKJE=; b=sRbm1ow6OMy4RlPfEgTljW9izUWN0W3hAaRtX7YSpSJRbcPKUyJM977UrI/CqjreUt JRFwICjEeLa3I4zG7Y/PH9PcqVpW7tW6/Os4BzeHGJkZZiSV2seuia9LAo7FQ1m6oqPa vvIsj8YShjmxi/nWzcdRAhCKOMJjpXlhKmjcfYNsRMclOHXFtRulwfJgNDZnk813xPg5 Zp/no8di6X9tDIZwJiNN2SlooqJgkZa3jRrpn0cuX1yzIx7n05+8F16TEUG5Xc415Q6E cFKmY6WAp45aSIpL1/i6XFGF14Kp79ZrUFVuttwaLJ8svEs/YS3AcnEcTOGHfzVvB0Ra czNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=acDEo8MXiNoRRWQ/LKc41cpCF79OTRwWmw6nG02XKJE=; b=cv17oiOiJZzA1YMmQwbDkmZz5/KTkSUeY10QZ3Eju9ah9mFnWiFyOtXXEL2O6B8EcT mt+5kHEiY2oyXCoqrVdmQESBWSI+t4cgTJnoTf4Gxhz473P4qvXwyysRvkMsUKpTUUBw PmDZKKoCqDHskDrjOJ9vzFfYYtH9w+oAlOTnfNY3L3p7GdXv6FJwIFbYUyH6PfGDjS43 BRx7/tT0bj6ZJcKYS49Cjde/IRdizvtdYtKvbgA+3cLLDzlMPNLX6BexDnpk5KEmVDll vdZqBdUixL9/ZRhV2VvKdr6Jr2jv1T/59CKyHvX9NqXjHYSxh95vf8t6LaDkqkKXx+kj Wj7A== X-Gm-Message-State: AOAM532LJQ6buj7YIc6AlaPAohSCGbQKe8evCTD40s0ZJYuJG15qMLoi LGthS+zhjBfSOLSlJSX0UNM82ba8 X-Google-Smtp-Source: ABdhPJxCYNtb5p4oYxf9KdVt/5taYFzlGn+/XLgqcMPRp/Tup+mWZ10k/7oJPMPupNmwbz2Vz0r50A== X-Received: by 2002:a37:a416:: with SMTP id n22mr6190740qke.49.1591846233327; Wed, 10 Jun 2020 20:30:33 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:dd4d:2b5c:f471:f332]) by smtp.gmail.com with ESMTPSA id v3sm1164078qkh.130.2020.06.10.20.30.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 20:30:32 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH v2 07/10] vchan-socket-proxy: Switch data_loop() to take state Date: Wed, 10 Jun 2020 23:29:33 -0400 Message-Id: <20200611032936.350657-8-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200611032936.350657-1-jandryuk@gmail.com> References: <20200611032936.350657-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Switch data_loop to take a pointer to vchan_proxy_state. No functional change. This removes a dead store to input_fd identified by Coverity. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 65 +++++++++++++++-------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index a932c94c97..29a12260ed 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -286,13 +286,13 @@ static void discard_buffers(struct libxenvchan *ctrl) { } } -int data_loop(struct libxenvchan *ctrl, int input_fd, int output_fd) +int data_loop(struct vchan_proxy_state *state) { int ret; int libxenvchan_fd; int max_fd; - libxenvchan_fd = libxenvchan_fd_for_select(ctrl); + libxenvchan_fd = libxenvchan_fd_for_select(state->ctrl); for (;;) { fd_set rfds; fd_set wfds; @@ -300,15 +300,15 @@ int data_loop(struct libxenvchan *ctrl, int input_fd, int output_fd) FD_ZERO(&wfds); max_fd = -1; - if (input_fd != -1 && insiz != BUFSIZE) { - FD_SET(input_fd, &rfds); - if (input_fd > max_fd) - max_fd = input_fd; + if (state->input_fd != -1 && insiz != BUFSIZE) { + FD_SET(state->input_fd, &rfds); + if (state->input_fd > max_fd) + max_fd = state->input_fd; } - if (output_fd != -1 && outsiz) { - FD_SET(output_fd, &wfds); - if (output_fd > max_fd) - max_fd = output_fd; + if (state->output_fd != -1 && outsiz) { + FD_SET(state->output_fd, &wfds); + if (state->output_fd > max_fd) + max_fd = state->output_fd; } FD_SET(libxenvchan_fd, &rfds); if (libxenvchan_fd > max_fd) @@ -319,52 +319,53 @@ int data_loop(struct libxenvchan *ctrl, int input_fd, int output_fd) exit(1); } if (FD_ISSET(libxenvchan_fd, &rfds)) { - libxenvchan_wait(ctrl); - if (!libxenvchan_is_open(ctrl)) { + libxenvchan_wait(state->ctrl); + if (!libxenvchan_is_open(state->ctrl)) { if (verbose) fprintf(stderr, "vchan client disconnected\n"); while (outsiz) - socket_wr(output_fd); - close(output_fd); - close(input_fd); - discard_buffers(ctrl); + socket_wr(state->output_fd); + close(state->output_fd); + close(state->input_fd); + discard_buffers(state->ctrl); break; } - vchan_wr(ctrl); + vchan_wr(state->ctrl); } - if (FD_ISSET(input_fd, &rfds)) { - ret = read(input_fd, inbuf + insiz, BUFSIZE - insiz); + if (FD_ISSET(state->input_fd, &rfds)) { + ret = read(state->input_fd, inbuf + insiz, BUFSIZE - insiz); if (ret < 0 && errno != EAGAIN) exit(1); if (verbose) fprintf(stderr, "from-unix: %.*s\n", ret, inbuf + insiz); if (ret == 0) { /* EOF on socket, write everything in the buffer and close the - * input_fd socket */ + * state->input_fd socket */ while (insiz) { - vchan_wr(ctrl); - libxenvchan_wait(ctrl); + vchan_wr(state->ctrl); + libxenvchan_wait(state->ctrl); } - close(input_fd); - input_fd = -1; + close(state->input_fd); + state->input_fd = -1; /* TODO: maybe signal the vchan client somehow? */ break; } if (ret) insiz += ret; - vchan_wr(ctrl); + vchan_wr(state->ctrl); } - if (FD_ISSET(output_fd, &wfds)) - socket_wr(output_fd); - while (libxenvchan_data_ready(ctrl) && outsiz < BUFSIZE) { - ret = libxenvchan_read(ctrl, outbuf + outsiz, BUFSIZE - outsiz); + if (FD_ISSET(state->output_fd, &wfds)) + socket_wr(state->output_fd); + while (libxenvchan_data_ready(state->ctrl) && outsiz < BUFSIZE) { + ret = libxenvchan_read(state->ctrl, outbuf + outsiz, + BUFSIZE - outsiz); if (ret < 0) exit(1); if (verbose) fprintf(stderr, "from-vchan: %.*s\n", ret, outbuf + outsiz); outsiz += ret; - socket_wr(output_fd); + socket_wr(state->output_fd); } } return 0; @@ -481,7 +482,7 @@ int main(int argc, char **argv) ret = 1; break; } - if (data_loop(state.ctrl, state.input_fd, state.output_fd) != 0) + if (data_loop(&state) != 0) break; /* keep it running only when get UNIX socket path */ if (socket_path[0] != '/') @@ -504,7 +505,7 @@ int main(int argc, char **argv) ret = 1; break; } - if (data_loop(state.ctrl, state.input_fd, state.output_fd) != 0) + if (data_loop(&state) != 0) break; /* don't reconnect if output was stdout */ if (strcmp(socket_path, "-") == 0) From patchwork Thu Jun 11 03:29:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11599191 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D6F792A for ; Thu, 11 Jun 2020 03:32:35 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 071392075F for ; Thu, 11 Jun 2020 03:32:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eUweJLbD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 071392075F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvf-0008Dw-5z; Thu, 11 Jun 2020 03:30:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvd-0007xd-Sc for xen-devel@lists.xenproject.org; Thu, 11 Jun 2020 03:30:57 +0000 X-Inumbo-ID: e98808b4-ab93-11ea-bb8b-bc764e2007e4 Received: from mail-qk1-x743.google.com (unknown [2607:f8b0:4864:20::743]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e98808b4-ab93-11ea-bb8b-bc764e2007e4; Thu, 11 Jun 2020 03:30:35 +0000 (UTC) Received: by mail-qk1-x743.google.com with SMTP id l17so4334414qki.9 for ; Wed, 10 Jun 2020 20:30:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jBbbs2empnWr4OrIOc7w1Xk6T14OGQN0B87vFfy4hdE=; b=eUweJLbDTdnBpX5SsoXJM2K72GHviq9XjGrlOwvQdhlGZgtM7K6IU/8iFa31ui8Uku R8vJOtPfanGzGUKPQeP3uBP2uQAFdwa4qLqRATFfQfiCpBuCvtTH2sYVrc9C2Ibx6xo8 fxaB+NQMiBkskXxATPZMz0bVZj/7G2nIIeRZnNvgQxG/2GYaZRe8SGCxLY5ne7E42iqN J5alV1dzQQeAge8bVtBdmBw5KVYIfgXZiCF87dKkOxUPQOTFXPLc79SI7pAFRhgEqtm2 2UYqHkgyRtp9TMuEnIAElZK2pkoyvWrhv4ZJJXXrF80PCYehydckhABoe/6LJMI/58dI /9wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jBbbs2empnWr4OrIOc7w1Xk6T14OGQN0B87vFfy4hdE=; b=aIX0VGeh/2xY+KHIFGKD0zzRibkv91NFoZ1oafy3t/9ESYx9O6VSgPlC260Blyq5mX yeJ1Sn5W8R3MoaWXqpb2QhKv+hXQDyRX53BrzzONOzX69dDY9HAsBMgPieP3cTlxI1ae wA6XrVFdVTx8xTwW6GI0Mt0Tk3DHnqhHm5MvTSaDpN4h2OPO0DHg3/5Vn60Spoz/uszD BYzccuM3NEsTwQ92a0+7TA4QOsQ565R7z0kb2xymKRH8tKTQd56FmBk5rX44XCY+7EI2 bY9cZEZL5Vavx3Uuwq9BEDAEtSK2zhdxo0kRlmd6ye4GupwZXMuWj2Q+bVNKs50MT47t aSkw== X-Gm-Message-State: AOAM5307KM25A1ur7TZ0+bSIM8/wvtC7hw9NGqnc2hQ2+wDnIzHPHJR2 Bn+Zby0Wke0Bc09IlGHafiwK7m/D X-Google-Smtp-Source: ABdhPJyUgzppKig/FkUgRMJXAOFXdwdkz9Bo8jHpQNMRLt+rs6RiduerxyRzPMSEA+M3JN5rCx1C0g== X-Received: by 2002:ae9:e10f:: with SMTP id g15mr6616600qkm.285.1591846234982; Wed, 10 Jun 2020 20:30:34 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:dd4d:2b5c:f471:f332]) by smtp.gmail.com with ESMTPSA id v3sm1164078qkh.130.2020.06.10.20.30.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 20:30:34 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH v2 08/10] vchan-socket-proxy: Set closed FDs to -1 Date: Wed, 10 Jun 2020 23:29:34 -0400 Message-Id: <20200611032936.350657-9-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200611032936.350657-1-jandryuk@gmail.com> References: <20200611032936.350657-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" These FDs are closed, so set them to -1 so they are no longer valid. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index 29a12260ed..cd7629bc4e 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -326,7 +326,9 @@ int data_loop(struct vchan_proxy_state *state) while (outsiz) socket_wr(state->output_fd); close(state->output_fd); + state->output_fd = -1; close(state->input_fd); + state->input_fd = -1; discard_buffers(state->ctrl); break; } From patchwork Thu Jun 11 03:29:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11599175 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A60DF1392 for ; Thu, 11 Jun 2020 03:31:22 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 812342072E for ; Thu, 11 Jun 2020 03:31:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f37z0AnH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 812342072E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvj-0008Hz-G7; Thu, 11 Jun 2020 03:31:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvi-0007xd-Sw for xen-devel@lists.xenproject.org; Thu, 11 Jun 2020 03:31:02 +0000 X-Inumbo-ID: eab8e834-ab93-11ea-bca7-bc764e2007e4 Received: from mail-qt1-x841.google.com (unknown [2607:f8b0:4864:20::841]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id eab8e834-ab93-11ea-bca7-bc764e2007e4; Thu, 11 Jun 2020 03:30:37 +0000 (UTC) Received: by mail-qt1-x841.google.com with SMTP id g18so3576001qtu.13 for ; Wed, 10 Jun 2020 20:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tzm6Mh214muY5lx/rQlFhXvADj4YlPdVI5v2o4d8yuk=; b=f37z0AnH7+bYS0HKpYVntf0Qni0Aax6duvGiA3QSII8dzY4/Y72MpGqWpFnuFiS8gf vgtf+XD0TsYKzn4HeCrQVZet9wK5nHD98GARtJiz/irbBvdJsoAdDD3yx2uy45wqmS1O PHcZq5j8+xFBlp6Qkt/LgeoEoxJZvVbbKAKTCh+j6qr69rsY7zHvFT6PeBkq4JTJS7a1 j2ocbNDwhPGvqBSL1aRrdvXXH22qvWpSIF97vZOzHl6bCUDqqQ17V3VufgHItwBs2lQS Lx46+um3MJmmemuAifhN+PyjJHBFDBZ5WvT45MVle0ffY0gGwNpRuie8HhJkq3irStIZ LnZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tzm6Mh214muY5lx/rQlFhXvADj4YlPdVI5v2o4d8yuk=; b=hZ2bLqrwSFihmh/Np2/D6+5QHto4+BIrIzOrzbRDfxkN+S2TbO2R3JtygRnS5W1JGx jG5ZV4/7QKJ5QT+UXS0jVh7SEjHYahxppIaYF9JjdYhLKsHvam9cAD1CYPmTD6inueCT zm6U26h1SK4jr+b3G+DVBt3WZCQ4KJMfFeF33P1AosHwgeWbMm3Xec62BCVwZ4skaYZY g40X41Bc9PXvKUHRk3cBpZOO2AXVFHWv9T03yfnmGmIbr3AvCEhHWD+7BbjezN2skhkK 5WfvKnOpvAgrDKSX+nvX8NVP4fMWKWVnZTGmD5E+6VkNpATaA3XnblisD8x55OK61mgE 85YA== X-Gm-Message-State: AOAM5304A45kITz6hvRl/u3R8fnY8zZV9JX6JIE8h0y6PQv1iqZUl8Yb yCDjNUV5NSrbpQJY1CJKq83Clb/X X-Google-Smtp-Source: ABdhPJxmdePJkrVa2BdhDezcmAvxku0TI6Mdn10/VkgQUT3queN0E8kb8S6GrS020z7e8W5WLa0n8w== X-Received: by 2002:ac8:7cd:: with SMTP id m13mr6539169qth.332.1591846236971; Wed, 10 Jun 2020 20:30:36 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:dd4d:2b5c:f471:f332]) by smtp.gmail.com with ESMTPSA id v3sm1164078qkh.130.2020.06.10.20.30.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 20:30:36 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH v2 09/10] vchan-socket-proxy: Cleanup resources on exit Date: Wed, 10 Jun 2020 23:29:35 -0400 Message-Id: <20200611032936.350657-10-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200611032936.350657-1-jandryuk@gmail.com> References: <20200611032936.350657-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Close open FDs and close th vchan connection when exiting the program. This addresses some Coverity findings about leaking file descriptors. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index cd7629bc4e..3552783ec2 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -518,5 +518,14 @@ int main(int argc, char **argv) } } + if (state.output_fd >= 0) + close(state.output_fd); + if (state.input_fd >= 0) + close(state.input_fd); + if (state.ctrl) + libxenvchan_close(state.ctrl); + if (socket_fd >= 0) + close(socket_fd); + return ret; } From patchwork Thu Jun 11 03:29:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11599193 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60CCA912 for ; Thu, 11 Jun 2020 03:37:25 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 32A122072F for ; Thu, 11 Jun 2020 03:37:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M48EJOMI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32A122072F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjE1E-0000Ys-5z; Thu, 11 Jun 2020 03:36:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjDvn-0007xd-T0 for xen-devel@lists.xenproject.org; Thu, 11 Jun 2020 03:31:07 +0000 X-Inumbo-ID: ebcd4792-ab93-11ea-bca7-bc764e2007e4 Received: from mail-qt1-x843.google.com (unknown [2607:f8b0:4864:20::843]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ebcd4792-ab93-11ea-bca7-bc764e2007e4; Thu, 11 Jun 2020 03:30:39 +0000 (UTC) Received: by mail-qt1-x843.google.com with SMTP id g62so3610368qtd.5 for ; Wed, 10 Jun 2020 20:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=khKs/ueL3SKxrTYIvshrhZXLqxoI5KFK9g9nhuvMTiw=; b=M48EJOMIzperQGLcjFAMzo6UJzx6vE/5utVAUhmsnb5gX/0yhT9UkQIc/2ewu5q7vu qG1JtDY8t4coEvAkbyiMff2EyUOd/qsb6bXPz1cDbtbzJRZ0woc0FxjunV3XgUdYMLp5 byeQw4/DhQrQKgOQ1sWB7kEmNQwacDmy7x6c5VCanLS9bjhcd9msTUilIWIf2vnlMJha uoAx7ggRaq4iPdA9wXn3d+JMh8OZzSqJKMvqamstebItR5lrKQaKQZ1LqgLajPbVrWh5 MqP9Y0NtPT+MLnqlMNbOrwVsNHM6MhnSauSruqBPvKnrbEbCEWXFCGh7WR0y0hykLn+T Q7gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=khKs/ueL3SKxrTYIvshrhZXLqxoI5KFK9g9nhuvMTiw=; b=mKi4c3LrZmw7jHAVRpQVfNdiAl5CghU6BJFtbG+89rIEN5hoYn4APSgG1vS9jdjL9F zgE3oT3n9nisOQJQ2F16AwNJF4Dt/By9cVv3Y+MPXmL4LAGADNuj0u4fsviwrDMz73YX x1DDdbPrY82TuSFq732OWJ2+RFVwgE4fVOPpEfPGWNjgY1IDc5B0uKHrC2aEtka2eKO5 KAgbNVWYxtuBWTiCOsoSj81zwO8MCIw4cqXwvwmbByzJsxWQavM4ey8D98LfxDQH9AtP t8rPZHQb3zw8i6erGGMkZX4TgZy03GaBZ39HTM5QL6HS0RWcE47nF6cZoMpFJmbnEY+d UT0A== X-Gm-Message-State: AOAM531ZWG6nJJAEur1KaXRZNgKhUauaDYfH7jzNx2YyMdUgqj9HPoBi RsK0P/zUg988PylZLvm4M24VfVLo X-Google-Smtp-Source: ABdhPJw8KtmXLensobiDVVb6TjPFlvpUQ+j3O+FqXc7Hj+hM6FWMuk/H1OsnljFEAFJkGcJ/Ig7d9w== X-Received: by 2002:ac8:7b4d:: with SMTP id m13mr6922467qtu.165.1591846238793; Wed, 10 Jun 2020 20:30:38 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:dd4d:2b5c:f471:f332]) by smtp.gmail.com with ESMTPSA id v3sm1164078qkh.130.2020.06.10.20.30.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 20:30:38 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH v2 10/10] vchan-socket-proxy: Handle closing shared input/output_fd Date: Wed, 10 Jun 2020 23:29:36 -0400 Message-Id: <20200611032936.350657-11-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200611032936.350657-1-jandryuk@gmail.com> References: <20200611032936.350657-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" input_fd & output_fd may be the same FD. In that case, mark both as -1 when closing one. That avoids a dangling FD reference. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index 3552783ec2..e1d959c6d1 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -349,6 +349,8 @@ int data_loop(struct vchan_proxy_state *state) libxenvchan_wait(state->ctrl); } close(state->input_fd); + if (state->input_fd == state->output_fd) + state->output_fd = -1; state->input_fd = -1; /* TODO: maybe signal the vchan client somehow? */ break;