From nobody Tue Feb 10 01:30:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1592778361; cv=none; d=zohomail.com; s=zohoarc; b=TDbsao7yQgZsD1v0yex9/LS4pq5tSgrsaEXZvZzVi1AiX77eGftQdQjxsNpUyXeKhKEVDALSsdzYYnQJvbzbl+A60/eouXICN0pmJ+uv13cqQfgM+Z9oVpdf0lqWIpFRJ1ITpvzBFfpWc+CfgCtyEyKG8iuQ3CuHkpuT0mpyvs0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592778361; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=P3Unw1EXcbsPX3rQNzDhlRvuyZNKGoxGjjtQy1qvkI0=; b=DP7CNAMbHzQIlUFpBhTxy4LL6Qz6W5YC871tOG57pvpJF5pq1ZuO34SQHXQvgOCEtucPVy39Dzl5I+YQo7hwb3CX6SAyEIaCbv035hhrAm/hUgdXzEvPKJJ4u63bms4xXKAf7Ynoou9TJzkFP1c4EQ+8BrHgcGdD4WwU6sIvdoQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1592778361386894.520707981267; Sun, 21 Jun 2020 15:26:01 -0700 (PDT) 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-301-mBg3Yt3-O3SrFmYKU2so-g-1; Sun, 21 Jun 2020 18:25:58 -0400 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 5A7CA8018AB; Sun, 21 Jun 2020 22:25:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 39DDD7C1F5; Sun, 21 Jun 2020 22:25:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0542F1809547; Sun, 21 Jun 2020 22:25:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05LMPRWN001559 for ; Sun, 21 Jun 2020 18:25:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 279D72157F25; Sun, 21 Jun 2020 22:25:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 22D2F2157F23 for ; Sun, 21 Jun 2020 22:25:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 100B3185A78B for ; Sun, 21 Jun 2020 22:25:24 +0000 (UTC) Received: from relay3.sw.ru (relay.sw.ru [185.231.240.75]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-144-cUlY40qxOjurzu7FyOA_3w-1; Sun, 21 Jun 2020 18:25:21 -0400 Received: from [172.16.25.65] (helo=dhcp-172-16-25-65.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jn7Ka-00045s-C6 for libvir-list@redhat.com; Mon, 22 Jun 2020 00:16:48 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592778360; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:content-type:content-type: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=P3Unw1EXcbsPX3rQNzDhlRvuyZNKGoxGjjtQy1qvkI0=; b=U47j4s6bPGpVeDDUQ+puPf50B0IcKZaOXgsjmOPUqF79grhnUfv/L/WrMf70lKFGq0IoFz bzmfTbx4k9YIIQUqiCG3U/Qu8wyGfyvDzElcCMXmBT7BuWGYFit1nXqF25qSRELHM2RdOe hm6Ck60rxfcCQrJ2+habuCcj7ToVA+A= X-MC-Unique: mBg3Yt3-O3SrFmYKU2so-g-1 X-MC-Unique: cUlY40qxOjurzu7FyOA_3w-1 From: Dmitry Nesterenko To: libvir-list@redhat.com Subject: [PATCH 1/2] virthook: refactoring for support hooks placed in several files Date: Mon, 22 Jun 2020 00:16:38 +0300 Message-Id: <20200621211639.385175-2-dmitry.nesterenko@virtuozzo.com> In-Reply-To: <20200621211639.385175-1-dmitry.nesterenko@virtuozzo.com> References: <20200621211639.385175-1-dmitry.nesterenko@virtuozzo.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Dmitry Nesterenko Reviewed-by: Michal Privoznik --- src/util/virhook.c | 74 +++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/src/util/virhook.c b/src/util/virhook.c index e499841f66..64ee9a2307 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -221,6 +221,57 @@ virHookPresent(int driver) return 1; } =20 +/** + * virRunScript: + * @path: the script path + * @id: an id for the object '-' if non available for example on daemon ho= oks + * @op: the operation on the id + * @subop: a sub_operation, currently unused + * @extra: optional string information + * @input: extra input given to the script on stdin + * @output: optional address of variable to store malloced result buffer + * + * Implement a execution of script. This is a synchronous call, we wait for + * execution completion. If @output is non-NULL, *output is guaranteed to = be + * allocated after successful virRunScript, and is best-effort allocated a= fter + * failed virRunScript; the caller is responsible for freeing *output. + * + * Returns: 0 if the execution succeeded, -1 if script returned an error + */ +static int +virRunScript(const char *path, + const char *id, + const char *op, + const char *subop, + const char *extra, + const char *input, + char **output) +{ + int ret; + g_autoptr(virCommand) cmd =3D NULL; + + VIR_DEBUG("Calling hook %s id=3D%s op=3D%s subop=3D%s extra=3D%s", + path, id, op, subop, extra); + + cmd =3D virCommandNewArgList(path, id, op, subop, extra, NULL); + + virCommandAddEnvPassCommon(cmd); + + if (input) + virCommandSetInputBuffer(cmd, input); + if (output) + virCommandSetOutputBuffer(cmd, output); + + ret =3D virCommandRun(cmd, NULL); + if (ret < 0) { + /* Convert INTERNAL_ERROR into known error. */ + virReportError(VIR_ERR_HOOK_SCRIPT_FAILED, "%s", + virGetLastErrorMessage()); + } + + return ret; +} + /** * virHookCall: * @driver: the driver number (from virHookDriver enum) @@ -249,7 +300,6 @@ virHookCall(int driver, const char *input, char **output) { - int ret; g_autofree char *path =3D NULL; g_autoptr(virCommand) cmd =3D NULL; const char *drvstr; @@ -318,24 +368,6 @@ virHookCall(int driver, return -1; } =20 - VIR_DEBUG("Calling hook opstr=3D%s subopstr=3D%s extra=3D%s", - opstr, subopstr, extra); - - cmd =3D virCommandNewArgList(path, id, opstr, subopstr, extra, NULL); - - virCommandAddEnvPassCommon(cmd); - - if (input) - virCommandSetInputBuffer(cmd, input); - if (output) - virCommandSetOutputBuffer(cmd, output); - - ret =3D virCommandRun(cmd, NULL); - if (ret < 0) { - /* Convert INTERNAL_ERROR into known error. */ - virReportError(VIR_ERR_HOOK_SCRIPT_FAILED, "%s", - virGetLastErrorMessage()); - } - - return ret; + return virRunScript(path, id, opstr, subopstr, extra, + input, output); } --=20 2.18.4