diff --git a/Makefile.am b/Makefile.am index 6ba369a090..1e804dacfe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2087,6 +2087,7 @@ libsystemd_cppflags = \ -I$(srcdir)/src/libnm-systemd-shared/ \ -I$(srcdir)/src/libnm-systemd-shared/sd-adapt-shared \ -I$(srcdir)/src/libnm-systemd-shared/src/basic \ + -I$(srcdir)/src/libnm-systemd-shared/src/fundamental \ -I$(srcdir)/src/libnm-systemd-shared/src/shared \ $(LIBSYSTEMD_NM_CFLAGS) \ $(GLIB_CFLAGS) \ @@ -2123,13 +2124,16 @@ src_libnm_systemd_shared_libnm_systemd_shared_la_SOURCES = \ src/libnm-systemd-shared/sd-adapt-shared/missing_magic.h \ src/libnm-systemd-shared/sd-adapt-shared/missing_network.h \ src/libnm-systemd-shared/sd-adapt-shared/missing_sched.h \ + src/libnm-systemd-shared/sd-adapt-shared/missing_syscall_def.h \ src/libnm-systemd-shared/sd-adapt-shared/missing_timerfd.h \ src/libnm-systemd-shared/sd-adapt-shared/mkdir.h \ src/libnm-systemd-shared/sd-adapt-shared/namespace-util.h \ src/libnm-systemd-shared/sd-adapt-shared/nm-sd-adapt-shared.h \ src/libnm-systemd-shared/sd-adapt-shared/nulstr-util.h \ + src/libnm-systemd-shared/sd-adapt-shared/os-util.h \ src/libnm-systemd-shared/sd-adapt-shared/raw-clone.h \ src/libnm-systemd-shared/sd-adapt-shared/rlimit-util.h \ + src/libnm-systemd-shared/sd-adapt-shared/sysctl-util.h \ src/libnm-systemd-shared/sd-adapt-shared/terminal-util.h \ src/libnm-systemd-shared/sd-adapt-shared/unaligned.h \ src/libnm-systemd-shared/sd-adapt-shared/user-util.h \ @@ -2138,6 +2142,7 @@ src_libnm_systemd_shared_libnm_systemd_shared_la_SOURCES = \ src/libnm-systemd-shared/src/basic/alloc-util.h \ src/libnm-systemd-shared/src/basic/async.h \ src/libnm-systemd-shared/src/basic/cgroup-util.h \ + src/libnm-systemd-shared/src/basic/dns-def.h \ src/libnm-systemd-shared/src/basic/env-file.c \ src/libnm-systemd-shared/src/basic/env-file.h \ src/libnm-systemd-shared/src/basic/env-util.c \ @@ -2182,6 +2187,8 @@ src_libnm_systemd_shared_libnm_systemd_shared_la_SOURCES = \ src/libnm-systemd-shared/src/basic/missing_stat.h \ src/libnm-systemd-shared/src/basic/missing_syscall.h \ src/libnm-systemd-shared/src/basic/missing_type.h \ + src/libnm-systemd-shared/src/basic/ordered-set.c \ + src/libnm-systemd-shared/src/basic/ordered-set.h \ src/libnm-systemd-shared/src/basic/parse-util.c \ src/libnm-systemd-shared/src/basic/parse-util.h \ src/libnm-systemd-shared/src/basic/path-util.c \ @@ -2222,6 +2229,10 @@ src_libnm_systemd_shared_libnm_systemd_shared_la_SOURCES = \ src/libnm-systemd-shared/src/basic/utf8.h \ src/libnm-systemd-shared/src/basic/util.c \ src/libnm-systemd-shared/src/basic/util.h \ + src/libnm-systemd-shared/src/fundamental/macro-fundamental.h \ + src/libnm-systemd-shared/src/fundamental/string-util-fundamental.c \ + src/libnm-systemd-shared/src/fundamental/string-util-fundamental.h \ + src/libnm-systemd-shared/src/fundamental/type.h \ src/libnm-systemd-shared/src/shared/dns-domain.c \ src/libnm-systemd-shared/src/shared/dns-domain.h \ src/libnm-systemd-shared/src/shared/log-link.h \ diff --git a/src/core/devices/nm-lldp-listener.c b/src/core/devices/nm-lldp-listener.c index 808c1e2680..5cf99484f1 100644 --- a/src/core/devices/nm-lldp-listener.c +++ b/src/core/devices/nm-lldp-listener.c @@ -903,7 +903,7 @@ handle_changed: } static void -lldp_event_handler(sd_lldp *lldp, sd_lldp_event event, sd_lldp_neighbor *n, void *userdata) +lldp_event_handler(sd_lldp *lldp, sd_lldp_event_t event, sd_lldp_neighbor *n, void *userdata) { process_lldp_neighbor( userdata, diff --git a/src/core/systemd/src/libsystemd/sd-event/sd-event.c b/src/core/systemd/src/libsystemd/sd-event/sd-event.c index ecbbf22666..1db618d05c 100644 --- a/src/core/systemd/src/libsystemd/sd-event/sd-event.c +++ b/src/core/systemd/src/libsystemd/sd-event/sd-event.c @@ -3175,7 +3175,7 @@ static int process_child(sd_event *e, int64_t threshold, int64_t *ret_min_priori zero(s->child.siginfo); if (waitid(P_PID, s->child.pid, &s->child.siginfo, WNOHANG | (s->child.options & WEXITED ? WNOWAIT : 0) | s->child.options) < 0) - return -errno; + return negative_errno(); if (s->child.siginfo.si_pid != 0) { bool zombie = IN_SET(s->child.siginfo.si_code, CLD_EXITED, CLD_KILLED, CLD_DUMPED); diff --git a/src/libnm-systemd-shared/meson.build b/src/libnm-systemd-shared/meson.build index 42d6e5f04b..68daa20e0a 100644 --- a/src/libnm-systemd-shared/meson.build +++ b/src/libnm-systemd-shared/meson.build @@ -22,6 +22,7 @@ libnm_systemd_shared = static_library( 'src/basic/io-util.c', 'src/basic/memory-util.c', 'src/basic/mempool.c', + 'src/basic/ordered-set.c', 'src/basic/parse-util.c', 'src/basic/path-util.c', 'src/basic/prioq.c', @@ -39,6 +40,7 @@ libnm_systemd_shared = static_library( 'src/basic/tmpfile-util.c', 'src/basic/utf8.c', 'src/basic/util.c', + 'src/fundamental/string-util-fundamental.c', 'src/shared/dns-domain.c', 'src/shared/web-util.c', ), @@ -46,6 +48,7 @@ libnm_systemd_shared = static_library( include_directories( 'sd-adapt-shared', 'src/basic', + 'src/fundamental', 'src/shared', ), top_inc, @@ -58,6 +61,7 @@ libnm_systemd_shared_dep_inc = declare_dependency( include_directories: include_directories( 'sd-adapt-shared', 'src/basic', + 'src/fundamental', 'src/shared', ), ) diff --git a/src/libnm-systemd-shared/sd-adapt-shared/dhcp-server-internal.h b/src/libnm-systemd-shared/sd-adapt-shared/dhcp-server-internal.h index 637892c2d6..953416b692 100644 --- a/src/libnm-systemd-shared/sd-adapt-shared/dhcp-server-internal.h +++ b/src/libnm-systemd-shared/sd-adapt-shared/dhcp-server-internal.h @@ -1,3 +1,5 @@ #pragma once /* dummy header */ + +#include "ordered-set.h" diff --git a/src/libnm-systemd-shared/sd-adapt-shared/missing_syscall_def.h b/src/libnm-systemd-shared/sd-adapt-shared/missing_syscall_def.h new file mode 100644 index 0000000000..637892c2d6 --- /dev/null +++ b/src/libnm-systemd-shared/sd-adapt-shared/missing_syscall_def.h @@ -0,0 +1,3 @@ +#pragma once + +/* dummy header */ diff --git a/src/libnm-systemd-shared/sd-adapt-shared/nm-sd-adapt-shared.h b/src/libnm-systemd-shared/sd-adapt-shared/nm-sd-adapt-shared.h index 2fc8b83176..fd8352ab69 100644 --- a/src/libnm-systemd-shared/sd-adapt-shared/nm-sd-adapt-shared.h +++ b/src/libnm-systemd-shared/sd-adapt-shared/nm-sd-adapt-shared.h @@ -28,90 +28,6 @@ /*****************************************************************************/ -static inline int -_nm_log_get_max_level_realm(void) -{ - /* inline function, to avoid coverity warning about constant expression. */ - return 7 /* LOG_DEBUG */; -} -#define log_get_max_level_realm(realm) _nm_log_get_max_level_realm() - -#define log_internal_realm(level, error, file, line, func, format, ...) \ - ({ \ - const int _nm_e = (error); \ - const NMLogLevel _nm_l = nm_log_level_from_syslog(LOG_PRI(level)); \ - \ - if (_nm_log_enabled_impl(!(NM_THREAD_SAFE_ON_MAIN_THREAD), _nm_l, LOGD_SYSTEMD)) { \ - const char *_nm_location = strrchr(("" file), '/'); \ - \ - _nm_log_impl(_nm_location ? _nm_location + 1 : ("" file), \ - (line), \ - (func), \ - !(NM_THREAD_SAFE_ON_MAIN_THREAD), \ - _nm_l, \ - LOGD_SYSTEMD, \ - _nm_e, \ - NULL, \ - NULL, \ - ("%s" format), \ - "libsystemd: ", \ - ##__VA_ARGS__); \ - } \ - (_nm_e > 0 ? -_nm_e : _nm_e); \ - }) - -#define log_assert_failed(text, file, line, func) \ - G_STMT_START \ - { \ - log_internal(LOG_CRIT, \ - 0, \ - file, \ - line, \ - func, \ - "Assertion '%s' failed at %s:%u, function %s(). Aborting.", \ - text, \ - file, \ - line, \ - func); \ - g_assert_not_reached(); \ - } \ - G_STMT_END - -#define log_assert_failed_unreachable(text, file, line, func) \ - G_STMT_START \ - { \ - log_internal(LOG_CRIT, \ - 0, \ - file, \ - line, \ - func, \ - "Code should not be reached '%s' at %s:%u, function %s(). Aborting.", \ - text, \ - file, \ - line, \ - func); \ - g_assert_not_reached(); \ - } \ - G_STMT_END - -#define log_assert_failed_return(text, file, line, func) \ - ({ \ - log_internal(LOG_DEBUG, \ - 0, \ - file, \ - line, \ - func, \ - "Assertion '%s' failed at %s:%u, function %s(). Ignoring.", \ - text, \ - file, \ - line, \ - func); \ - g_return_if_fail_warning(G_LOG_DOMAIN, G_STRFUNC, text); \ - (void) 0; \ - }) - -/*****************************************************************************/ - #ifndef VALGRIND #define VALGRIND 0 #endif @@ -133,6 +49,8 @@ _nm_log_get_max_level_realm(void) #define HAVE_SECCOMP 0 + #define LOG_TRACE 0 + /*****************************************************************************/ /* systemd cannot be compiled with "-Wdeclaration-after-statement". In particular @@ -196,6 +114,8 @@ _nm_gettid(void) #define HAVE_RT_SIGQUEUEINFO 0 #endif + #define HAVE_LINUX_TIME_TYPES_H 0 + #ifndef __COMPAR_FN_T #define __COMPAR_FN_T typedef int (*__compar_fn_t)(const void *, const void *); diff --git a/src/libnm-systemd-shared/sd-adapt-shared/os-util.h b/src/libnm-systemd-shared/sd-adapt-shared/os-util.h new file mode 100644 index 0000000000..637892c2d6 --- /dev/null +++ b/src/libnm-systemd-shared/sd-adapt-shared/os-util.h @@ -0,0 +1,3 @@ +#pragma once + +/* dummy header */ diff --git a/src/libnm-systemd-shared/sd-adapt-shared/sysctl-util.h b/src/libnm-systemd-shared/sd-adapt-shared/sysctl-util.h new file mode 100644 index 0000000000..637892c2d6 --- /dev/null +++ b/src/libnm-systemd-shared/sd-adapt-shared/sysctl-util.h @@ -0,0 +1,3 @@ +#pragma once + +/* dummy header */ diff --git a/src/libnm-systemd-shared/src/basic/fs-util.c b/src/libnm-systemd-shared/src/basic/fs-util.c index a984468ebf..ff096852cf 100644 --- a/src/libnm-systemd-shared/src/basic/fs-util.c +++ b/src/libnm-systemd-shared/src/basic/fs-util.c @@ -1637,6 +1637,7 @@ int path_is_encrypted(const char *path) { return blockdev_is_encrypted(p, 10 /* safety net: maximum recursion depth */); } +#endif /* NM_IGNORED */ int conservative_renameat( int olddirfd, const char *oldpath, @@ -1728,4 +1729,3 @@ do_rename: return 1; } -#endif /* NM_IGNORED */ diff --git a/src/libnm-systemd-shared/src/basic/in-addr-util.c b/src/libnm-systemd-shared/src/basic/in-addr-util.c index 799920aa6c..00bdbfcc9a 100644 --- a/src/libnm-systemd-shared/src/basic/in-addr-util.c +++ b/src/libnm-systemd-shared/src/basic/in-addr-util.c @@ -216,6 +216,7 @@ int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen) return in_addr_prefix_nth(family, u, prefixlen, 1); } +#endif /* NM_IGNORED */ /* * Calculates the nth prefix of size prefixlen starting from the address denoted by u. @@ -295,6 +296,7 @@ int in_addr_prefix_nth(int family, union in_addr_union *u, unsigned prefixlen, u return -EAFNOSUPPORT; } +#if 0 /* NM_IGNORED */ int in_addr_random_prefix( int family, union in_addr_union *u, diff --git a/src/libnm-systemd-shared/src/basic/log.h b/src/libnm-systemd-shared/src/basic/log.h index 4fa9ba5731..bcb3d494a1 100644 --- a/src/libnm-systemd-shared/src/basic/log.h +++ b/src/libnm-systemd-shared/src/basic/log.h @@ -39,7 +39,15 @@ LogTarget log_get_target(void) _pure_; void log_set_max_level(int level); int log_set_max_level_from_string(const char *e); +#if 0 /* NM_IGNORED */ int log_get_max_level(void) _pure_; +#else /* NM_IGNORED */ +static inline int +log_get_max_level(void) +{ + return 7 /* LOG_DEBUG */; +} +#endif /* NM_IGNORED */ void log_set_facility(int facility); @@ -64,8 +72,9 @@ int log_show_tid_from_string(const char *e); #if 0 /* NM_IGNORED */ assert_cc(STRLEN(__FILE__) > STRLEN(RELATIVE_SOURCE_PATH) + 1); #define PROJECT_FILE (&__FILE__[STRLEN(RELATIVE_SOURCE_PATH) + 1]) -#endif /* NM_IGNORED */ +#else /* NM_IGNORED */ #define PROJECT_FILE __FILE__ +#endif /* NM_IGNORED */ int log_open(void); void log_close(void); @@ -85,7 +94,9 @@ int log_dispatch_internal( const char *extra, const char *extra_field, char *buffer); +#endif /* NM_IGNORED */ +#if 0 /* NM_IGNORED */ int log_internal( int level, int error, @@ -93,6 +104,30 @@ int log_internal( int line, const char *func, const char *format, ...) _printf_(6,7); +#else /* NM_IGNORED */ +#define log_internal(level, error, file, line, func, format, ...) \ + ({ \ + const int _nm_e = (error); \ + const NMLogLevel _nm_l = nm_log_level_from_syslog(LOG_PRI(level)); \ + \ + if (_nm_log_enabled_impl(!(NM_THREAD_SAFE_ON_MAIN_THREAD), _nm_l, LOGD_SYSTEMD)) { \ + const char *_nm_location = strrchr(("" file), '/'); \ + \ + _nm_log_impl(_nm_location ? _nm_location + 1 : ("" file), \ + (line), \ + (func), \ + !(NM_THREAD_SAFE_ON_MAIN_THREAD), \ + _nm_l, \ + LOGD_SYSTEMD, \ + _nm_e, \ + NULL, \ + NULL, \ + ("%s" format), \ + "libsystemd: ", \ + ##__VA_ARGS__); \ + } \ + (_nm_e > 0 ? -_nm_e : _nm_e); \ + }) #endif /* NM_IGNORED */ #if 0 /* NM_IGNORED */ @@ -117,7 +152,9 @@ int log_object_internalv( const char *extra, const char *format, va_list ap) _printf_(10,0); +#endif /* NM_IGNORED */ +#if 0 /* NM_IGNORED */ int log_object_internal( int level, int error, @@ -129,7 +166,35 @@ int log_object_internal( const char *extra_field, const char *extra, const char *format, ...) _printf_(10,11); +#else /* NM_IGNORED */ +#define log_object_internal(level, \ + error, \ + file, \ + line, \ + func, \ + object_field, \ + object, \ + extra_field, \ + extra, \ + format, \ + ...) \ + ({ \ + const char *const _object = (object); \ + \ + log_internal((level), \ + (error), \ + file, \ + (line), \ + (func), \ + "%s%s" format, \ + _object ?: "", \ + _object ? ": " : "", \ + ##__VA_ARGS__); \ + }) +#endif /* NM_IGNORED */ + +#if 0 /* NM_IGNORED */ int log_struct_internal( int level, int error, @@ -137,16 +202,18 @@ int log_struct_internal( int line, const char *func, const char *format, ...) _printf_(6,0) _sentinel_; +#endif /* NM_IGNORED */ +#if 0 /* NM_IGNORED */ int log_oom_internal( int level, const char *file, int line, const char *func); +#else /* NM_IGNORED */ +#define log_oom_internal(level, file, line, func) \ + log_internal(level, ENOMEM, file, line, func, "Out of memory.") #endif /* NM_IGNORED */ -#define log_oom_internal(realm, file, line, func) \ - log_internal_realm (LOG_REALM_PLUS_LEVEL (realm, LOG_ERR), \ - ENOMEM, file, line, func, "Out of memory.") #if 0 /* NM_IGNORED */ int log_format_iovec( @@ -175,26 +242,84 @@ int log_dump_internal( int line, const char *func, char *buffer); +#endif /* NM_IGNORED */ /* Logging for various assertions */ +#if 0 /* NM_IGNORED */ _noreturn_ void log_assert_failed( const char *text, const char *file, int line, const char *func); +#else /* NM_IGNORED */ +#define log_assert_failed(text, file, line, func) \ + G_STMT_START \ + { \ + log_internal(LOG_CRIT, \ + 0, \ + file, \ + line, \ + func, \ + "Assertion '%s' failed at %s:%u, function %s(). Aborting.", \ + text, \ + file, \ + line, \ + func); \ + g_assert_not_reached(); \ + } \ + G_STMT_END +#endif /* NM_IGNORED */ +#if 0 /* NM_IGNORED */ _noreturn_ void log_assert_failed_unreachable( const char *text, const char *file, int line, const char *func); +#else /* NM_IGNORED */ +#define log_assert_failed_unreachable(text, file, line, func) \ + G_STMT_START \ + { \ + log_internal(LOG_CRIT, \ + 0, \ + file, \ + line, \ + func, \ + "Code should not be reached '%s' at %s:%u, function %s(). Aborting.", \ + text, \ + file, \ + line, \ + func); \ + g_assert_not_reached(); \ + } \ + G_STMT_END +#endif /* NM_IGNORED */ +#if 0 /* NM_IGNORED */ void log_assert_failed_return( const char *text, const char *file, int line, const char *func); +#else /* NM_IGNORED */ +#define log_assert_failed_return(text, file, line, func) \ + ({ \ + log_internal(LOG_DEBUG, \ + 0, \ + file, \ + line, \ + func, \ + "Assertion '%s' failed at %s:%u, function %s(). Ignoring.", \ + text, \ + file, \ + line, \ + func); \ + g_return_if_fail_warning(G_LOG_DOMAIN, G_STRFUNC, text); \ + (void) 0; \ + }) +#endif /* NM_IGNORED */ +#if 0 /* NM_IGNORED */ #define log_dispatch(level, error, buffer) \ log_dispatch_internal(level, error, PROJECT_FILE, __LINE__, __func__, NULL, NULL, NULL, NULL, buffer) #endif /* NM_IGNORED */ @@ -284,9 +409,10 @@ int log_syntax_internal( int line, const char *func, const char *format, ...) _printf_(9, 10); -#endif /* NM_IGNORED */ +#else /* NM_IGNORED */ #define log_syntax_internal(unit, level, config_file, config_line, error, file, line, func, format, ...) \ - log_internal_realm((level), (error), file, (line), (func), "syntax[%s]: "format, (config_file), __VA_ARGS__) \ + log_internal((level), (error), file, (line), (func), "syntax[%s]: "format, (config_file), __VA_ARGS__) +#endif /* NM_IGNORED */ int log_syntax_invalid_utf8_internal( const char *unit, diff --git a/src/libnm-systemd-shared/src/basic/ordered-set.c b/src/libnm-systemd-shared/src/basic/ordered-set.c index 58fa8af1b7..db979864f5 100644 --- a/src/libnm-systemd-shared/src/basic/ordered-set.c +++ b/src/libnm-systemd-shared/src/basic/ordered-set.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "nm-sd-adapt-shared.h" + #include "fileio.h" #include "ordered-set.h" #include "strv.h" diff --git a/src/libnm-systemd-shared/src/basic/path-util.c b/src/libnm-systemd-shared/src/basic/path-util.c index 0597688f0e..cf1607a56c 100644 --- a/src/libnm-systemd-shared/src/basic/path-util.c +++ b/src/libnm-systemd-shared/src/basic/path-util.c @@ -781,6 +781,7 @@ char* dirname_malloc(const char *path) { return dir2; } +#endif /* NM_IGNORED */ const char *last_path_component(const char *path) { @@ -907,7 +908,6 @@ int path_extract_directory(const char *p, char **ret) { *ret = TAKE_PTR(a); return 0; } -#endif /* NM_IGNORED */ bool filename_is_valid(const char *p) { const char *e; diff --git a/src/libnm-systemd-shared/src/fundamental/string-util-fundamental.c b/src/libnm-systemd-shared/src/fundamental/string-util-fundamental.c index 9f14597fef..c1abae6c41 100644 --- a/src/libnm-systemd-shared/src/fundamental/string-util-fundamental.c +++ b/src/libnm-systemd-shared/src/fundamental/string-util-fundamental.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "nm-sd-adapt-shared.h" + #ifndef SD_BOOT #include