]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
CODING_STYLE: describe log & return operations
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 22 Nov 2018 09:39:31 +0000 (10:39 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 22 Nov 2018 09:54:38 +0000 (10:54 +0100)
docs/CODING_STYLE.md

index e70c56b766bbe5319fc38a304db378750b495c83..8a3a6e2b40220a02bf8ffedf04f9ea03075337da 100644 (file)
   "logging" function, then it should not generate log messages, so
   that log messages are not generated twice for the same errors.
 
+- If possible, do a combined log & return operation:
+
+  ```c
+  r = operation(...);
+  if (r < 0)
+          return log_(error|warning|notice|...)_errno(r, "Failed to ...: %m");
+  ```
+
+  If the error value is "synthetic", i.e. it was not received from
+  the called function, use `SYNTHETIC_ERRNO` wrapper to tell the logging
+  system to not log the errno value, but still return it:
+
+  ```c
+  n = read(..., s, sizeof s);
+  if (n != sizeof s)
+          return log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to read ...");
+  ```
+
 - Avoid static variables, except for caches and very few other
   cases. Think about thread-safety! While most of our code is never
   used in threaded environments, at least the library code should make