[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 11:01:48 PST 2014
On Mon, Jan 27, 2014 at 07:53:51PM +0100, Kay Sievers wrote:
> On Mon, Jan 27, 2014 at 7:50 PM, Zbigniew Jędrzejewski-Szmek
> <zbyszek at in.waw.pl> wrote:
> > On Mon, Jan 27, 2014 at 07:15:23PM +0100, Kay Sievers wrote:
> >> On Mon, Jan 27, 2014 at 6:27 PM, Zbigniew Jędrzejewski-Szmek
> >> <zbyszek at in.waw.pl> wrote:
> >> > On Mon, Jan 27, 2014 at 05:57:56PM +0100, Kay Sievers wrote:
> >>
> >> >> 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?
> >>
> >> > No, it is supposed to fail properly if it doesn't work. The flags were
> >> > changed to be incompatible with old kernels. We should probably have a
> >> > unit test for that. I have a small utility I was using for tests, I'll
> >> > dig it up.
> >>
> >> Oh, any idea how this works? I couldn't see any kernel code that
> >> checks for currently unused flags and fails.
> >
> > open("/tmp", O_TMPFILE|O_RDWR, S_IRUSR | S_IWUSR)
> >
> > returns -1, errno=EISDIR on Linux 3.9.
>
> Yeah, but what happens for a "/tmp/does-not-exist" request? :)
It returns -1/ENOENT (all versions).
For "/tmp/exists" -1/ENOTDIR (all versions).
See for yourself :) :
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char** argv) {
int fd = open(argv[1], O_TMPFILE|O_RDWR, S_IRUSR | S_IWUSR);
printf("fd=%d %m\n", fd);
sleep(1000);
return 0;
}
More information about the systemd-devel
mailing list