Skip to contentSkip to conversation

creating anonymous files

proposal john slee 1 participant 1 message May 2, 2009

lore
Share & tools
lore

john slee

author
#0 lore raw

Hi,

At present developers seem to go through all kinds of ridiculous antics to try to open a temporary file with some degree of safety. Most of these seem to revolve around choosing a name, and in many cases it gets unlinked immediately after open() anyway.

Temporary file creation/handling would be far less unpleasant if it went something like this:

/* need to establish which fs the new inode goes on */ dirfd = open("/etc", O_RDONLY);

fd = openfdat(dirfd, O_CREAT, S_IWUSR|S_IRUSR); /* file has no links, no need to unlink. now use fd */

/* if we want to keep the file, add a link */

if (all_ok) {
    linkfdat(dirfd, fd, "nsswitch.conf");
} else {

/* no cleanup required, inode has no links and */ /* disappears at process exit */
}

I had a quick look through the Free/OpenBSD and Solaris 10 manpages in case they had implemented something similar, but it seems that they haven't.

Sorry about lack of attached patch. I did have a good look through fs/namei.c and fs/open.c but I am more a sysadmin than a kernel hacker

Comments/constructive abuse appreciated...

John

Signature · 1 line
P-plate adventurer -- http://indigoid.org/