News for hackers. Stuff that matters.
Re:C++ still isn't cutting it by sudeepj on Sunday October 18, 2020 @12:29PM (#24818991)
I am not sure what TTCTTOU is, but what you are saying needs transaction like semantics in filesystems. So its more of a property of an FS instead of a language.

All the common FS (in linux .. ext* xfs) do not have that these.

Re:C++ still isn't cutting it by merrywhether on Sunday October 18, 2020 @12:54PM (#24819204)
“time to check to time to use”

As you intuited, a problem that arises in environments that lack transactions/locks/etc

Re:C++ still isn't cutting it by Iwan-Zotow on Sunday October 18, 2020 @05:16PM (#24821197)
> All the common FS (in linux .. ext* xfs) do not have that these

You know that files are nameless on Unix, right?

Re:C++ still isn't cutting it by sudeepj on Sunday October 18, 2020 @10:14PM (#24822812)
> do not have that these

I was referring to the transaction semantics

Re:C++ still isn't cutting it by Iwan-Zotow on Wednesday October 21, 2020 @05:25PM (#24852363)
> let f = File::open("username.txt");

> /what if the file is deleted here?/

you don't need transaction semantics here.

On Unix file is basically inode with counter. If it doesn't have record (aka name) in directory but non-zero counter, it would exist.

So on open(2) counter is bumped up and is equal to 2 (or higher if there are hardlinks), one for the directory record and one for program running it.

If you remove record from directory (aka `rm filename`), counter would decrease by 1, but it is still non-zero, program still has it open, could read its content, etc. Only after close(2) counter would decrease to 0 and file would be gone.

Just tested it on Ubuntu 20.4 with simple C program