From nobody Mon Feb 9 03:00:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1548423134752344.9905753322787; Fri, 25 Jan 2019 05:32:14 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id F2EF3A7EF; Fri, 25 Jan 2019 13:32:12 +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 BDABD61533; Fri, 25 Jan 2019 13:32:12 +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 64D694ED45; Fri, 25 Jan 2019 13:32:12 +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 x0PDVvR7002052 for ; Fri, 25 Jan 2019 08:31:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id D4C7D1048125; Fri, 25 Jan 2019 13:31:57 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5AA931048117 for ; Fri, 25 Jan 2019 13:31:57 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 25 Jan 2019 14:31:48 +0100 Message-Id: <0269ab11be5e99c4b5a1c54774c1070c92b5ac25.1548422575.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 Subject: [libvirt] [PATCH 4/5] virinitctl: Expose fifo paths and allow caller to chose one 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 25 Jan 2019 13:32:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" So far the virInitctlSetRunLevel() is fully automatic. It finds the correct fifo to use to talk to the init and it will set the desired runlevel. Well, callers (so far there is just one) will need to inspect the fifo a bit just before the runlevel is set. Therefore, expose the internal list of fifos and also allow caller to explicitly use one. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 2 +- src/util/virinitctl.c | 66 +++++++++++++++++++++++++--------------- src/util/virinitctl.h | 6 +++- 4 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 89b8ca3b4f..af490be12c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2049,6 +2049,7 @@ virIdentitySetX509DName; =20 =20 # util/virinitctl.h +virInitctlFifos; virInitctlSetRunLevel; =20 =20 diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 6c0f9b57db..943d199616 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3277,7 +3277,7 @@ lxcDomainInitctlCallback(pid_t pid ATTRIBUTE_UNUSED, void *opaque) { int *command =3D opaque; - return virInitctlSetRunLevel(*command); + return virInitctlSetRunLevel(NULL, *command); } =20 =20 diff --git a/src/util/virinitctl.c b/src/util/virinitctl.c index 0b06743151..8f8bbae4bc 100644 --- a/src/util/virinitctl.c +++ b/src/util/virinitctl.c @@ -101,7 +101,20 @@ struct virInitctlRequest { verify(sizeof(struct virInitctlRequest) =3D=3D 384); # endif =20 -/* + +/* List of fifos that inits are known to listen on */ +const char *virInitctlFifos[] =3D { + "/run/initctl", + "/dev/initctl", + "/etc/.initctl", +}; + + +/** + * virInitctlSetRunLevel: + * @fifo: the path to fifo that init listens on (can be NULL for autodetec= tion) + * @level: the desired runlevel + * * Send a message to init to change the runlevel. This function is * asynchronous-signal-safe (thus safe to use after fork of a * multithreaded parent) - which is good, because it should only be @@ -110,18 +123,14 @@ struct virInitctlRequest { * Returns 1 on success, 0 if initctl does not exist, -1 on error */ int -virInitctlSetRunLevel(virInitctlRunLevel level) +virInitctlSetRunLevel(const char *fifo, + virInitctlRunLevel level) { struct virInitctlRequest req; int fd =3D -1; int ret =3D -1; - const char *initctl_fifo =3D NULL; + const int open_flags =3D O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY; size_t i =3D 0; - const char *initctl_fifos[] =3D { - "/run/initctl", - "/dev/initctl", - "/etc/.initctl", - }; =20 memset(&req, 0, sizeof(req)); =20 @@ -131,31 +140,39 @@ virInitctlSetRunLevel(virInitctlRunLevel level) /* Yes it is an 'int' field, but wants a numeric character. Go figure = */ req.runlevel =3D '0' + level; =20 - for (i =3D 0; i < ARRAY_CARDINALITY(initctl_fifos); i++) { - initctl_fifo =3D initctl_fifos[i]; - - if ((fd =3D open(initctl_fifo, - O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY)) >=3D 0) - break; - - if (errno !=3D ENOENT) { + if (fifo) { + if ((fd =3D open(fifo, open_flags)) < 0) { virReportSystemError(errno, _("Cannot open init control %s"), - initctl_fifo); + fifo); goto cleanup; } - } + } else { + for (i =3D 0; i < ARRAY_CARDINALITY(virInitctlFifos); i++) { + fifo =3D virInitctlFifos[i]; =20 - /* Ensure we found a valid initctl fifo */ - if (fd < 0) { - ret =3D 0; - goto cleanup; + if ((fd =3D open(fifo, open_flags)) >=3D 0) + break; + + if (errno !=3D ENOENT) { + virReportSystemError(errno, + _("Cannot open init control %s"), + fifo); + goto cleanup; + } + } + + /* Ensure we found a valid initctl fifo */ + if (fd < 0) { + ret =3D 0; + goto cleanup; + } } =20 if (safewrite(fd, &req, sizeof(req)) !=3D sizeof(req)) { virReportSystemError(errno, _("Failed to send request to init control %s"= ), - initctl_fifo); + fifo); goto cleanup; } =20 @@ -166,7 +183,8 @@ virInitctlSetRunLevel(virInitctlRunLevel level) return ret; } #else -int virInitctlSetRunLevel(virInitctlRunLevel level ATTRIBUTE_UNUSED) +int virInitctlSetRunLevel(const char *fifo ATTRIBUTE_UNUSED, + virInitctlRunLevel level ATTRIBUTE_UNUSED) { virReportUnsupportedError(); return -1; diff --git a/src/util/virinitctl.h b/src/util/virinitctl.h index 7ac627883a..f12741c7c1 100644 --- a/src/util/virinitctl.h +++ b/src/util/virinitctl.h @@ -33,6 +33,10 @@ typedef enum { VIR_INITCTL_RUNLEVEL_LAST } virInitctlRunLevel; =20 -int virInitctlSetRunLevel(virInitctlRunLevel level); + +extern const char *virInitctlFifos[3]; + +int virInitctlSetRunLevel(const char *fifo, + virInitctlRunLevel level); =20 #endif /* LIBVIRT_VIRINITCTL_H */ --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list