runit: tryshsgr.c: why not test whether gid_t is short by using "sizeof(short) == sizeof(gid_t)"

From: Zhixu Liu <zhixu.liu_at_gmail.com>
Date: Wed, 4 Sep 2024 19:35:23 +0800

Hi,

I'm trying to keep runit remaining available in gentoo's official portage tree,
see https://bugs.gentoo.org/938282 . I setup a github repo at
https://github.com/clan/runit/ for this purpose, following is what I'm doing
now:
1. fix all the compilation error(s)
2. eliminate the compilation warning(s) as much as possible

Now I 'm in stage 2, when fixing the warning of
-Wincompatible-pointer-types, see
https://github.com/clan/runit/blob/master/admin/runit-2.1.2/src/tryshsgr.c

As G. Pape has commented at
https://github.com/clan/runit/commit/5a7b8099ae638ce72abae2c4d8cac7ce33477522

> "tryshsgr" is specifically there to check whether the size of gid_t is short,
> it doesn't matter if it fails at compile time or run time. But with this
> change, it always succeeds, and so always size short is
> assumed, even though most systems should have unsigned int I guess.

At first, what Pape said is correct, I didn't fully understand the semantic
meaning of this check before fixing. I should use debian's patch
(0029-fix-ftbfs-with-gcc14.patch) which casts x by (gid_t *) instead of
changing from short x[4] to gid_t x[4] in my current patch (which is wrong).

But I'm just wondering why we don't use "sizeof(short) == sizeof(gid_t)" to do
the test which is more intuitive?

Part of the reason is that I found the test of the result depends on the
running user's supplement group config after I changed short to gid_t, which
is very confusing. If I run as root with many supplement groups, the test
fails, if running as another user w/o supplement groups, the test succeeds.
Of course, after the change from short to gid_t, the test logic or assumption
is wrong from the beginning.

Thanks.
Received on Wed Sep 04 2024 - 13:35:23 CEST

This archive was generated by hypermail 2.4.0 : Wed Sep 04 2024 - 13:36:30 CEST