(backport) nspawn: Simplify tmpfs_patch_options() usage, and trickle that up
authorLuke Shumaker <lukeshu@parabola.nu>
Tue, 13 Jun 2017 22:06:09 +0000 (18:06 -0400)
committerAdrian Szyndela <adrian.s@samsung.com>
Thu, 26 Mar 2020 15:28:06 +0000 (16:28 +0100)
commit9f227e76db2b20a27358d6909bbffa4c3643f1f1
tree04702e0e5eea1490120ce474d6c24eee7ca0c881
parenta38e2bbf80ed9d3da6f238ee87d2348b61a6e372
(backport) nspawn: Simplify tmpfs_patch_options() usage, and trickle that up

One of the things that tmpfs_patch_options does is take an (optional) UID,
and insert "uid=${UID},gid=${UID}" into the options string.  So we need a
uid_t argument, and a way of telling if we should use it.  Fortunately,
that is built in to the uid_t type by having UID_INVALID as a possible
value.

So this is really a feature that requires one argument.  Yet, it is somehow
taking 4!  That is absurd.  Simplify it to only take one argument, and have
that trickle all the way up to mount_all()'s usage.

Now, in may of the uses, the argument becomes

    uid_shift == 0 ? UID_INVALID : uid_shift

because it used to treat uid_shift=0 as invalid unless the patch_ids flag
was also set.  This keeps the behavior the same.  Note that in all cases
where it is invoked, if !use_userns (sometimes called !userns), then
uid_shift is 0; we don't have to add any checks for that.

That said, I'm pretty sure that "uid=0" and not setting "uid=" are the
same, but Christian Brauner seemed to not think so when implementing the
cgns support.  https://github.com/systemd/systemd/pull/3589

Change-Id: I1b44d4415c10611b89423145f90b83e0d72eb4bc
src/nspawn/nspawn-mount.c
src/nspawn/nspawn-mount.h
src/nspawn/nspawn.c