From nobody Sun Feb 8 18:31:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1604407446; cv=none; d=zohomail.com; s=zohoarc; b=Ac6QkmwdfqR24rj5gmkIA9d4fbCwYoCJlQ6g9W57NcU+NHFJSid8QBVbBiUkW9swe06LsN7Ovl5CxThs2ey6HVFgltbL0Bf5suN8qMcMeUr/7slB0pnrVqMycwOJRYz+J6PWkL5gAe/IGtJGrxvkqUW5/9qb9XzviiMamr3TqFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604407446; 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=6h9w2F4VI327F4HgOLijj+Apr0gT5wBbj4rqromKiEk=; b=R4r7Xmv8+be+S2WDtAO65wbceio48duuBydr8K2I5asKimRCptGvnmn8tE3u4PzOC6jl+LUj3guYg3352alNzhs+BoWsx2fOqRhNF058kkpuBy4rggLSjBiQ4u1HHk/TsvKE5GJ20IOJBqxzBfERh4AKSirUhTdcjZllngwQF/o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1604407446818807.1171145784092; Tue, 3 Nov 2020 04:44:06 -0800 (PST) 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-547-MJaIG3cENFeEqu2dgajECw-1; Tue, 03 Nov 2020 07:42:20 -0500 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 3C6C4805F12; Tue, 3 Nov 2020 12:42:13 +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 1AAF97366D; Tue, 3 Nov 2020 12:42:13 +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 DB7638C7DC; Tue, 3 Nov 2020 12:42:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0A3Cg5HK016302 for ; Tue, 3 Nov 2020 07:42:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8FF9073667; Tue, 3 Nov 2020 12:42:05 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.192.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09B0073664 for ; Tue, 3 Nov 2020 12:42:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604407445; 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=6h9w2F4VI327F4HgOLijj+Apr0gT5wBbj4rqromKiEk=; b=U/pAjLSvroLDNcrj8+4KlcuEb5NUbNtzNfLRWsmTJlcA3C9hIjxCn1HNlzZ1G9fWUtLDLk Sl5LGMWouMkSkNpOvvaXVkVQfBaUh97oyVnaSduBUHAOtJS/WwziAblhG9yYbGUaQ6fd35 IfzKqtLPFBHJ/wkb4qV361o5WBdmGVY= X-MC-Unique: MJaIG3cENFeEqu2dgajECw-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 22/25] vircgroup: refactor virCgroupEnableMissingControllers Date: Tue, 3 Nov 2020 13:41:34 +0100 Message-Id: <224d1d6584227af3ea2719d65fc17e6bcc01ecd6.1604407065.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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 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) Content-Type: text/plain; charset="utf-8" Use virStringSplit() to get the list of directories needed to be created. This improves readability of the code and stops passing absolute path to virCgroupNewFromParent(). Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 1e18b84b54..f4c1623567 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1131,21 +1131,18 @@ virCgroupEnableMissingControllers(char *path, virCgroupPtr *group) { g_autoptr(virCgroup) parent =3D NULL; - char *offset =3D path; + VIR_AUTOSTRINGLIST tokens =3D virStringSplit(path, "/", 0); + size_t i; =20 - if (virCgroupNew("/", - controllers, - &parent) < 0) + if (virCgroupNew("/", controllers, &parent) < 0) return -1; =20 - for (;;) { + /* Skip the first token as it is empty string. */ + for (i =3D 1; tokens[i]; i++) { g_autoptr(virCgroup) tmp =3D NULL; - char *t =3D strchr(offset + 1, '/'); - if (t) - *t =3D '\0'; =20 if (virCgroupNewFromParent(parent, - path, + tokens[i], controllers, &tmp) < 0) return -1; @@ -1153,17 +1150,10 @@ virCgroupEnableMissingControllers(char *path, if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_SYSTEMD) < 0) return -1; =20 - if (t) { - *t =3D '/'; - offset =3D t; - virCgroupFree(parent); - parent =3D g_steal_pointer(&tmp); - } else { - *group =3D g_steal_pointer(&tmp); - break; - } + parent =3D g_steal_pointer(&tmp); } =20 + *group =3D g_steal_pointer(&parent); return 0; } =20 --=20 2.26.2