[systemd-commits] 4 commits - .gitignore Makefile.am man/sd_journal_print.xml man/systemd.xml src/core src/journal src/shared src/test

Lennart Poettering lennart at poettering.net
Tue Jan 28 03:27:14 PST 2014


On Mon, 27.01.14 20:17, Zbigniew Jędrzejewski-Szmek (zbyszek at kemper.freedesktop.org) wrote:

> +        for (int i = 0; i < j; i++) {
> +                size_t written = 0;
> +
> +                while (written < w[i].iov_len) {
> +                        ssize_t r;
> +
> +                        r = write(fd, (char*) w[i].iov_base + written, w[i].iov_len - written);
> +                        if (r < 0 && errno != -EINTR)
> +                                return -errno;
> +
> +                        written += r;
> +                }
> +        }
> +
> +        return 0;
> +}

I am really not convinced we need this. This really appears like
something where the man page documentation is just missing a sentence
about signal safety... Also, we hack against glibc, and this really
looks like something where we can fix things should they ever show
up. But duplicating the code here from glibc sounds like we can only
lose.

Internally in the kernel write() is just a special case of writev(), so
I really fail to see the benefit here...

> +int mkostemp_safe(char *pattern, int flags) {
> +        char *s = pattern + strlen(pattern) - 6;

I don't really like mixing function calls into variable declarations... :-(

> +        uint64_t tries = TMP_MAX;
> +        int randfd, fd, i;
> +
> +        assert(streq(s, "XXXXXX"));
> +
> +        randfd = open("/dev/urandom", O_RDONLY);
> +        if (randfd < 0)
> +                return -ENOSYS;

There's random_bytes() already, which is similar to this... It might
make sense to use that here, maybe with an additional argument that
tells it to never fallback to PRNG.

> +
> +        while (tries--) {
> +                fd = read(randfd, s, 6);
> +                if (fd == 0)
> +                        return -ENOSYS;
> +
> +                for (i = 0; i < 6; i++)
> +                        s[i] = ALPHANUMERICAL[(unsigned) s[i] % strlen(ALPHANUMERICAL)];
> +
> +                fd = open(pattern, flags|O_EXCL|O_CREAT, S_IRUSR|S_IWUSR);
> +                if (fd >= 0)
> +                        return fd;
> +                if (!IN_SET(errno, EEXIST, EINTR))
> +                        return -errno;
> +        }
> +
> +        return -EEXIST;
> +}
> +

BTW, another possible backend for this is actually sd-memfd... Not any
better supported than O_TMPFILE though... Hence probably not really
useful...

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-commits mailing list