From nobody Mon Feb 9 01:51:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644491644; cv=none; d=zohomail.com; s=zohoarc; b=IokqcNYDIg3m3MErazylgkt7L4yu1vOzhepKNebOPA1epyeyJFnFwSYpNzx9Yb1MYswLd2lNgsUy6OEERtO7FmnWUZkFd+vI5gW3TQK+AXZA40n1OE5r+43XOYyTD4W9fIjzpmeAvbN4DsQAgTz5MVuuk56fb9+lMPWQ8AK8VFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644491644; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LKttHx/E6t8Mk31KceJCcmMGr4T+H9o/8mLCfmYuGLc=; b=NoyagNkxXH94EWUuENRXCjfbPhNhlSjWGcXhGzty8qHFk0gTECLdH0QIu7y/GVJknlf6yC0eGC25UlpD4gP7zCR0INke7eDeasg445+EgpCpRSKV+vcQNOOaACaMGYxf9QtyZ7VykqX+V5CjNHccpigKCqPGKLD2AtIPijUK16c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644491644154916.8008659250276; Thu, 10 Feb 2022 03:14:04 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-443-Lo9ENB7PM5Cmp1C7i60S3Q-1; Thu, 10 Feb 2022 06:14:00 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 59DD780D694; Thu, 10 Feb 2022 11:13:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 156897039E; Thu, 10 Feb 2022 11:13:55 +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 D8CD24A7C9; Thu, 10 Feb 2022 11:13:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21ABDmnG018788 for ; Thu, 10 Feb 2022 06:13:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 46EC910589DE; Thu, 10 Feb 2022 11:13:48 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id C548710589DD for ; Thu, 10 Feb 2022 11:13:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644491644; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=LKttHx/E6t8Mk31KceJCcmMGr4T+H9o/8mLCfmYuGLc=; b=GLxD2qNnYY+R6sSssfGuNhrb1J8bp5h+6ys3YGyGxodEqrJIWzsFQhJpJsKD5OV18Js5xe sNgkHq2mJWdTvwCjeVSnnhIvTKpiLMrfH8nO4kCa5LO3mf89Axb7ppFPWVbkv//LHW6BS4 hOeAiF6v1hMZlqbzkN6tSH8Kh8O+NSg= X-MC-Unique: Lo9ENB7PM5Cmp1C7i60S3Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/5] virFileRewrite: Allow callback report errors Date: Thu, 10 Feb 2022 12:13:25 +0100 Message-Id: <22ce632ff98d3f6e9b488798a19623e259327113.1644491535.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644491646284100005 Content-Type: text/plain; charset="utf-8" Sometimes it may be handy for the callback to report error, even though our current callbacks are trivial. Let's report an error only if callback returns a well known value, otherwise assume it reported error message on its own. Signed-off-by: Michal Privoznik --- src/util/virfile.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index f99e7f95e1..dd065a537c 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -499,6 +499,10 @@ int virFileUnlock(int fd G_GNUC_UNUSED, * @uid:@gid (pass -1 for current uid/gid) and written by * @rewrite callback. * + * A negative value returned by @rewrite callback is treated as + * error and if the value is different to -1 then it's the + * callback's responsibility to report error. + * * Returns: 0 on success, * -1 otherwise (with error reported) */ @@ -512,6 +516,7 @@ virFileRewrite(const char *path, g_autofree char *newfile =3D NULL; int fd =3D -1; int ret =3D -1; + int rc; =20 newfile =3D g_strdup_printf("%s.new", path); =20 @@ -524,9 +529,11 @@ virFileRewrite(const char *path, goto cleanup; } =20 - if (rewrite(fd, opaque) < 0) { - virReportSystemError(errno, _("cannot write data to file '%s'"), - newfile); + if ((rc =3D rewrite(fd, opaque)) < 0) { + if (rc =3D=3D -1) { + virReportSystemError(errno, _("cannot write data to file '%s'"= ), + newfile); + } goto cleanup; } =20 --=20 2.34.1