From nobody Mon Feb 9 15:11:15 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=1592923592; cv=none; d=zohomail.com; s=zohoarc; b=eZr9xuT1zQblYp0PZFM9hJkJoJapAokL4JBA29v3NAtWX+afVALRoQ8aNQi+ZgYMin48MmdGGb7CztPS/6BHkUjA4utHshqAHolvkOtWyBbfssKMyoi55dLmq7+RpsTwt9wBm8QcIkkKwiit8pfacTH5E2rSk32PpcYGN9BTSOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592923592; 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=W57MP3riJ3pnAyiMzRNJCervehGd2s8xozztOBd7d1OSfL7LS87Wr/UTxH4izmKAZOjWZhaaVcrUCj6iskqzg0bJ2DYT3O/57Tht97OVY9M2PJX4dC0W3A2WZvUj50yo+Ps6G3roEs0J43oXkLBAMWtDXfoQ6LVKcNPL6Dfcy+4= 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1592923592356774.2263313646146; Tue, 23 Jun 2020 07:46:32 -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-183-F4QOpMiQPcuHqgaaIzRr7Q-1; Tue, 23 Jun 2020 10:46:27 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 328D98031CB; Tue, 23 Jun 2020 14:46:22 +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 0DA9310013D2; Tue, 23 Jun 2020 14:46:22 +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 CF3231800433; Tue, 23 Jun 2020 14:46:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05NEjqbP015956 for ; Tue, 23 Jun 2020 10:45:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id D74D3B3015; Tue, 23 Jun 2020 14:45:52 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D078AB302C for ; Tue, 23 Jun 2020 14:45:50 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 65A8081DA50 for ; Tue, 23 Jun 2020 14:45:50 +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-106-HuH4xSf2O7GWp9dsIDbpGw-1; Tue, 23 Jun 2020 10:45:44 -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 1jnkB0-000298-Db for libvir-list@redhat.com; Tue, 23 Jun 2020 17:45:30 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592923591; 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=ZHkax3A+JOJ87mYStnUtgKqv4VUd5JniVQSgV2ZdEzj3yxgaHO85TBCPv1wIlJOAP1Z9Px y31FLDnS2eylS2D3kbFhnpKX4NVv9Y/xgMXjtoqeCUOyhbCyU7WhoXLi0KlzuOJY45X6tH l3MG6e+Z1q1HhiSRCvRZyPi5/wE+hMU= X-MC-Unique: F4QOpMiQPcuHqgaaIzRr7Q-1 X-MC-Unique: HuH4xSf2O7GWp9dsIDbpGw-1 From: Dmitry Nesterenko To: libvir-list@redhat.com Subject: [PATCH v2 1/3] virhook: refactoring for support hooks placed in several files Date: Tue, 23 Jun 2020 17:45:33 +0300 Message-Id: <20200623144535.149179-2-dmitry.nesterenko@virtuozzo.com> In-Reply-To: <20200623144535.149179-1-dmitry.nesterenko@virtuozzo.com> References: <20200623144535.149179-1-dmitry.nesterenko@virtuozzo.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 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.84 on 10.5.11.22 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 --- 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