]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: split out errno related stuff
authorLennart Poettering <lennart@poettering.net>
Thu, 14 Mar 2019 11:24:39 +0000 (12:24 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 14 Mar 2019 12:25:51 +0000 (13:25 +0100)
20 files changed:
src/activate/activate.c
src/basic/async.c
src/basic/errno-util.h [new file with mode: 0644]
src/basic/fs-util.h
src/basic/log.c
src/basic/meson.build
src/basic/rm-rf.h
src/basic/selinux-util.c
src/basic/util.h
src/journal/journal-send.c
src/journal/mmap-cache.c
src/libsystemd/sd-bus/bus-error.c
src/libsystemd/sd-resolve/sd-resolve.c
src/nss-myhostname/nss-myhostname.c
src/nss-mymachines/nss-mymachines.c
src/nss-resolve/nss-resolve.c
src/shared/calendarspec.c
src/shared/clock-util.c
src/shared/json.c
src/test/test-chown-rec.c

index 9a83bc7f24378e9f0484a2e1007c3892af71c76a..7eae9e22c2858a52a388e57aa157001170e110b7 100644 (file)
@@ -10,6 +10,7 @@
 #include "sd-daemon.h"
 
 #include "alloc-util.h"
+#include "errno-util.h"
 #include "escape.h"
 #include "fd-util.h"
 #include "log.h"
index c45ca01847f398afc453133c19a247f599eb2c65..daa95cd102fb4f5d2487064ae81507f5c9d98d7d 100644 (file)
@@ -6,6 +6,7 @@
 #include <unistd.h>
 
 #include "async.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "log.h"
 #include "macro.h"
diff --git a/src/basic/errno-util.h b/src/basic/errno-util.h
new file mode 100644 (file)
index 0000000..2d72b8c
--- /dev/null
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#pragma once
+
+#include "macro.h"
+
+static inline void _reset_errno_(int *saved_errno) {
+        if (*saved_errno < 0) /* Invalidated by UNPROTECT_ERRNO? */
+                return;
+
+        errno = *saved_errno;
+}
+
+#define PROTECT_ERRNO                                                   \
+        _cleanup_(_reset_errno_) _unused_ int _saved_errno_ = errno
+
+#define UNPROTECT_ERRNO                         \
+        do {                                    \
+                errno = _saved_errno_;          \
+                _saved_errno_ = -1;             \
+        } while (false)
+
+static inline int negative_errno(void) {
+        /* This helper should be used to shut up gcc if you know 'errno' is
+         * negative. Instead of "return -errno;", use "return negative_errno();"
+         * It will suppress bogus gcc warnings in case it assumes 'errno' might
+         * be 0 and thus the caller's error-handling might not be triggered. */
+        assert_return(errno > 0, -EINVAL);
+        return -errno;
+}
index 9c9044669d9c436672870c91b297105703100fc8..b9651205e60818661ebf97af4e8cfc38f0e9c8bb 100644 (file)
@@ -10,8 +10,8 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include "errno-util.h"
 #include "time-util.h"
-#include "util.h"
 
 int unlink_noerrno(const char *path);
 
index 84621932db4946fe6282407bd3d026a400bf8480..3b7bff3a973af93a141955f65ea7f221c264ef0d 100644 (file)
@@ -19,6 +19,7 @@
 #include "sd-messages.h"
 
 #include "alloc-util.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "format-util.h"
 #include "io-util.h"
@@ -37,7 +38,6 @@
 #include "terminal-util.h"
 #include "time-util.h"
 #include "utf8.h"
-#include "util.h"
 
 #define SNDBUF_SIZE (8*1024*1024)
 
index c666ab941f49ccdbfe2dc0a778ec71da77629aad..1f7ef8683a463b44e15d9dc26a7878f60c53e4d4 100644 (file)
@@ -45,6 +45,7 @@ basic_sources = files('''
         env-util.h
         errno-list.c
         errno-list.h
+        errno-util.h
         escape.c
         escape.h
         ether-addr-util.c
index 3ee2b97e3768ba967bd5fd1388ffbc33558bf2c8..d42ebef4349135ff533de1a372b805a4c0a35a9c 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <sys/stat.h>
 
-#include "util.h"
+#include "errno-util.h"
 
 typedef enum RemoveFlags {
         REMOVE_ONLY_DIRECTORIES = 1 << 0,
index dc06f3d0740c59a24e953964fa00bf170efe0cfb..375da920f7a21cdfe61791a015b505ff08c19d06 100644 (file)
@@ -16,6 +16,7 @@
 #endif
 
 #include "alloc-util.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "log.h"
 #include "macro.h"
@@ -23,7 +24,6 @@
 #include "selinux-util.h"
 #include "stdio-util.h"
 #include "time-util.h"
-#include "util.h"
 
 #if HAVE_SELINUX
 DEFINE_TRIVIAL_CLEANUP_FUNC(char*, freecon);
index f6f005a29bcc7dac3f81b4e488c6e1c16e6f4bff..d1a8a8f3b47ac9928c6aeb4a2050217fe2f8fea8 100644 (file)
@@ -63,31 +63,6 @@ void in_initrd_force(bool value);
 
 int on_ac_power(void);
 
-static inline void _reset_errno_(int *saved_errno) {
-        if (*saved_errno < 0) /* Invalidated by UNPROTECT_ERRNO? */
-                return;
-
-        errno = *saved_errno;
-}
-
-#define PROTECT_ERRNO                                                   \
-        _cleanup_(_reset_errno_) _unused_ int _saved_errno_ = errno
-
-#define UNPROTECT_ERRNO                         \
-        do {                                    \
-                errno = _saved_errno_;          \
-                _saved_errno_ = -1;             \
-        } while (false)
-
-static inline int negative_errno(void) {
-        /* This helper should be used to shut up gcc if you know 'errno' is
-         * negative. Instead of "return -errno;", use "return negative_errno();"
-         * It will suppress bogus gcc warnings in case it assumes 'errno' might
-         * be 0 and thus the caller's error-handling might not be triggered. */
-        assert_return(errno > 0, -EINVAL);
-        return -errno;
-}
-
 static inline unsigned u64log2(uint64_t n) {
 #if __SIZEOF_LONG_LONG__ == 8
         return (n > 1) ? (unsigned) __builtin_clzll(n) ^ 63U : 0;
index 8618454131bcb70c02c0a9d90d012fcc1de873bb..5ef11fa1a48820366730a5aaf7ec7b213a7f3d44 100644 (file)
@@ -13,6 +13,7 @@
 #include "sd-journal.h"
 
 #include "alloc-util.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "io-util.h"
 #include "memfd-util.h"
@@ -20,7 +21,6 @@
 #include "stdio-util.h"
 #include "string-util.h"
 #include "tmpfile-util.h"
-#include "util.h"
 
 #define SNDBUF_SIZE (8*1024*1024)
 
index 7152564293194fb8495b2753d1c59f423db3428f..e2f7bd7ec45761e2e9369f9f256a9c1ef802d425 100644 (file)
@@ -5,6 +5,7 @@
 #include <sys/mman.h>
 
 #include "alloc-util.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "hashmap.h"
 #include "list.h"
index dc952375b6853729eccd3b3acdf606a242e53524..96319645d1f70e94412d6b3ce78605e04a549bb4 100644 (file)
@@ -12,6 +12,7 @@
 #include "alloc-util.h"
 #include "bus-error.h"
 #include "errno-list.h"
+#include "errno-util.h"
 #include "string-util.h"
 #include "util.h"
 
index fdad3bd6972ef72bdcc0e72b993c1adcb746e33c..868cc023b12984b9ea689c4fc3c59625ed2d1c0d 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "alloc-util.h"
 #include "dns-domain.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "io-util.h"
 #include "list.h"
index e491351deed28b6ef45ec31c76c726ee724859fd..707caaa321b4bb205204bd6592d093d6b358266b 100644 (file)
@@ -8,13 +8,13 @@
 #include <string.h>
 
 #include "alloc-util.h"
+#include "errno-util.h"
 #include "hostname-util.h"
 #include "local-addresses.h"
 #include "macro.h"
 #include "nss-util.h"
 #include "signal-util.h"
 #include "string-util.h"
-#include "util.h"
 
 /* We use 127.0.0.2 as IPv4 address. This has the advantage over
  * 127.0.0.1 that it can be translated back to the local hostname. For
index da003e6aa75791d155d86b023559154ef5c368c9..a73ac939a7495c16fe7d908fa302adc50944ab78 100644 (file)
@@ -9,6 +9,7 @@
 #include "alloc-util.h"
 #include "bus-common-errors.h"
 #include "env-util.h"
+#include "errno-util.h"
 #include "hostname-util.h"
 #include "in-addr-util.h"
 #include "macro.h"
index 8370fed07608b30551e0ce3098351a85897826be..12c9c4f7f362bb5013ec6e301e1e3118756ff18d 100644 (file)
@@ -9,13 +9,13 @@
 #include "sd-bus.h"
 
 #include "bus-common-errors.h"
+#include "errno-util.h"
 #include "in-addr-util.h"
 #include "macro.h"
 #include "nss-util.h"
 #include "resolved-def.h"
-#include "string-util.h"
-#include "util.h"
 #include "signal-util.h"
+#include "string-util.h"
 
 NSS_GETHOSTBYNAME_PROTOTYPES(resolve);
 NSS_GETHOSTBYADDR_PROTOTYPES(resolve);
index e7ee90aa9c57f3bc7bcafb2a50fdf216183076c6..601bde6d4da90d4203fad4b7a73e90294db566f7 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "alloc-util.h"
 #include "calendarspec.h"
+#include "errno-util.h"
 #include "fileio.h"
 #include "macro.h"
 #include "parse-util.h"
index 1877a81434578d1723d5c761b518e1056b329319..32cce1e1098a4528128feae14e0c75830071c857 100644 (file)
 
 #include "alloc-util.h"
 #include "clock-util.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "macro.h"
 #include "string-util.h"
-#include "util.h"
 
 int clock_get_hwclock(struct tm *tm) {
         _cleanup_close_ int fd = -1;
index 55163a733b39cf0effad07a63883e3fb9b684e5e..253957d298ba7f5086986a42e2c5b8b3ab5f7bca 100644 (file)
@@ -11,6 +11,7 @@
 #include "sd-messages.h"
 
 #include "alloc-util.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "float.h"
index 9e14672b2fab61f5cf15f1a07be77628e683e291..7e93e487d2ab76c4671bfccdd4bad42c63e64b90 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
 #include <sys/xattr.h>
+#include <unistd.h>
 
 #include "alloc-util.h"
 #include "chown-recursive.h"