summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-03-14 12:24:39 +0100
committerLennart Poettering <lennart@poettering.net>2019-03-14 13:25:51 +0100
commit2b2fec7db0791e40b46cc99d8a1eea6eddaf0f39 (patch)
treead343275593ae9811ef6ec9ac93ef742f0921f9c
parentutil: split out plymouth related stuff (diff)
downloadsystemd-2b2fec7db0791e40b46cc99d8a1eea6eddaf0f39.tar.xz
systemd-2b2fec7db0791e40b46cc99d8a1eea6eddaf0f39.zip
util: split out errno related stuff
-rw-r--r--src/activate/activate.c1
-rw-r--r--src/basic/async.c1
-rw-r--r--src/basic/errno-util.h29
-rw-r--r--src/basic/fs-util.h2
-rw-r--r--src/basic/log.c2
-rw-r--r--src/basic/meson.build1
-rw-r--r--src/basic/rm-rf.h2
-rw-r--r--src/basic/selinux-util.c2
-rw-r--r--src/basic/util.h25
-rw-r--r--src/journal/journal-send.c2
-rw-r--r--src/journal/mmap-cache.c1
-rw-r--r--src/libsystemd/sd-bus/bus-error.c1
-rw-r--r--src/libsystemd/sd-resolve/sd-resolve.c1
-rw-r--r--src/nss-myhostname/nss-myhostname.c2
-rw-r--r--src/nss-mymachines/nss-mymachines.c1
-rw-r--r--src/nss-resolve/nss-resolve.c4
-rw-r--r--src/shared/calendarspec.c1
-rw-r--r--src/shared/clock-util.c2
-rw-r--r--src/shared/json.c1
-rw-r--r--src/test/test-chown-rec.c1
20 files changed, 48 insertions, 34 deletions
diff --git a/src/activate/activate.c b/src/activate/activate.c
index 9a83bc7f24..7eae9e22c2 100644
--- a/src/activate/activate.c
+++ b/src/activate/activate.c
@@ -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"
diff --git a/src/basic/async.c b/src/basic/async.c
index c45ca01847..daa95cd102 100644
--- a/src/basic/async.c
+++ b/src/basic/async.c
@@ -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
index 0000000000..2d72b8ce9e
--- /dev/null
+++ b/src/basic/errno-util.h
@@ -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;
+}
diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h
index 9c9044669d..b9651205e6 100644
--- a/src/basic/fs-util.h
+++ b/src/basic/fs-util.h
@@ -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);
diff --git a/src/basic/log.c b/src/basic/log.c
index 84621932db..3b7bff3a97 100644
--- a/src/basic/log.c
+++ b/src/basic/log.c
@@ -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)
diff --git a/src/basic/meson.build b/src/basic/meson.build
index c666ab941f..1f7ef8683a 100644
--- a/src/basic/meson.build
+++ b/src/basic/meson.build
@@ -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
diff --git a/src/basic/rm-rf.h b/src/basic/rm-rf.h
index 3ee2b97e37..d42ebef434 100644
--- a/src/basic/rm-rf.h
+++ b/src/basic/rm-rf.h
@@ -3,7 +3,7 @@
#include <sys/stat.h>
-#include "util.h"
+#include "errno-util.h"
typedef enum RemoveFlags {
REMOVE_ONLY_DIRECTORIES = 1 << 0,
diff --git a/src/basic/selinux-util.c b/src/basic/selinux-util.c
index dc06f3d074..375da920f7 100644
--- a/src/basic/selinux-util.c
+++ b/src/basic/selinux-util.c
@@ -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);
diff --git a/src/basic/util.h b/src/basic/util.h
index f6f005a29b..d1a8a8f3b4 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -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;
diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
index 8618454131..5ef11fa1a4 100644
--- a/src/journal/journal-send.c
+++ b/src/journal/journal-send.c
@@ -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)
diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c
index 7152564293..e2f7bd7ec4 100644
--- a/src/journal/mmap-cache.c
+++ b/src/journal/mmap-cache.c
@@ -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"
diff --git a/src/libsystemd/sd-bus/bus-error.c b/src/libsystemd/sd-bus/bus-error.c
index dc952375b6..96319645d1 100644
--- a/src/libsystemd/sd-bus/bus-error.c
+++ b/src/libsystemd/sd-bus/bus-error.c
@@ -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"
diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c
index fdad3bd697..868cc023b1 100644
--- a/src/libsystemd/sd-resolve/sd-resolve.c
+++ b/src/libsystemd/sd-resolve/sd-resolve.c
@@ -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"
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c
index e491351dee..707caaa321 100644
--- a/src/nss-myhostname/nss-myhostname.c
+++ b/src/nss-myhostname/nss-myhostname.c
@@ -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
diff --git a/src/nss-mymachines/nss-mymachines.c b/src/nss-mymachines/nss-mymachines.c
index da003e6aa7..a73ac939a7 100644
--- a/src/nss-mymachines/nss-mymachines.c
+++ b/src/nss-mymachines/nss-mymachines.c
@@ -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"
diff --git a/src/nss-resolve/nss-resolve.c b/src/nss-resolve/nss-resolve.c
index 8370fed076..12c9c4f7f3 100644
--- a/src/nss-resolve/nss-resolve.c
+++ b/src/nss-resolve/nss-resolve.c
@@ -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);
diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c
index e7ee90aa9c..601bde6d4d 100644
--- a/src/shared/calendarspec.c
+++ b/src/shared/calendarspec.c
@@ -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"
diff --git a/src/shared/clock-util.c b/src/shared/clock-util.c
index 1877a81434..32cce1e109 100644
--- a/src/shared/clock-util.c
+++ b/src/shared/clock-util.c
@@ -12,11 +12,11 @@
#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;
diff --git a/src/shared/json.c b/src/shared/json.c
index 55163a733b..253957d298 100644
--- a/src/shared/json.c
+++ b/src/shared/json.c
@@ -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"
diff --git a/src/test/test-chown-rec.c b/src/test/test-chown-rec.c
index 9e14672b2f..7e93e487d2 100644
--- a/src/test/test-chown-rec.c
+++ b/src/test/test-chown-rec.c
@@ -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"