From nobody Sun Apr 6 03:25:52 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1736922421; cv=none; d=zohomail.com; s=zohoarc; b=aNfQcQZHL4ShhO9p9vrxk4NtmHLPGWLtAnWE5PrjeSg0YIKa6rsTK0LdwB9unNRCKod/lssQjngkmFbzwSXuC+R+2xf28c8PH5/zkyIiu08gDp5o3bxtJo8cugbzXo1pskDiYhBacSVGrW2GTMZTTLssAYyiZrcJucJT13HQPvU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1736922421; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Pdcvm4r1FFh3mjhqnqaxRGqrOq+krKeGclEgq6h25tg=; b=XCP9cCkMebK+oZCxxuTdIxqBJMlYwEXqTrm5uW3tPXQAMB54j41tbWpOYKJHvPAfW46L4e3x+Gyqlj2vIOczML+AJbu3jlRhnPHftQdQg9wByO/BeIcpxEG5ZIPO7TzJcWQsX+sG7OMORcfYFxIlKlJN9XeZS+0SXE8wzchCtFo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1736922421091152.28236823439727; Tue, 14 Jan 2025 22:27:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXwqs-0005fG-EY; Wed, 15 Jan 2025 01:26:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tXwqq-0005el-DL for qemu-devel@nongnu.org; Wed, 15 Jan 2025 01:26:04 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tXwqo-0006XT-FT for qemu-devel@nongnu.org; Wed, 15 Jan 2025 01:26:03 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2161eb94cceso77607265ad.2 for ; Tue, 14 Jan 2025 22:26:02 -0800 (PST) Received: from localhost ([157.82.203.37]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21a9f10f97csm76565705ad.16.2025.01.14.22.25.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Jan 2025 22:26:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1736922361; x=1737527161; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Pdcvm4r1FFh3mjhqnqaxRGqrOq+krKeGclEgq6h25tg=; b=Xq5jWB4N8crDa6D42Wy5UbO7Ep62/K8RwYu7HmVzKY7pOLdhTxe+MJVQU7s8GRELHH aa60qc2/jXhKmoydxoVqD66R51ARVXV7nHe1L+Y5Sc2HU1b6oQjN77IH26wdfYn6D6fH in8QFiNZbAp550I/Nuz+I73zx1B2cuj2gVG6CoMvM7mI4CnP943zFJ2Sex2Yn3p1plev sHEZCFRe7Nwx/c/DFEwgF4nt4nyd8QRnBkL8uZ5L7tZP5vGUnWFfK7chlrlD6Jtd2tTp iBJbzrKpGFVCD+kKeLaUFcNS3+JjvhOaPS5vd6XqAjxaEJ4uGihj5d4zN0GbXsuY/TDB HMYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736922361; x=1737527161; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pdcvm4r1FFh3mjhqnqaxRGqrOq+krKeGclEgq6h25tg=; b=ubauyHrgLhpkbjDclwUv9tbhpqip1aWZLx+Js/5dceQIyRgYOkLbrrwu2m3A0Gicpc TmpfqDHW4P5mMt0d+Ru5OrgbYGYmTICpDUfyrewAKCB2+5ND3VZQnteg/BpvBQufZxXx xBBLPm3jI2yBps7T6ltVtYn1PiN2nWMYCEPjIMQKppuhEaYTad4zijoh4I7ndGbetceM 69zFACV0Y+ZFoxkgMhRebHLGXIIXjmmUIrb1xvGepjm1crZ3sRMlFIOZ/CQ9e/+P/0Qq IzYo4HK/z31fOTDYlFEDSO9CYQTAryupIvpEhKNN2qyq04Or3Wl7c5ZUYgn8kl81bedj rpVg== X-Gm-Message-State: AOJu0Yx4c9z89rNwOSXCa1S7//w7RAb4VXo5qOWmeiKpHEFnshRXaPoQ XsvYDDzoShL3oB46InwI6uZrIN1QL4HA6aj3xhyowYyy5G9xdq++Sz7rvM/v2W0= X-Gm-Gg: ASbGnctmTyq1iJO32nElDDT83PLdy66TYh6lMBZW+ASETcEzyCrKW71ZVhO946M2/ZD SbD075tlqkP4fBcly/o+VjufgthTYmT6f581Ni/L7H20rFHtmGdnXLB3/EjQvQ2MaVOl0C4FRDi qti5sZYfwHGZeQDEQGa2M9DnARvjk7AZJVROV8crxbvbhZvTor2lRIYesyI2eu+0lldlOV6Y2YE eSVF8F8s8XBiL3PdmtBbjO3lB36HPUQA6ZrSQwi+mWfVaeY73itgDbzji0= X-Google-Smtp-Source: AGHT+IG7TdAwhLeVX2A4dCE/eNC9Oh9DqjvjsX2UJ9zSLDGU0IAo3zNr8oAgWMDKgfV3YU9AVXhlGA== X-Received: by 2002:a17:902:e84f:b0:216:410d:4c53 with SMTP id d9443c01a7336-21a83fc6db1mr389792495ad.41.1736922361061; Tue, 14 Jan 2025 22:26:01 -0800 (PST) From: Akihiko Odaki Date: Wed, 15 Jan 2025 15:25:46 +0900 Subject: [PATCH v3 1/2] glib-compat: Define g_spawn_check_wait_status() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250115-glib-v3-1-bd3153344698@daynix.com> References: <20250115-glib-v3-0-bd3153344698@daynix.com> In-Reply-To: <20250115-glib-v3-0-bd3153344698@daynix.com> To: Jason Wang , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki , Lei Yang X-Mailer: b4 0.14-dev-fd6e3 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=2607:f8b0:4864:20::629; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1736922421840019000 g_spawn_check_exit_status() is renamed to g_spawn_check_wait_status() in 2.70. Signed-off-by: Akihiko Odaki Tested-by: Lei Yang --- include/glib-compat.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/glib-compat.h b/include/glib-compat.h index 86be439ba0ef..a553ba13a36e 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -68,6 +68,17 @@ * without generating warnings. */ =20 +static inline gboolean g_spawn_check_wait_status_qemu(gint wait_status, + GError **error) +{ +#if GLIB_CHECK_VERSION(2, 70, 0) + return g_spawn_check_wait_status(wait_status, error); +#else + return g_spawn_check_exit_status(wait_status, error); +#endif +} +#define g_spawn_check_wait_status(w, e) g_spawn_check_wait_status_qemu(w, = e) + /* * g_memdup2_qemu: * @mem: (nullable): the memory to copy. --=20 2.47.1 From nobody Sun Apr 6 03:25:52 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1736922414; cv=none; d=zohomail.com; s=zohoarc; b=P/SsPn+AlKuSjEVdvq9lv0dwOU3O5DOkGuTR5ndr0T+rxVY/CzvkC+CDusCwanMhC7VcfLN8hc8X9Ljw9QBCi3iG/qpLFsYQMRm596mPuwS0IMuQntU7cFTjBDGnnISil+AsRT9N2K8ZHE0QeklukRtCZWEo1q0/lOPY/qwDXNU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1736922414; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LbKIAcs32T5KVRGK6kz0Z6vHisYjym1l27iUCi/5cQ4=; b=Jra/RKBZiCvlC8BF5UKD99FL4K2xZC99oy6klEoCmNRDLVO2+593g/yysoYrICv2B5Vbpii6G5IXmO3d+206BZKZ90g2NPf8XKMCk1NQHjfXu1bOvEjiU7kwwX3gw2FRB6Fk8AiFpFF6VgX4qqKyy29wgN3+MMT133Ll2xV72t8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1736922414636630.0187423602474; Tue, 14 Jan 2025 22:26:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXwqx-0005gp-0G; Wed, 15 Jan 2025 01:26:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tXwqu-0005fO-VQ for qemu-devel@nongnu.org; Wed, 15 Jan 2025 01:26:08 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tXwqs-0006Xr-Vo for qemu-devel@nongnu.org; Wed, 15 Jan 2025 01:26:08 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-2163b0c09afso116533305ad.0 for ; Tue, 14 Jan 2025 22:26:06 -0800 (PST) Received: from localhost ([157.82.203.37]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72d40591ff4sm8410059b3a.77.2025.01.14.22.26.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Jan 2025 22:26:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1736922365; x=1737527165; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=LbKIAcs32T5KVRGK6kz0Z6vHisYjym1l27iUCi/5cQ4=; b=0r61FBimwPscphxtUefr8hK7CT6tJs2Hx/g8GRds9huaD0F4mrC/YW7dGpymK+IQFZ 9kDpLgFNDBtHcq0DMSbjsPmQIAu0gS9Z2YIkFz4ykoSe0ahPKy96oWY2YYaCSZdYx2eP TXGHm4f9Rg8K1jEN3GLAI3UNqKohvApR4LYVTTsHxIKZKnmgUTquKEmRWfvKvrPRMH2H Zgww/g8UlBJqgWtb894hwYy4aJmv1XnsWvXK46jyLPwElgGFYFi73EZ/NqekvaORqCTv k1PvCS1uCStzaWksrPAua+OmyTFUbHdJIv6xU2XQmvB3G1lTaNVwhuAsJMDgBt//iGFk +3HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736922365; x=1737527165; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LbKIAcs32T5KVRGK6kz0Z6vHisYjym1l27iUCi/5cQ4=; b=YTDIXhSr+IsvVRfJYB8a24eUBER0E3Q33Evog92hEyQiWFIULTblzImRMuRdXOccee q/0Vh+B45mt0QkzR3WNf0BrOMaCI86CgElabf7D3SyMZFQE4gR6wYyeJFaYLLUkQYoTA Nw8ywWKiInmzwIX7jdlvlFhsHLbsnudFVfnNtn5r2T65Mpcx8Z7YgJPSWxD6n+RTvN06 fqZyxJhDPOwsi/DagUZkI1/w1OkUhk5Y9x15uoSbEhQoDgq4YfILt2PBD6KIWpARwh0G +PqVonBBuN8E03AkYxnt9MUuUfGHscf/Q6qWul5y4+mE4HiVZBJYlMQssWVOfuku/Exu kZcw== X-Gm-Message-State: AOJu0YyV2hol4pePWU5KsZFc+T7LKhzhlP+1COFOOfJ6YVPzi7nRNJCW ZTjwnXKB0imiVeKI1bIve1cFa4gYC15gMif2uhawDkBApxKmbyGvJFIMtVIGSbY= X-Gm-Gg: ASbGnctBsduyxCR3wkOndPiqpfOYTwXvAD7VOdDMWMnE9emWJzYMc8+wf4az8bsmlp/ kZR6F1WlrsbUsAAYFyAB6bZ2bl61hfSz1XaXF9MwAPBSNZHetm8/TZl93DJ4Z5RTaACZkAMvGGv wt+wL9Ilppy+DcbmP8ThN1sFp4hAjRN9o+sLrsUixsL+74ACYmzxbNYwNpMB5cFEN1XueQKKu+4 vt0h31o0rQo5cr55FxlgneFLonhy2ujnzwuWOtZzZj/eURanebE9sev8Vc= X-Google-Smtp-Source: AGHT+IEojZn+RG19fjTflRGbA0HAfwGHw/h4NvXHQS+t7Jc283fTgUnM3lsTV6k9SxziE3MbHSa8zg== X-Received: by 2002:a05:6a00:368d:b0:727:99a8:cd31 with SMTP id d2e1a72fcca58-72d21f47fc5mr38197913b3a.14.1736922365113; Tue, 14 Jan 2025 22:26:05 -0800 (PST) From: Akihiko Odaki Date: Wed, 15 Jan 2025 15:25:47 +0900 Subject: [PATCH v3 2/2] tap: Use g_spawn_sync() and g_spawn_check_wait_status() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250115-glib-v3-2-bd3153344698@daynix.com> References: <20250115-glib-v3-0-bd3153344698@daynix.com> In-Reply-To: <20250115-glib-v3-0-bd3153344698@daynix.com> To: Jason Wang , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki , Lei Yang X-Mailer: b4 0.14-dev-fd6e3 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=2607:f8b0:4864:20::635; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1736922416023019000 g_spawn_sync() gives an informative message if it fails to execute the script instead of reporting exiting status 1. g_spawn_check_wait_status() also gives an message easier to understand than the raw value returned by waitpid(). Signed-off-by: Akihiko Odaki Tested-by: Lei Yang --- net/tap.c | 169 ++++++++++++++++++++++++----------------------------------= ---- 1 file changed, 66 insertions(+), 103 deletions(-) diff --git a/net/tap.c b/net/tap.c index ae1c7e398321..392a024f8ed9 100644 --- a/net/tap.c +++ b/net/tap.c @@ -385,56 +385,30 @@ static TAPState *net_tap_fd_init(NetClientState *peer, return s; } =20 -static void close_all_fds_after_fork(int excluded_fd) +static void unset_cloexec(gpointer data) { - const int skip_fd[] =3D {STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, - excluded_fd}; - unsigned int nskip =3D ARRAY_SIZE(skip_fd); - - /* - * skip_fd must be an ordered array of distinct fds, exclude - * excluded_fd if already included in the [STDIN_FILENO - STDERR_FILEN= O] - * range - */ - if (excluded_fd <=3D STDERR_FILENO) { - nskip--; - } - - qemu_close_all_open_fd(skip_fd, nskip); + g_assert(!fcntl(GPOINTER_TO_INT(data), F_SETFD, 0)); } =20 static void launch_script(const char *setup_script, const char *ifname, int fd, Error **errp) { - int pid, status; - char *args[3]; - char **parg; + gint status; + gchar *argv[] =3D { (gchar *)setup_script, (gchar *)ifname, NULL }; + g_autoptr(GError) error =3D NULL; =20 /* try to launch network script */ - pid =3D fork(); - if (pid < 0) { - error_setg_errno(errp, errno, "could not launch network script %s", - setup_script); + if (!g_spawn_sync(NULL, argv, NULL, G_SPAWN_CHILD_INHERITS_STDIN, + unset_cloexec, GINT_TO_POINTER(fd), + NULL, NULL, &status, &error)) { + error_setg(errp, "could not launch network script %s: %s", + setup_script, error->message); return; } - if (pid =3D=3D 0) { - close_all_fds_after_fork(fd); - parg =3D args; - *parg++ =3D (char *)setup_script; - *parg++ =3D (char *)ifname; - *parg =3D NULL; - execv(setup_script, args); - _exit(1); - } else { - while (waitpid(pid, &status, 0) !=3D pid) { - /* loop */ - } =20 - if (WIFEXITED(status) && WEXITSTATUS(status) =3D=3D 0) { - return; - } - error_setg(errp, "network script %s failed with status %d", - setup_script, status); + if (!g_spawn_check_wait_status(status, &error)) { + error_setg(errp, "network script %s failed: %s", + setup_script, error->message); } } =20 @@ -477,6 +451,12 @@ static int net_bridge_run_helper(const char *helper, c= onst char *bridge, { sigset_t oldmask, mask; g_autofree char *default_helper =3D NULL; + g_autofree char *fd_buf =3D NULL; + g_autofree char *br_buf =3D NULL; + g_autofree char *helper_cmd =3D NULL; + g_autoptr(GError) error =3D NULL; + int fd; + int saved_errno; int pid, status; char *args[5]; char **parg; @@ -495,82 +475,65 @@ static int net_bridge_run_helper(const char *helper, = const char *bridge, return -1; } =20 - /* try to launch bridge helper */ - pid =3D fork(); - if (pid < 0) { - error_setg_errno(errp, errno, "Can't fork bridge helper"); - return -1; - } - if (pid =3D=3D 0) { - char *fd_buf =3D NULL; - char *br_buf =3D NULL; - char *helper_cmd =3D NULL; - - close_all_fds_after_fork(sv[1]); - fd_buf =3D g_strdup_printf("%s%d", "--fd=3D", sv[1]); + fd_buf =3D g_strdup_printf("%s%d", "--fd=3D", sv[1]); =20 - if (strrchr(helper, ' ') || strrchr(helper, '\t')) { - /* assume helper is a command */ + if (strrchr(helper, ' ') || strrchr(helper, '\t')) { + /* assume helper is a command */ =20 - if (strstr(helper, "--br=3D") =3D=3D NULL) { - br_buf =3D g_strdup_printf("%s%s", "--br=3D", bridge); - } - - helper_cmd =3D g_strdup_printf("%s %s %s %s", helper, - "--use-vnet", fd_buf, br_buf ? br_buf : ""); - - parg =3D args; - *parg++ =3D (char *)"sh"; - *parg++ =3D (char *)"-c"; - *parg++ =3D helper_cmd; - *parg++ =3D NULL; + if (strstr(helper, "--br=3D") =3D=3D NULL) { + br_buf =3D g_strdup_printf("%s%s", "--br=3D", bridge); + } =20 - execv("/bin/sh", args); - g_free(helper_cmd); - } else { - /* assume helper is just the executable path name */ + helper_cmd =3D g_strdup_printf("%s %s %s %s", helper, + "--use-vnet", fd_buf, br_buf ? br_buf : ""); =20 - br_buf =3D g_strdup_printf("%s%s", "--br=3D", bridge); + parg =3D args; + *parg++ =3D (char *)"sh"; + *parg++ =3D (char *)"-c"; + *parg++ =3D helper_cmd; + *parg++ =3D NULL; + } else { + /* assume helper is just the executable path name */ =20 - parg =3D args; - *parg++ =3D (char *)helper; - *parg++ =3D (char *)"--use-vnet"; - *parg++ =3D fd_buf; - *parg++ =3D br_buf; - *parg++ =3D NULL; + br_buf =3D g_strdup_printf("%s%s", "--br=3D", bridge); =20 - execv(helper, args); - } - g_free(fd_buf); - g_free(br_buf); - _exit(1); + parg =3D args; + *parg++ =3D (char *)helper; + *parg++ =3D (char *)"--use-vnet"; + *parg++ =3D fd_buf; + *parg++ =3D br_buf; + *parg++ =3D NULL; + } =20 - } else { - int fd; - int saved_errno; + /* try to launch bridge helper */ + if (!g_spawn_async(NULL, args, NULL, + G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_CHILD_INHERITS_= STDIN, + unset_cloexec, GINT_TO_POINTER(sv[1]), &pid, &error= )) { + error_setg(errp, "could not launch bridge helper: %s", error->mess= age); + return -1; + } =20 - close(sv[1]); + close(sv[1]); =20 - fd =3D RETRY_ON_EINTR(recv_fd(sv[0])); - saved_errno =3D errno; + fd =3D RETRY_ON_EINTR(recv_fd(sv[0])); + saved_errno =3D errno; =20 - close(sv[0]); + close(sv[0]); =20 - while (waitpid(pid, &status, 0) !=3D pid) { - /* loop */ - } - sigprocmask(SIG_SETMASK, &oldmask, NULL); - if (fd < 0) { - error_setg_errno(errp, saved_errno, - "failed to recv file descriptor"); - return -1; - } - if (!WIFEXITED(status) || WEXITSTATUS(status) !=3D 0) { - error_setg(errp, "bridge helper failed"); - return -1; - } - return fd; + while (waitpid(pid, &status, 0) !=3D pid) { + /* loop */ } + sigprocmask(SIG_SETMASK, &oldmask, NULL); + if (fd < 0) { + error_setg_errno(errp, saved_errno, + "failed to recv file descriptor"); + return -1; + } + if (!g_spawn_check_wait_status(status, &error)) { + error_setg(errp, "bridge helper failed: %s", error->message); + return -1; + } + return fd; } =20 int net_init_bridge(const Netdev *netdev, const char *name, --=20 2.47.1