Re: [patch] pg_copy - a command for reliable WAL archiving - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: [patch] pg_copy - a command for reliable WAL archiving
Date
Msg-id 20140820132736.GA7648@eldon.alvh.no-ip.org
Whole thread Raw
In response to Re: [patch] pg_copy - a command for reliable WAL archiving  (Greg Stark <stark@mit.edu>)
Responses Re: [patch] pg_copy - a command for reliable WAL archiving
List pgsql-hackers
Greg Stark wrote:

>                   char path[PATH_MAX];
>                   fd = open("/path/to/dir", O_TMPFILE | O_RDWR,
>                                           S_IRUSR | S_IWUSR);
> 
>                   /* File I/O on 'fd'... */
> 
>                   snprintf(path, PATH_MAX,  "/proc/self/fd/%d", fd);
>                   linkat(AT_FDCWD, path, AT_FDCWD, "/path/for/file",
>                                           AT_SYMLINK_FOLLOW);

Hmm, the real trick here is linkat(... "/proc/self/foobar"), not the
O_TMPFILE: you can have an open file descriptor to an "invisible" file
simply by creating a normal file and unlinking it.  I looked at linkat()
yesterday but the idea of using /proc/self didn't occur to me.  Nasty
trick :-(  It seems linkat() is quite a bit more portable than
O_TMPFILE, fortunately ...

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services



pgsql-hackers by date:

Previous
From: "Tomas Vondra"
Date:
Subject: Re: tweaking NTUP_PER_BUCKET
Next
From: Andres Freund
Date:
Subject: Re: [patch] pg_copy - a command for reliable WAL archiving