commit: 3666ba0ad5d17714100bc1503648b8d4d2652ee2
parent bd1fa9a4ce52785a646e61e91373a3d931a509c1
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 2 Mar 2023 17:21:42 +0100
notes/unix-defects: errno, CLibraryAPIRequiresC
Diffstat:
1 file changed, 32 insertions(+), 19 deletions(-)
diff --git a/notes/unix-defects.xhtml b/notes/unix-defects.xhtml
@@ -9,34 +9,47 @@
<main>
<h1>Unix defects</h1>
<p>This tries to list all the defects that are present in Unix, an OS from the early 70's. I consider "Unix" what current Unix clones (BSDs, illumos, Linux, …) have implemented.</p>
+ <p>None of this should be present in brand new systems except within a cleanly-separated compatibility layer (like Plan9 ape).</p>
- <section>
- <h2 id="internet">Internet</h2>
- <p>Where Unix isn't internet-ready</p>
+ <h3 id="cstr"><code>NULL</code>-Terminated strings</h3>
+ <dd>
+ <dt>Slow</dt><dd>Time taken to obtain the length increases with each <em>byte</em> aka <code class="math">O(n)</code> while length prefix is constant-time aka <code class="math">O(1)</code>.</dd>
+ <dt>Unsafe</dt><dd>How do you handle <code>NULL</code> being present in the middle of a string? Or <code>NULL</code> being absent?</dd>
+ </dd>
+
+ <h3 id="errno"><code>errno</code></h3>
+ <p>
+ Implementation-defined, had to become stored in thread-local-storage in modern systems so it's not actually a global variable… enjoy.<br />
+ It's also a very poor way to handle errors, if you're wondering where the occasional "Error: Success" comes from: This is it.<br />
+ And of course, it means having a pretty much static amount of possible errors.
+ </p>
- <section id="getaddrinfo">
- <h3><code>getaddrinfo(3)</code>, <code>gethostbyname(3)</code>, …</h3>
+ <h3 id="libnss"><code>nsswitch.conf</code>, <code>resolv.conf</code>, …</h3>
+ <p>
+ Because falsely language-independent configurations with implementation-defined options are the best.<br />
+ Please consider: Clean ABI; Virtual filesystems (could look like <a href="https://www.openwall.com/tcb/">tcb shadow</a> for <code>passwd</code>); or proper servers instead.
+ </p>
+ <p>
+ It also doesn't allows to do any query that aren't precooked for you, for example you cannot query DNS records like <code>TXT</code>, arguably it's DNS-specific but still ought to be present in a standard library.
+ </p>
+
+ <h3 id="getaddrinfo"><code>getaddrinfo(3)</code></h3>
+ <p>Related to <a href="#libnss"><code>nsswitch.conf</code></a>.</p>
<ul>
+ <li>Enjoy most developers having to write code to handle multiple records. Hopefully an unreachable/slow host isn't fatal…</li>
<li>Cannot handle <a href="https://en.wikipedia.org/wiki/Happy_Eyeballs">Happy Eyeballs</a> (one of the ways to support IPv6)</li>
<li>Doesn't handles <a href="https://en.wikipedia.org/wiki/SRV_record"><code>SRV</code> records</a>, similarly to how email is using <a href="https://en.wikipedia.org/wiki/MX_record"><code>MX</code> records</a> (not handled either but at least it's a special case).</li>
</ul>
- <p>Compare this to <a href="http://man.9front.org/2/dial">Plan9 <code>dial(2)</code></a> which also has a nice <code>NetConnInfo</code> structure</p>
- </section>
-
- </section> <!-- internet -->
+ <p>Compare this to <a href="http://man.9front.org/2/dial">Plan9 <code>dial(2)</code></a> which also has a nice <code>NetConnInfo</code> structure.</p>
- <section>
- <h2 id="libc">libc and related Unix C shenanigans</h2>
+ <h3 id="gethostbyname"><code>gethostbyname(3)</code></h3>
+ <p>The older brother of <a href="#getaddrinfo"><code>getaddrinfo(3)</code></a>, it doesn't handles multiple records.</p>
- <section>
- <h3><code>NULL</code>-Terminated strings</h3>
- <dd>
- <dt>Slow</dt><dd>Time taken to obtain the length increases with each <em>byte</em> aka <code class="math">O(n)</code> while length prefix is constant-time <code class="math">O(1)</code>.</dd>
- <dt>Unsafe</dt><dd>How do you handle NULL being present in a string? Or NULL being absent?</dd>
- </dd>
- </section>
+ <h2>See Also</h2>
+ <ul>
+ <li><a href="https://utcc.utoronto.ca/~cks/space/blog/unix/CLibraryAPIRequiresC">The Unix C library API can only be reliably used from C</a></li>
+ </ul>
- </section> <!-- libc -->
</main>
<!--#include file="/templates/en/footer.shtml" -->
</body>