If I remember correctly, it would be something like this:
fd = open("/tmp", O_TMPFILE | O_RDWR, 0600);
linkat(fd, "", AT_FDCWD, "/tmp/test", AT_EMPTY_PATH);
This is pretty specific to OS/kernel version and quite possibly the filesystem 
too.  This could be entirely too much of an edge case to be reasonably done.

- Greg


> On Oct 11, 2018, at 9:02 PM, Justin Israel <justinisr...@gmail.com> wrote:
> 
> 
> 
>> On Fri, Oct 12, 2018, 2:31 PM Ian Lance Taylor <i...@golang.org> wrote:
>> On Thu, Oct 11, 2018 at 4:48 PM, Greg Saylor <greg.saylor....@gmail.com> 
>> wrote:
>> >
>> > In other programming languages (this is specific to Linux/Unix systems), in
>> > the past to ensure security in the even of a program crash, we would do
>> > something like:
>> >
>> > 1. Create a temporary file and squirrel away the file handle
>> > 2. Unlink the temporary file by name
>> > 3. Various functions would write stuff to the file
>> > 4. If the programs completes to some successful state, create a hardlink to
>> > the file handle with the final filename
>> >
>> > I'm finding this very difficult to do in Go, as there does not seem to be a
>> > way to do #4.  And this is a very important consideration for this piece of
>> > the system.
>> >
>> > For example, os.Rename takes filenames as the old/new filename.
>> >
>> > I figured looking in that code might reveal something lower level that 
>> > could
>> > be used, which lead me to syscal_linuxl.Rename()
>> >
>> > That lead me to syscall_linux.RenameAt()
>> >
>> > Which led me to zsyscall_linux_amd64.go.
>> >
>> > .. at this point I got pretty lost on how to do any of this.  _AT_FDCWD and
>> > fishing around in what appears to be some pretty low-level internals of
>> > Go...
>> >
>> > Is there some way to achieve this or a way that can ensure these files are
>> > always removed if the program is kill -9'd, terminates from a panic, etc.
>> 
>> Can you show us how you do this in C?
> 
> 
> Probably linkat(2) ? 
> 
> http://man7.org/linux/man-pages/man2/linkat.2.html
> 
>> 
>> I expect that will point toward how to do it in Go.
>> 
>> Ian
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to