Merge pull request #7855 from poettering/log-h-includes

log.h #include cleanups
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-01-15 13:43:09 +04:00
committed by GitHub
89 changed files with 182 additions and 249 deletions
+2
View File
@@ -20,6 +20,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <sys/socket.h>
#include "string-util.h"
const char *af_to_name(int id);
+1
View File
@@ -35,6 +35,7 @@
#include "fileio.h"
#include "macro.h"
#include "parse-util.h"
#include "process-util.h"
#include "string-util.h"
#include "time-util.h"
+1
View 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"
+1
View File
@@ -18,6 +18,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <net/ethernet.h>
#include <stdio.h>
#include <sys/types.h>
+1
View 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"
-2
View File
@@ -4,8 +4,6 @@
* Copyright 2000, 2005 Red Hat, Inc.
*/
#include <stdlib.h>
#include "gunicode.h"
#define unichar uint32_t
+2
View 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) {
+1
View File
@@ -21,6 +21,7 @@
***/
#include <stdbool.h>
#include <stdio.h>
#include "macro.h"
+1
View File
@@ -18,6 +18,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <unistd.h>
#include "alloc-util.h"
+33 -3
View File
@@ -54,6 +54,7 @@
#include "syslog-util.h"
#include "terminal-util.h"
#include "time-util.h"
#include "utf8.h"
#include "util.h"
#define SNDBUF_SIZE (8*1024*1024)
@@ -1226,10 +1227,12 @@ static const char *const log_target_table[_LOG_TARGET_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(log_target, LogTarget);
void log_received_signal(int level, const struct signalfd_siginfo *si) {
if (si->ssi_pid > 0) {
assert(si);
if (pid_is_valid(si->ssi_pid)) {
_cleanup_free_ char *p = NULL;
get_process_comm(si->ssi_pid, &p);
(void) get_process_comm(si->ssi_pid, &p);
log_full(level,
"Received SIG%s from PID %"PRIu32" (%s).",
@@ -1239,7 +1242,6 @@ void log_received_signal(int level, const struct signalfd_siginfo *si) {
log_full(level,
"Received SIG%s.",
signal_to_string(si->ssi_signo));
}
int log_syntax_internal(
@@ -1289,6 +1291,27 @@ int log_syntax_internal(
NULL);
}
int log_syntax_invalid_utf8_internal(
const char *unit,
int level,
const char *config_file,
unsigned config_line,
const char *file,
int line,
const char *func,
const char *rvalue) {
_cleanup_free_ char *p = NULL;
if (rvalue)
p = utf8_escape_invalid(rvalue);
log_syntax_internal(unit, level, config_file, config_line, 0, file, line, func,
"String is not UTF-8 clean, ignoring assignment: %s", strna(p));
return -EINVAL;
}
void log_set_upgrade_syslog_to_journal(bool b) {
upgrade_syslog_to_journal = b;
}
@@ -1300,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;
}
+25 -18
View File
@@ -20,18 +20,16 @@
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,
@@ -194,7 +192,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! */
@@ -240,9 +238,9 @@ void log_assert_failed_return_realm(
/* Logging with level */
#define log_full_errno_realm(realm, level, error, ...) \
({ \
int _level = (level), _e = (error); \
(log_get_max_level_realm((realm)) >= LOG_PRI(_level)) \
? log_internal_realm(LOG_REALM_PLUS_LEVEL((realm), _level), _e, \
int _level = (level), _e = (error), _realm = (realm); \
(log_get_max_level_realm(_realm) >= LOG_PRI(_level)) \
? log_internal_realm(LOG_REALM_PLUS_LEVEL(_realm, _level), _e, \
__FILE__, __LINE__, __func__, __VA_ARGS__) \
: -abs(_e); \
})
@@ -252,13 +250,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__)
@@ -266,7 +266,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__)
@@ -317,6 +317,16 @@ int log_syntax_internal(
const char *func,
const char *format, ...) _printf_(9, 10);
int log_syntax_invalid_utf8_internal(
const char *unit,
int level,
const char *config_file,
unsigned config_line,
const char *file,
int line,
const char *func,
const char *rvalue);
#define log_syntax(unit, level, config_file, config_line, error, ...) \
({ \
int _level = (level), _e = (error); \
@@ -328,12 +338,9 @@ int log_syntax_internal(
#define log_syntax_invalid_utf8(unit, level, config_file, config_line, rvalue) \
({ \
int _level = (level); \
if (log_get_max_level() >= LOG_PRI(_level)) { \
_cleanup_free_ char *_p = NULL; \
_p = utf8_escape_invalid(rvalue); \
log_syntax_internal(unit, _level, config_file, config_line, 0, __FILE__, __LINE__, __func__, \
"String is not UTF-8 clean, ignoring assignment: %s", strna(_p)); \
} \
(log_get_max_level() >= LOG_PRI(_level)) \
? log_syntax_invalid_utf8_internal(unit, _level, config_file, config_line, __FILE__, __LINE__, __func__, rvalue) \
: -EINVAL; \
})
#define DEBUG_LOGGING _unlikely_(log_get_max_level() >= LOG_DEBUG)
+1
View File
@@ -21,6 +21,7 @@
***/
#include <alloca.h>
#include <errno.h>
#include <sched.h>
#include <signal.h>
#include <stdbool.h>
+4 -3
View File
@@ -21,11 +21,12 @@
#include <elf.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/time.h>
#include <linux/random.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#if HAVE_SYS_AUXV_H
# include <sys/auxv.h>
+1
View File
@@ -19,6 +19,7 @@
***/
#include <errno.h>
#include <stdio.h>
#include "alloc-util.h"
#include "extract-word.h"
+1
View 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"
+3 -2
View File
@@ -21,10 +21,11 @@
#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"
+1
View 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"
+2
View File
@@ -22,10 +22,12 @@
#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"