Check out my first novel, midnight's simulacra!

Questions

From dankwiki
Revision as of 07:17, 7 August 2009 by Dank (talk | contribs)

Some questions I've pondered, and my answers, which may or may not be correct.

UNIX

  • Q: Why are PF_UNIX sockets the only means of exchanging file descriptors (why not regular pipes? why not PF_INET or PF_INET6 sockets?)
  • A: The socket infrastructure provided sufficient mechanism -- recvmsg(2)/sendmsg(2), struct msghdr etc. Regular pipes don't have out-of-band signaling capabilities, as used by the SCM_RIGHTS cmsg_type. File descriptors index a kernelspace array, and thus any non-local socket family would introduce the possibility of a copy of those structures (if that is even meaningful and possible in a given context). Furthermore, they're credentials, in that access checks have already been performed; a socket family involving peers not trusted by the local kernel could subvert the access control.

C

  • Q: Why aren't "target"-style #includes a good idea with any sane compiler?
  • A: So long as you can append to the default include search path (ie, the -I option to gcc), the <target>-style include can search in your project directory. Building from the source toplevel, a simple -I. added to CFLAGS allows #include <toplevel/relative/filename>. Moved headers will trigger a preprocessing failure. If "target"-style #includes are used, the directory of the source being compiled is typically searched prior to other include paths. This means moving source files or introducing new headers can change the files being included, which is almost always undesirable.