[systemd-devel] [RFC PATCH 1/2] Replace mkostemp+unlink with open(O_TMPFILE)

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Mon Jan 27 08:37:37 PST 2014


On Mon, Jan 27, 2014 at 11:52:48AM -0200, Lucas De Marchi wrote:
> On Sun, Jan 26, 2014 at 3:21 AM, Zbigniew Jędrzejewski-Szmek
> > +int open_tmpfile(const char *path, int flags) {
> > +        int fd;
> > +        char *p;
> > +
> > +#ifdef O_TMPFILE
> > +        fd = open(path, flags | O_TMPFILE, S_IRUSR | S_IWUSR);
> > +        if (fd >= 0)
> > +                return fd;
> > +#endif
> > +        p = strappenda(path, "/systemd-tmp-XXXXXX");
> > +
> > +        RUN_WITH_UMASK(0077) {
> > +                fd = mkostemp(p, O_RDWR|O_CLOEXEC);
> > +        }
> > +
> > +        if (fd < 0)
> > +                return -errno;
> > +
> > +        unlink(path);
> 
> This unlink() doesn't make much sense with O_TMPFILE.

unlink is only reached if open(O_TMPFILE) failed and fd comes
from mkostemp.

Zbyszek


More information about the systemd-devel mailing list