chiark / gitweb /
sd-id128: return -ENOMEDIUM on null id
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 16 May 2018 11:55:12 +0000 (13:55 +0200)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
We currently return -ENOMEDIUM when /etc/machine-id is empty, and -EINVAL when
it is all zeros. But -EINVAL is also used for invalid args. The distinction
between empty and all-zero is not very important, let's use the same return
code.

Also document -ENOENT and -ENOMEDIUM since they can be a bit surprising.

man/sd_id128_get_machine.xml
src/libelogind/sd-id128/sd-id128.c

index 2694c186b7248310706d31e854731e7d66f760e2..f3e15176024d022f5462d1ad30d18ea0e05e9f8d 100644 (file)
   <refsect1>
     <title>Return Value</title>
 
-    <para>The two calls return 0 on success (in which case
-    <parameter>ret</parameter> is filled in), or a negative
-    errno-style error code.</para>
+    <para>Those calls return 0 on success (in which case <parameter>ret</parameter> is filled in),
+    or a negative errno-style error code. In particular, <function>sd_id128_get_machine()</function>
+    and <function>sd_id128_get_machine_app_specific()</function> return <constant>-ENOENT</constant>
+    if <filename>/etc/machine-id</filename> is missing, and <constant>-ENOMEDIUM</constant> if is
+    empty or all zeros.</para>
   </refsect1>
 
   <refsect1>
index af2ff8353ab6cba2961274339d467debe565d09b..80548fdfcf9a4c371c035ac050c2f42ac61bcf1a 100644 (file)
@@ -98,7 +98,7 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) {
                         return r;
 
                 if (sd_id128_is_null(saved_machine_id))
-                        return -EINVAL;
+                        return -ENOMEDIUM;
         }
 
         *ret = saved_machine_id;