Vote Up
5
Votes
Vote Down

“In the world of POSIX, everything is a file. Well, sort of. There’s sockets and pipes, which behave rather like files except that you can’t seek on them and they have some extra metadata. And there’s devices, where sometimes you can only read and write appropriately-sized blocks, not individual bytes. And then there’s terminals, which are all sorts of weird. But in all these cases, you’ve got a file descriptor, and when you’re finished you release the resource by calling the close(2) system call.”

“There’s just one small problem: The way POSIX has defined close(2) is completely and utterly broken.”

#1 Posted by administrator on Dec 24, 2011 2:32 AM

not actually FUD, but still worth it for posterity.

#2 Posted by DrLoser on Dec 24, 2011 6:02 AM

Well, I like it, but it’s not strictly meaningful. As one commenter says, who cares what Posix says on the matter? All sane implementations (and apparently Linux, too) treat this absurdity with the contempt it deserves: ie, the fd isn’t actually “undefined” at all. The file is either closed or it isn’t.

I’ve certainly never seen an attempt in the wild to wrap EINTR in complex cotton wool.

A more interesting question is, why doesn’t Posix treat system calls atomically? At least wrt to signals, anyway. Signals are a horribly low-level holdover from the 1970s, and giving them a hard pre-emption over everything else the kernel does is just stupid and causes infinitely more problems than it solves.

Would it really hurt to queue the handler until the call to close() returns?

It strikes me that the founders of Unix didn’t actually make any design decisions at all. They simply rushed the initial implementation through in about three weeks and along the way picked just about any strategy or hack that looked like it might work at the time.

#3 Posted by administrator on Dec 24, 2011 6:50 AM

In that case, the development in Unix has a lot in common with the development of PHP. Ad hoc to the core.

#4 Posted by DrLoser on Dec 24, 2011 7:04 AM

Funny thing, that. I was reading a blog piece about the development of PHP (by a PHP core team member) and why PHP6 was such an utter failure, and I’m pretty sure that it made explicit reference to having the same design philosophy as Unix.

Sadly, I’ve lost the link; I think it was a couple of steps away from a Noyes piece, or something equally unlikely. It was hysterically funny, though. It was a template for your basic Loon article:

“Yes, we admit. We made mistakes along the way. Consequently the thing is an utter mess right now. But we know what we’re doing! The future is rosy!”

I had occasion to use PHP, just the once. It was an extraordinary experience, and I don’t mean that in a good way. I will confidently predict that my “solution” of providing a MySQL API for PHP4 (no objects) and PHP5 (not so much “objects” as “things”) by using the inbuilt slot hack was better than 99% of PHP out there, and it was still dreadful.

If you really have to use it, IRecommend™ the remote debugging facilities of Active State Komodo. Oh, and turn the option on that spews debugging information all over the browser page. It’s, er, an eye-opener.

Now if you will excuse me I have a TM to write.

You must be signed in to leave comments.