On Mon, Apr 06, 2026 at 18:16:54 -0400, Cole Robinson via Devel wrote:
> Make it more data driven. This reduces code and makes it easier
> to see dir mode requests at a glance.
> 
> Semantics of virDirCreate are subtly different, so keep dbusStateDir
> separate for now

[1]

> 
> Besides some operation reordering this should behave the same as
> before
> 
> Signed-off-by: Cole Robinson <[email protected]>
> ---
>  src/qemu/qemu_driver.c | 224 ++++++++++-------------------------------
>  1 file changed, 51 insertions(+), 173 deletions(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index b9f5e976b2..0cf88b8be9 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -522,192 +522,70 @@ static int
>  qemuStateInitializeDirs(bool privileged,
>                          virQEMUDriverConfig *cfg)
>  {
> -    int ret = -1;
> +    size_t i;
> +    g_autofree char *channeldir = g_path_get_dirname(cfg->channelTargetDir);

Since you're keeping dbusStateDir separate, keep this one too.
Especially since it's being removed later on.

[...]


> +    struct dirperms {
> +        const char *dir;
> +        int mode;
> +        uid_t user;
> +        gid_t group;
> +    };
> +    struct dirperms dirs[] = {
> +        /* example: /var/cache/libvirt/qemu */
> +        { cfg->cacheDir, 0777, -1, -1 }, @
> +
> +        /* example: /run/libvirt/qemu */
> +        { cfg->stateDir, 0777, -1, -1 }, @
> +        { cfg->slirpStateDir, 0777, cfg->user, cfg->group }, @#
> +        { cfg->passtStateDir, 0777, cfg->user, cfg->group }, @#
> +        { cfg->rdpStateDir, 0777, cfg->user, cfg->group }, @#
> +        { channeldir, 0777, cfg->user, cfg->group },
> +        { cfg->channelTargetDir, 0777, cfg->user, cfg->group }, @
> +
> +        /* example: /var/lib/libvirt/qemu */
> +        { cfg->libDir, 0777, cfg->user, cfg->group }, @
> +        { cfg->saveDir, 0777, cfg->user, cfg->group }, @
> +        { cfg->snapshotDir, 0777, cfg->user, cfg->group }, @
> +        { cfg->checkpointDir, 0777, cfg->user, cfg->group }, @
> +        { cfg->autoDumpPath, 0777, cfg->user, cfg->group }, @
> +        { cfg->nvramDir, 0777, cfg->user, cfg->group }, @#
> +        { cfg->varstoreDir, 0777, cfg->user, cfg->group }, @#
> +        { cfg->memoryBackingDir, 0777, cfg->user, cfg->group }, @#
> +    };
> +
> +    for (i = 0; i < G_N_ELEMENTS(dirs); i++) {
> +        if (g_mkdir_with_parents(dirs[i].dir, dirs[i].mode) < 0) {
> +            virReportSystemError(errno, _("Failed to create directory %1$s"),
> +                                 dirs[i].dir);
> +            return -1;
> +        }
> +
> +        if (privileged &&
> +            dirs[i].user != -1) {

Fails syntax-check:

make -C /home/pipo/build/libvirt/gcc/build-aux sc_prohibit_risky_id_promotion
―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
 ✀  
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
stdout:
make: Entering directory '/home/pipo/build/libvirt/gcc/build-aux'
/home/pipo/libvirt/src/qemu/qemu_driver.c:565:            dirs[i].user != -1) {
make: Leaving directory '/home/pipo/build/libvirt/gcc/build-aux'
stderr:
cast -1 to ([ug]id_t) before comparing against id
make: *** [/home/pipo/libvirt/build-aux/syntax-check.mk:183: 
sc_prohibit_risky_id_promotion] Error 1

You need to typecast -1 to uid_t.

With syntax-check fixed and the channelDir thing separate:

Reviewed-by: Peter Krempa <[email protected]>

Reply via email to