From nobody Mon Feb 9 08:55:37 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590375090; cv=none; d=zohomail.com; s=zohoarc; b=SknA7JKze3oVfER5fUrq2+2Rol8OkQAbsJ44QgQDcl86DW4lmxsARu0/luMWn6GoHL5A2I3YMNUITgSKV3lIcSibbP2dtk7SNG/39IhjGkarRtbo4e0t7E1yBPLVtG7yL2ROtctnQlPsHW9JL4tPfY9RvJVLtZMl5qqtptl9oXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590375090; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y9V1tgqrbsz8wnP0O1UzYnljlbdkN5+LC5mMxx9pPO4=; b=aJrRdvAD40Bb6Gul8Vt0gcoS7+bh0Sn2w/oTZdCJJ4xKQMJfC6cfB3uJa4uhcvZKa0IeELmeFkASF6NFOR647UusZXJT8/xH2vnbpkodaPwLIzDuTZ2VxFV/yqEn2uFjE8t/0y47ag8qmhsZPVtWBRIqaKXlDha3w66BFYTSAgY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1590375090912480.59449129239863; Sun, 24 May 2020 19:51:30 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Cl-0004PA-H9; Mon, 25 May 2020 02:51:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Ck-0004Ol-EJ for xen-devel@lists.xenproject.org; Mon, 25 May 2020 02:51:06 +0000 Received: from mail-qv1-xf41.google.com (unknown [2607:f8b0:4864:20::f41]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9005aba2-9e32-11ea-ae69-bc764e2007e4; Mon, 25 May 2020 02:50:59 +0000 (UTC) Received: by mail-qv1-xf41.google.com with SMTP id r3so7548284qve.1 for ; Sun, 24 May 2020 19:50:59 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:344b:9349:9475:b6a2]) by smtp.gmail.com with ESMTPSA id h134sm13539512qke.6.2020.05.24.19.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 19:50:57 -0700 (PDT) X-Inumbo-ID: 9005aba2-9e32-11ea-ae69-bc764e2007e4 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=y9V1tgqrbsz8wnP0O1UzYnljlbdkN5+LC5mMxx9pPO4=; b=cnyTYQB33jVd69hyM6RmnHA2+rsRnAQVdhGjUC68MMxQbGsHlnpStndqhrcOoLGwP/ HYVqoiTnWJ2kqpJWiL8Bk0dIOJh3eX0LNrS/pUvRQThjvzfT9VwKZ8VfXIxNJg+fAOVe OWJbriZfk4xqj82/E97TCGsSDT3LwGAzdAJ3uDfIx42sfsBrbuHRv+OZnkfq3eUz1gZr DzzZ1FOcOenLRZTw/6EbgwUfjRpqwyWmTmF1C09A4f7HTCrxgIoES9wTtYs2gJMjZadn llK0U86PwKlQiTIrGqk9zWjaty7YAYwO/nLMPL8S3MGcYtZl55oo2ul0ugX4UK3fFK+C PlVA== 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=y9V1tgqrbsz8wnP0O1UzYnljlbdkN5+LC5mMxx9pPO4=; b=eRpKNsmN75ja5iSBHa72gxeGSIOr6CSFZNv0pkUNOaT55RuwlY7hllOP8ActCLbIKU O44KDq5bY3n8YwGGcjg/q3ux+IN65ZZVQVBZy4Jfau6yBNkQ80mU7B/cFqWb7bea0MPU mY/S0pMxfNKlFKR5r5TbswTnZi5f7LxPlrp5BIHf/euJXv+ccdFjKqJ79IVmi7UXecWL F3mw1dUdxejdcB7cgN+WimeVzNSBgQSywfc5aXkzS0WIIF6nVE7k2chvR1dXoQcWUiPX L8KHszXRQf/SIzAaM005foTah6Vr1jCjMYon1FW4uAuDEKrBE89NweOlXNC5J6yTwZPB AZcQ== X-Gm-Message-State: AOAM530OFos4XhXiBl7Snty1KSGgDaeb3vL/yZ8gU+/x2GsqHTdytYZw uLtrtbwDUdsW4IwxuX8v7mxh0d+J X-Google-Smtp-Source: ABdhPJyeCUoOdYimoZsXvuzqA0tzdnRAtxmTY6XHOdXIW6cDTT6vGhf5s3BHQpaKoNNCv5yFr+iCog== X-Received: by 2002:ad4:57cb:: with SMTP id y11mr13770669qvx.26.1590375058455; Sun, 24 May 2020 19:50:58 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH 4/8] vchan-socket-proxy: Use a struct to store state Date: Sun, 24 May 2020 22:49:51 -0400 Message-Id: <20200525024955.225415-5-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200525024955.225415-1-jandryuk@gmail.com> References: <20200525024955.225415-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 , marmarek@invisiblethingslab.com, Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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-soc= ket-proxy.c index d85e24ee93..39f4bb1452 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -89,6 +89,12 @@ int insiz =3D 0; int outsiz =3D 0; int verbose =3D 0; =20 +struct vchan_proxy_state { + struct libxenvchan *ctrl; + int output_fd; + int input_fd; +}; + static void vchan_wr(struct libxenvchan *ctrl) { int ret; =20 @@ -374,8 +380,9 @@ int main(int argc, char **argv) { int is_server =3D 0; int socket_fd =3D -1; - int input_fd, output_fd; - struct libxenvchan *ctrl =3D NULL; + struct vchan_proxy_state state =3D { .ctrl =3D NULL, + .input_fd =3D -1, + .output_fd =3D -1 }; const char *socket_path; int domid; const char *vchan_path; @@ -415,15 +422,15 @@ int main(int argc, char **argv) socket_path =3D argv[optind+2]; =20 if (is_server) { - ctrl =3D libxenvchan_server_init(NULL, domid, vchan_path, 0, 0); - if (!ctrl) { + state.ctrl =3D libxenvchan_server_init(NULL, domid, vchan_path, 0,= 0); + if (!state.ctrl) { perror("libxenvchan_server_init"); exit(1); } } else { if (strcmp(socket_path, "-") =3D=3D 0) { - input_fd =3D 0; - output_fd =3D 1; + state.input_fd =3D 0; + state.output_fd =3D 1; } else { socket_fd =3D listen_socket(socket_path); if (socket_fd =3D=3D -1) { @@ -453,21 +460,21 @@ int main(int argc, char **argv) for (;;) { if (is_server) { /* wait for vchan connection */ - while (libxenvchan_is_open(ctrl) !=3D 1) - libxenvchan_wait(ctrl); + while (libxenvchan_is_open(state.ctrl) !=3D 1) + libxenvchan_wait(state.ctrl); /* vchan client connected, setup local FD if needed */ if (strcmp(socket_path, "-") =3D=3D 0) { - input_fd =3D 0; - output_fd =3D 1; + state.input_fd =3D 0; + state.output_fd =3D 1; } else { - input_fd =3D output_fd =3D connect_socket(socket_path); + state.input_fd =3D state.output_fd =3D connect_socket(sock= et_path); } - if (input_fd =3D=3D -1) { + if (state.input_fd =3D=3D -1) { perror("connect socket"); ret =3D 1; break; } - if (data_loop(ctrl, input_fd, output_fd) !=3D 0) + if (data_loop(state.ctrl, state.input_fd, state.output_fd) != =3D 0) break; /* keep it running only when get UNIX socket path */ if (socket_path[0] !=3D '/') @@ -475,28 +482,29 @@ int main(int argc, char **argv) } else { /* wait for local socket connection */ if (strcmp(socket_path, "-") !=3D 0) - input_fd =3D output_fd =3D accept(socket_fd, NULL, NULL); - if (input_fd =3D=3D -1) { + state.input_fd =3D state.output_fd =3D accept(socket_fd, + NULL, NULL); + if (state.input_fd =3D=3D -1) { perror("accept"); ret =3D 1; break; } - set_nonblocking(input_fd, 1); - set_nonblocking(output_fd, 1); - ctrl =3D connect_vchan(domid, vchan_path); - if (!ctrl) { + set_nonblocking(state.input_fd, 1); + set_nonblocking(state.output_fd, 1); + state.ctrl =3D connect_vchan(domid, vchan_path); + if (!state.ctrl) { perror("vchan client init"); ret =3D 1; break; } - if (data_loop(ctrl, input_fd, output_fd) !=3D 0) + if (data_loop(state.ctrl, state.input_fd, state.output_fd) != =3D 0) break; /* don't reconnect if output was stdout */ if (strcmp(socket_path, "-") =3D=3D 0) break; =20 - libxenvchan_close(ctrl); - ctrl =3D NULL; + libxenvchan_close(state.ctrl); + state.ctrl =3D NULL; } } =20 --=20 2.25.1