Commit b91bc69e authored by jan.koester's avatar jan.koester
Browse files

test: e2e_uid_r_src skips without the privilege to chown to UUIDs

It failed on the build host since that runs a uid_r kernel (getuid() isn't
root there), and in a build chroot (root of a user namespace, where
fchown() to a UUID owner is EPERM/EINVAL), which broke systempp's rpm
%check. Both now SKIP like a kernel without the *_r calls; any other
fchown() failure still fails.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 0382bda1
Loading
Loading
Loading
Loading
+14 −2
Changes for src/test/e2e/uid_r_src_test.c: 14 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -29,7 +29,11 @@ int main(void) {
        return 0;
    }
    CHECK(sizeof(uid_t) == 20 && sizeof(gid_t) == 20, "uid_t is the 20 byte union");
    CHECK(uid_r_eq(&me, &s0), "getuid() of root is legacy 0");
    /* the rest needs real root: chown to arbitrary owners */
    if (!uid_r_eq(&me, &s0)) {
        printf("SKIP: not running as root\n");
        return 0;
    }

    uid_r_from_str("6f1c2a3b-4d5e-4f60-8a7b-0c1d2e3f4a5b", &u);
    uid_r_from_str("{13121110-1514-1716-1819-1a1b1c1d1e0f}", &g);
@@ -38,7 +42,15 @@ int main(void) {
    snprintf(path, sizeof path, "/tmp/uid_r_src_%d", getpid());
    int fd = open(path, O_CREAT | O_WRONLY, 0644);
    CHECK(fd >= 0, "create test file");
    CHECK(fchown(fd, u, g) == 0, "fchown() to a UUID owner, GUID group");
    int rc = fchown(fd, u, g);
    if (rc != 0 && (errno == EPERM || errno == EINVAL)) {
        /* root of a user namespace (build chroots): no UUID owners there */
        close(fd);
        unlink(path);
        printf("SKIP: can't chown to a UUID owner here (user namespace?)\n");
        return 0;
    }
    CHECK(rc == 0, "fchown() to a UUID owner, GUID group");
    close(fd);
    CHECK(stat(path, &st) == 0 && uid_r_eq(&st.st_uid, &u) && uid_r_eq(&st.st_gid, &g),
          "stat() reports them");