chiark / gitweb /
log: minimize includes in log.h
authorLennart Poettering <lennart@poettering.net>
Wed, 10 Jan 2018 23:39:12 +0000 (00:39 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:50:07 +0000 (07:50 +0200)
log.h really should only include the bare minimum of other headers, as
it is really pulled into pretty much everything else and already in
itself one of the most basic pieces of code we have.

Let's hence drop inclusion of:

1. sd-id128.h because it's entirely unneeded in current log.h
2. errno.h, dito.
3. sys/signalfd.h which we can replace by a simple struct forward
   declaration
4. process-util.h which was needed for getpid_cached() which we now hide
   in a funciton log_emergency_level() instead, which nicely abstracts
   the details away.
5. sys/socket.h which was needed for struct iovec, but a simple struct
   forward declaration suffices for that too.

Ultimately this actually makes our source tree larger (since users of
the functionality above must now include it themselves, log.h won't do
that for them), but I think it helps to untangle our web of includes a
tiny bit.

(Background: I'd like to isolate the generic bits of src/basic/ enough
so that we can do a git submodule import into casync for it)

33 files changed:
src/basic/errno-list.c
src/basic/fs-util.c
src/basic/gunicode.c
src/basic/hash-funcs.c
src/basic/hostname-util.h
src/basic/log.c
src/basic/log.h
src/basic/process-util.h
src/basic/random-util.c
src/basic/socket-util.c
src/basic/stat-util.c
src/basic/time-util.c
src/basic/verbs.c
src/libelogind/sd-bus/bus-control.c
src/libelogind/sd-bus/bus-gvariant.c
src/libelogind/sd-bus/bus-signature.c
src/libelogind/sd-bus/bus-socket.c
src/libelogind/sd-bus/bus-type.c
src/libelogind/sd-bus/bus-type.h
src/libelogind/sd-bus/sd-bus.c
src/libelogind/sd-daemon/sd-daemon.c
src/libelogind/sd-id128/id128-util.c
src/login/logind-core.c
src/login/logind.c
src/shared/test-tables.h
src/test/test-cgroup.c
src/test/test-extract-word.c
src/test/test-hash.c
src/test/test-hexdecoct.c
src/test/test-log.c
src/test/test-parse-util.c
src/test/test-sizeof.c
src/test/test-util.c

index ee48332dbb5f66040b39058577c6c91b522f0976..256eec0867d5ce75ed7a65b5ca9145fa6407a5d1 100644 (file)
@@ -18,6 +18,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+//#include <errno.h>
 #include <string.h>
 
 #include "errno-list.h"
index 0cd339d299d31f0d2cf766c86ee178e7d8fbec09..a03cbfe35712d166732cf19d79993397a63c79a5 100644 (file)
@@ -39,6 +39,7 @@
 #include "mkdir.h"
 #include "parse-util.h"
 #include "path-util.h"
+//#include "process-util.h"
 #include "stat-util.h"
 #include "stdio-util.h"
 #include "string-util.h"
index e6ac0545a4efc5c0e0d5fc3d0c34c71eda0a53f5..8aff4a0fc509b8b1fead206a5f4f501ac1788130 100644 (file)
@@ -4,8 +4,6 @@
  *  Copyright 2000, 2005 Red Hat, Inc.
  */
 
-#include <stdlib.h>
-
 #include "gunicode.h"
 
 #define unichar uint32_t
index e69f81558dd7aa3120589935b5ac4a64e735e010..1716401d17e80640c2ff11aacfc63416f3176132 100644 (file)
@@ -19,6 +19,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+//#include <string.h>
+
 #include "hash-funcs.h"
 
 void string_hash_func(const void *p, struct siphash *state) {
index c10ba3261d37c3e8c7462eb4cc859ac7a5064f8b..37fb560042546948467bf15d1c97bd1c52e6ee2e 100644 (file)
@@ -21,6 +21,7 @@
 ***/
 
 #include <stdbool.h>
+//#include <stdio.h>
 
 #include "macro.h"
 
index 43cb7009622b0fa3e47b030345b86aacd448f779..5bbf65a4a4f38fe722ceae0a105095c5a467d396 100644 (file)
@@ -1260,7 +1260,6 @@ void log_received_signal(int level, const struct signalfd_siginfo *si) {
                 log_full(level,
                          "Received SIG%s.",
                          signal_to_string(si->ssi_signo));
-
 }
 
 #endif // 0
@@ -1324,3 +1323,10 @@ void log_set_always_reopen_console(bool b) {
 void log_set_open_when_needed(bool b) {
         open_when_needed = b;
 }
+
+int log_emergency_level(void) {
+        /* Returns the log level to use for log_emergency() logging. We use LOG_EMERG only when we are PID 1, as only
+         * then the system of the whole system is obviously affected. */
+
+        return getpid_cached() == 1 ? LOG_EMERG : LOG_ERR;
+}
index 297bb92b99c03567930adf4a33b54368e540f0ea..3bcc877665f19afb58e5b3f06f4f4c93147a2072 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <errno.h>
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <sys/signalfd.h>
-#include <sys/socket.h>
 #include <syslog.h>
 
-#include "sd-id128.h"
-
 #include "macro.h"
-#include "process-util.h"
+
+/* Some structures we reference but don't want to pull in headers for */
+struct iovec;
+struct signalfd_siginfo;
 
 typedef enum LogRealm {
         LOG_REALM_SYSTEMD,
@@ -196,7 +194,7 @@ int log_struct_iovec_internal(
                 const char *file,
                 int line,
                 const char *func,
-                const struct iovec input_iovec[],
+                const struct iovec *input_iovec,
                 size_t n_input_iovec);
 
 /* This modifies the buffer passed! */
@@ -254,13 +252,15 @@ void log_assert_failed_return_realm(
 
 #define log_full(level, ...) log_full_errno((level), 0, __VA_ARGS__)
 
+int log_emergency_level(void);
+
 /* Normal logging */
 #define log_debug(...)     log_full(LOG_DEBUG,   __VA_ARGS__)
 #define log_info(...)      log_full(LOG_INFO,    __VA_ARGS__)
 #define log_notice(...)    log_full(LOG_NOTICE,  __VA_ARGS__)
 #define log_warning(...)   log_full(LOG_WARNING, __VA_ARGS__)
 #define log_error(...)     log_full(LOG_ERR,     __VA_ARGS__)
-#define log_emergency(...) log_full(getpid_cached() == 1 ? LOG_EMERG : LOG_ERR, __VA_ARGS__)
+#define log_emergency(...) log_full(log_emergency_level(), __VA_ARGS__)
 
 /* Logging triggered by an errno-like error */
 #define log_debug_errno(error, ...)     log_full_errno(LOG_DEBUG,   error, __VA_ARGS__)
@@ -268,7 +268,7 @@ void log_assert_failed_return_realm(
 #define log_notice_errno(error, ...)    log_full_errno(LOG_NOTICE,  error, __VA_ARGS__)
 #define log_warning_errno(error, ...)   log_full_errno(LOG_WARNING, error, __VA_ARGS__)
 #define log_error_errno(error, ...)     log_full_errno(LOG_ERR,     error, __VA_ARGS__)
-#define log_emergency_errno(error, ...) log_full_errno(getpid_cached() == 1 ? LOG_EMERG : LOG_ERR, error, __VA_ARGS__)
+#define log_emergency_errno(error, ...) log_full_errno(log_emergency_level(), error, __VA_ARGS__)
 
 #ifdef LOG_TRACE
 #  define log_trace(...) log_debug(__VA_ARGS__)
index 652e4c34163e0b25348a20012990a849e022585d..7942d36e600e6c58b6bd409a3dc83b66f6b6a207 100644 (file)
@@ -21,6 +21,7 @@
 ***/
 
 #include <alloca.h>
+//#include <errno.h>
 #include <sched.h>
 #include <signal.h>
 #include <stdbool.h>
index 1bc8000896662d2166f111ccf1348c608b6c2f4f..127c4522b8839eb15a116c178a1a842f53cb04cf 100644 (file)
 #include <elf.h>
 #include <errno.h>
 #include <fcntl.h>
+//#include <linux/random.h>
 #include <stdbool.h>
+//#include <stdint.h>
 #include <stdlib.h>
+//#include <string.h>
 #include <sys/time.h>
-#include <linux/random.h>
-#include <stdint.h>
 
 #if HAVE_SYS_AUXV_H
 #  include <sys/auxv.h>
index c170e7432749c6e100ef409ad275349de21d0f78..d89136b01f7a373a2ec0742b6b374a5e689645f8 100644 (file)
@@ -41,6 +41,7 @@
 #include "missing.h"
 #include "parse-util.h"
 #include "path-util.h"
+//#include "process-util.h"
 #include "socket-util.h"
 #include "string-table.h"
 #include "string-util.h"
index 064e316fc99b13cc97ea1df34e7cdefdca36bab7..964fa91b23c7052416663c69218a2092f57001ee 100644 (file)
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
 #include <linux/magic.h>
+//#include <sched.h>
+//#include <sys/stat.h>
 #include <sys/statvfs.h>
+//#include <sys/types.h>
 #include <unistd.h>
 
 #include "dirent-util.h"
index 98324c2346b6d079c438f8556d8e62351d9fbcd3..dc387d8b7ff8a959d4223262fec5458b792a35e2 100644 (file)
@@ -38,6 +38,7 @@
 #include "macro.h"
 #include "parse-util.h"
 #include "path-util.h"
+//#include "process-util.h"
 #include "string-util.h"
 #include "strv.h"
 #include "time-util.h"
index 4f17d39f8006ed9938f179190466e154727efe6d..f2e9f29d6e9e3ed2a2b48b6de269c359ff62c248 100644 (file)
 #include <getopt.h>
 #include <stdbool.h>
 #include <stddef.h>
+//#include <string.h>
 
 //#include "env-util.h"
 #include "log.h"
 #include "macro.h"
+//#include "process-util.h"
 #include "string-util.h"
 #include "verbs.h"
 #include "virt.h"
index c6e3bf99fb20bf7b8a9089bf7f3e74eda2ad546c..819128cbd84ea961a9e2860d7c801ce54aef5768 100644 (file)
@@ -33,6 +33,7 @@
 #include "bus-message.h"
 #include "bus-util.h"
 #include "capability-util.h"
+//#include "process-util.h"
 #include "stdio-util.h"
 #include "string-util.h"
 #include "strv.h"
index 6a990a02c0485595ccba2be4bd43653f4ae8f3c5..8730a924cd4a0e174339156bbe77ed3c71ca01cb 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+//#include <errno.h>
+//#include <string.h>
+
+//#include "sd-bus.h"
+
 #include "bus-gvariant.h"
 #include "bus-signature.h"
 #include "bus-type.h"
index d16461f4ae95a56171e8a373db3fdbe60a83ad54..ba9708c7bb2239b9c56e8a92b39d59b1696bf6d8 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <util.h>
 
+//#include "sd-bus.h"
+
 #include "bus-signature.h"
 #include "bus-type.h"
 
index bc64779d356db01345c6f1639ee3f0d3ebd6abb9..bd0895f275ac36d7e51dc8f9e95c613810299105 100644 (file)
@@ -38,6 +38,7 @@
 #include "macro.h"
 #include "missing.h"
 //#include "path-util.h"
+//#include "process-util.h"
 #include "selinux-util.h"
 #include "signal-util.h"
 #include "stdio-util.h"
@@ -620,10 +621,13 @@ static void bus_get_peercred(sd_bus *b) {
 
         /* Get the list of auxiliary groups of the peer */
         r = getpeergroups(b->input_fd, &b->groups);
-        if (r >= 0)
+        if (r < 0) {
+                if (!IN_SET(r, -EOPNOTSUPP, -ENOPROTOOPT))
+                        log_debug_errno(r, "Failed to determine peer groups list: %m");
+
+                b->n_groups = (size_t) -1;
+        } else
                 b->n_groups = (size_t) r;
-        else if (!IN_SET(r, -EOPNOTSUPP, -ENOPROTOOPT))
-                log_debug_errno(r, "Failed to determine peer's group list: %m");
 }
 
 static int bus_socket_start_auth_client(sd_bus *b) {
index 817040b1ada8c42d3974e1edfac6f15c752efcbe..c580faaf91679668fa20c986e2d963699f83d7bd 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+//#include <errno.h>
+
+//#include "sd-bus.h"
+
 #include "bus-type.h"
 
 bool bus_type_is_valid(char c) {
index ae272b1e6a33521b8bc3cfe49f5e5e939d0a1fb2..834f09777a5d05fc6ead547e4b3f5bf43feac51c 100644 (file)
@@ -22,8 +22,6 @@
 
 #include <stdbool.h>
 
-#include "sd-bus.h"
-
 #include "macro.h"
 
 bool bus_type_is_valid(char c) _const_;
index 0668df2c19add40120074365ab2b71a4d5fbcdf2..0a43324b9e55521b29b5163a4b99504e8ab54fd2 100644 (file)
@@ -50,6 +50,7 @@
 #include "macro.h"
 #include "missing.h"
 #include "parse-util.h"
+//#include "process-util.h"
 #include "string-util.h"
 #include "strv.h"
 #include "util.h"
index 3e4c19cf538804450ec0e357831771ac016a7cc3..147042c9aec829d94304dde7b62b98d122810cfa 100644 (file)
@@ -39,6 +39,7 @@
 #include "fs-util.h"
 #include "parse-util.h"
 #include "path-util.h"
+//#include "process-util.h"
 #include "socket-util.h"
 #include "strv.h"
 #include "util.h"
index 6f6334bbe865fa5e50ab5792e64e492f1fc608a4..bdadf3efac47e50485d9ee3f81c72caf14673ca1 100644 (file)
@@ -18,6 +18,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+//#include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
 
index 71b9c76d31f723cd5664e5c27193a49ac24afb8f..625521e34a153c787fc58cc7475f6a7499510a87 100644 (file)
@@ -31,6 +31,7 @@
 #include "fd-util.h"
 #include "logind.h"
 #include "parse-util.h"
+//#include "process-util.h"
 #include "strv.h"
 #include "terminal-util.h"
 #include "udev-util.h"
index 0238cd889b95702cf45f382f4cc0a510754087ee..6993b965eebdf2a3a6878b63caf5b9a23d8ad7c0 100644 (file)
 #include "alloc-util.h"
 #include "bus-error.h"
 #include "bus-util.h"
+//#include "cgroup-util.h"
 #include "conf-parser.h"
 #include "def.h"
 #include "dirent-util.h"
 #include "fd-util.h"
 #include "format-util.h"
 #include "logind.h"
+//#include "process-util.h"
 #include "selinux-util.h"
 #include "signal-util.h"
 #include "strv.h"
index 6b223b1ee56afd9205fd595df87934ecac13f74b..b1ca4247f12ce79023dcd384aa5990aa4ef4d908 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+//#include <string.h>
 
 typedef const char* (*lookup_t)(int);
 typedef int (*reverse_t)(const char*);
index 5b06b9b1ad4d6fa51e2301d8b3f9d51ba8b146b2..232577a707e5c221f23295e7e157dc0b106b3212 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "cgroup-util.h"
 #include "path-util.h"
+//#include "process-util.h"
 #include "string-util.h"
 #include "util.h"
 /// Additional includes needed by elogind
index c8f735607b6ec638b1170f4011c8c09a3dfd8c81..cff40a4fb3e531a0a8330700d2560f7096062ccc 100644 (file)
@@ -19,6 +19,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+//#include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 
index f3b4258d6b5b4227831fcf4cbe427a131af83cf9..a08771abb70845742665207161281e87b0efc545 100644 (file)
@@ -18,6 +18,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+//#include <errno.h>
 #include <stdio.h>
 
 #include "alloc-util.h"
index fdb1d1ae39ccb887b5c3c210583a0ded044b582d..5756340f38755c28b6d6b70012181026fb818855 100644 (file)
@@ -18,6 +18,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+//#include <errno.h>
+
 #include "alloc-util.h"
 #include "hexdecoct.h"
 #include "macro.h"
index 3754b1285cc10140996f67abf703e9d75f635edb..242092bc19b1567fe7f1427825cf3d61d4d9624d 100644 (file)
@@ -23,9 +23,9 @@
 
 #include "format-util.h"
 #include "log.h"
-#include "util.h"
 /// Additional includes needed by elogind
 #include "process-util.h"
+//#include "util.h"
 
 assert_cc(LOG_REALM_REMOVE_LEVEL(LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, LOG_FTP | LOG_DEBUG))
           == LOG_REALM_SYSTEMD);
index 241145806e1fcd5dbfa16ed6e9ed9814a63d522c..668b5cdee67f7adfd44b751b00ea6966baa3d825 100644 (file)
@@ -19,6 +19,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+//#include <errno.h>
 #include <locale.h>
 #include <math.h>
 
index cdca954eae3828f33cf351094df9a1e4fc04539a..0d96b02c2a4c1225ff4ba3ad5f8f14fab6cb60b8 100644 (file)
@@ -19,6 +19,7 @@
 ***/
 
 #include <stdio.h>
+//#include <string.h>
 
 #include "time-util.h"
 
index c08a51a95c28ba1f4f2d13b9e3d66371932ad491..1bb39a69d987024c75e04ab20cb2fdf61f506912 100644 (file)
@@ -28,6 +28,7 @@
 #include "fileio.h"
 #include "fs-util.h"
 #include "parse-util.h"
+//#include "process-util.h"
 //#include "raw-clone.h"
 #include "rm-rf.h"
 #include "string-util.h"