[systemd-devel] [RFC PATCH 1/2] Replace mkostemp+unlink with open(O_TMPFILE)
Kay Sievers
kay at vrfy.org
Mon Jan 27 08:57:56 PST 2014
On Mon, Jan 27, 2014 at 5:37 PM, Zbigniew Jędrzejewski-Szmek
<zbyszek at in.waw.pl> wrote:
> 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.
Can we expect open(O_TMPFILE) to fail on kernels which do not support it?
I guess they will just silently ignore it? Then we never unlink?
Kay
More information about the systemd-devel
mailing list