Skip to content

Commit dccca82

Browse files
committed
log: minimize includes in log.h
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)
1 parent 1a86b08 commit dccca82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+124
-22
lines changed

src/basic/af-list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
along with systemd; If not, see <http://www.gnu.org/licenses/>.
2121
***/
2222

23+
#include <sys/socket.h>
24+
2325
#include "string-util.h"
2426

2527
const char *af_to_name(int id);

src/basic/calendarspec.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "fileio.h"
3636
#include "macro.h"
3737
#include "parse-util.h"
38+
#include "process-util.h"
3839
#include "string-util.h"
3940
#include "time-util.h"
4041

src/basic/errno-list.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
along with systemd; If not, see <http://www.gnu.org/licenses/>.
1919
***/
2020

21+
#include <errno.h>
2122
#include <string.h>
2223

2324
#include "errno-list.h"

src/basic/ether-addr-util.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
along with systemd; If not, see <http://www.gnu.org/licenses/>.
1919
***/
2020

21+
#include <errno.h>
2122
#include <net/ethernet.h>
2223
#include <stdio.h>
2324
#include <sys/types.h>

src/basic/fs-util.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "mkdir.h"
4040
#include "parse-util.h"
4141
#include "path-util.h"
42+
#include "process-util.h"
4243
#include "stat-util.h"
4344
#include "stdio-util.h"
4445
#include "string-util.h"

src/basic/gunicode.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* Copyright 2000, 2005 Red Hat, Inc.
55
*/
66

7-
#include <stdlib.h>
8-
97
#include "gunicode.h"
108

119
#define unichar uint32_t

src/basic/hash-funcs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
along with systemd; If not, see <http://www.gnu.org/licenses/>.
2020
***/
2121

22+
#include <string.h>
23+
2224
#include "hash-funcs.h"
2325

2426
void string_hash_func(const void *p, struct siphash *state) {

src/basic/hostname-util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
***/
2222

2323
#include <stdbool.h>
24+
#include <stdio.h>
2425

2526
#include "macro.h"
2627

src/basic/journal-importer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
along with systemd; If not, see <http://www.gnu.org/licenses/>.
1919
***/
2020

21+
#include <errno.h>
2122
#include <unistd.h>
2223

2324
#include "alloc-util.h"

src/basic/log.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,6 @@ void log_received_signal(int level, const struct signalfd_siginfo *si) {
12391239
log_full(level,
12401240
"Received SIG%s.",
12411241
signal_to_string(si->ssi_signo));
1242-
12431242
}
12441243

12451244
int log_syntax_internal(
@@ -1300,3 +1299,10 @@ void log_set_always_reopen_console(bool b) {
13001299
void log_set_open_when_needed(bool b) {
13011300
open_when_needed = b;
13021301
}
1302+
1303+
int log_emergency_level(void) {
1304+
/* Returns the log level to use for log_emergency() logging. We use LOG_EMERG only when we are PID 1, as only
1305+
* then the system of the whole system is obviously affected. */
1306+
1307+
return getpid_cached() == 1 ? LOG_EMERG : LOG_ERR;
1308+
}

0 commit comments

Comments
 (0)