all/systemd: reformat ./{shared,src}/systemd/ with new clang-format style

./contrib/scripts/nm-code-format.sh -i
This commit is contained in:
Thomas Haller
2020-09-28 19:57:20 +02:00
parent 8435deecfa
commit 2bc3588c1d
12 changed files with 332 additions and 309 deletions

View File

@@ -10,31 +10,27 @@
/*****************************************************************************/
gboolean
_nm_log_enabled_impl (gboolean mt_require_locking,
NMLogLevel level,
NMLogDomain domain)
_nm_log_enabled_impl(gboolean mt_require_locking, NMLogLevel level, NMLogDomain domain)
{
return FALSE;
return FALSE;
}
void
_nm_log_impl (const char *file,
guint line,
const char *func,
gboolean mt_require_locking,
NMLogLevel level,
NMLogDomain domain,
int error,
const char *ifname,
const char *con_uuid,
const char *fmt,
...)
{
}
_nm_log_impl(const char *file,
guint line,
const char *func,
gboolean mt_require_locking,
NMLogLevel level,
NMLogDomain domain,
int error,
const char *ifname,
const char *con_uuid,
const char *fmt,
...)
{}
void
_nm_utils_monotonic_timestamp_initialized (const struct timespec *tp,
gint64 offset_sec,
gboolean is_boottime)
{
}
_nm_utils_monotonic_timestamp_initialized(const struct timespec *tp,
gint64 offset_sec,
gboolean is_boottime)
{}

View File

@@ -22,32 +22,31 @@ const bool mempool_use_allowed = true;
/*****************************************************************************/
gboolean
nm_sd_utils_path_equal (const char *a, const char *b)
nm_sd_utils_path_equal(const char *a, const char *b)
{
return path_equal (a, b);
return path_equal(a, b);
}
char *
nm_sd_utils_path_simplify (char *path, gboolean kill_dots)
nm_sd_utils_path_simplify(char *path, gboolean kill_dots)
{
return path_simplify (path, kill_dots);
return path_simplify(path, kill_dots);
}
const char *
nm_sd_utils_path_startswith (const char *path, const char *prefix)
nm_sd_utils_path_startswith(const char *path, const char *prefix)
{
return path_startswith (path, prefix);
return path_startswith(path, prefix);
}
/*****************************************************************************/
int
nm_sd_utils_unbase64char (char ch, gboolean accept_padding_equal)
nm_sd_utils_unbase64char(char ch, gboolean accept_padding_equal)
{
if ( ch == '='
&& accept_padding_equal)
return G_MAXINT;
return unbase64char (ch);
if (ch == '=' && accept_padding_equal)
return G_MAXINT;
return unbase64char(ch);
}
/**
@@ -69,60 +68,54 @@ nm_sd_utils_unbase64char (char ch, gboolean accept_padding_equal)
* function fail.
*/
int
nm_sd_utils_unbase64mem (const char *p,
size_t l,
gboolean secure,
guint8 **mem,
size_t *len)
nm_sd_utils_unbase64mem(const char *p, size_t l, gboolean secure, guint8 **mem, size_t *len)
{
return unbase64mem_full (p, l, secure, (void **) mem, len);
return unbase64mem_full(p, l, secure, (void **) mem, len);
}
int nm_sd_dns_name_to_wire_format (const char *domain,
guint8 *buffer,
size_t len,
gboolean canonical)
int
nm_sd_dns_name_to_wire_format(const char *domain, guint8 *buffer, size_t len, gboolean canonical)
{
return dns_name_to_wire_format (domain, buffer, len, canonical);
return dns_name_to_wire_format(domain, buffer, len, canonical);
}
int nm_sd_dns_name_is_valid (const char *s)
int
nm_sd_dns_name_is_valid(const char *s)
{
return dns_name_is_valid (s);
return dns_name_is_valid(s);
}
gboolean nm_sd_hostname_is_valid (const char *s, bool allow_trailing_dot)
gboolean
nm_sd_hostname_is_valid(const char *s, bool allow_trailing_dot)
{
return hostname_is_valid (s, allow_trailing_dot);
return hostname_is_valid(s, allow_trailing_dot);
}
/*****************************************************************************/
static gboolean
_http_url_is_valid (const char *url, gboolean only_https)
_http_url_is_valid(const char *url, gboolean only_https)
{
if ( !url
|| !url[0])
return FALSE;
if (!url || !url[0])
return FALSE;
if ( !only_https
&& NM_STR_HAS_PREFIX (url, "http://"))
url += NM_STRLEN ("http://");
else if (NM_STR_HAS_PREFIX (url, "https://"))
url += NM_STRLEN ("https://");
else
return FALSE;
if (!only_https && NM_STR_HAS_PREFIX(url, "http://"))
url += NM_STRLEN("http://");
else if (NM_STR_HAS_PREFIX(url, "https://"))
url += NM_STRLEN("https://");
else
return FALSE;
if (!url[0])
return FALSE;
if (!url[0])
return FALSE;
return !NM_STRCHAR_ANY (url, ch, (guchar) ch >= 128u);
return !NM_STRCHAR_ANY(url, ch, (guchar) ch >= 128u);
}
gboolean
nm_sd_http_url_is_valid_https (const char *url)
nm_sd_http_url_is_valid_https(const char *url)
{
/* We use this function to verify connection:mud-url property, it must thus
/* We use this function to verify connection:mud-url property, it must thus
* not change behavior.
*
* Note that sd_dhcp_client_set_mud_url() and sd_dhcp6_client_set_request_mud_url()
@@ -134,46 +127,46 @@ nm_sd_http_url_is_valid_https (const char *url)
*
* We only must make sure that this is also correct in the future, when we
* re-import systemd code. */
nm_assert (_http_url_is_valid (url, FALSE) == http_url_is_valid (url));
return _http_url_is_valid (url, TRUE);
nm_assert(_http_url_is_valid(url, FALSE) == http_url_is_valid(url));
return _http_url_is_valid(url, TRUE);
}
/*****************************************************************************/
int
nmtst_systemd_extract_first_word_all (const char *str, char ***out_strv)
nmtst_systemd_extract_first_word_all(const char *str, char ***out_strv)
{
gs_unref_ptrarray GPtrArray *arr = NULL;
gs_unref_ptrarray GPtrArray *arr = NULL;
/* we implement a str split function to parse `/proc/cmdline`. This
/* we implement a str split function to parse `/proc/cmdline`. This
* code should behave like systemd, which uses extract_first_word()
* for that.
*
* As we want to unit-test our implementation to match systemd,
* expose this function for testing. */
g_assert (out_strv);
g_assert (!*out_strv);
g_assert(out_strv);
g_assert(!*out_strv);
if (!str)
return 0;
if (!str)
return 0;
arr = g_ptr_array_new_with_free_func (g_free);
arr = g_ptr_array_new_with_free_func(g_free);
for (;;) {
gs_free char *word = NULL;
int r;
for (;;) {
gs_free char *word = NULL;
int r;
r = extract_first_word (&str, &word, NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX);
if (r < 0)
return r;
if (r == 0)
break;
g_ptr_array_add (arr, g_steal_pointer (&word));
}
r = extract_first_word(&str, &word, NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX);
if (r < 0)
return r;
if (r == 0)
break;
g_ptr_array_add(arr, g_steal_pointer(&word));
}
g_ptr_array_add (arr, NULL);
g_ptr_array_add(arr, NULL);
*out_strv = (char **) g_ptr_array_free (g_steal_pointer (&arr), FALSE);
return 1;
*out_strv = (char **) g_ptr_array_free(g_steal_pointer(&arr), FALSE);
return 1;
}

View File

@@ -8,38 +8,32 @@
/*****************************************************************************/
gboolean nm_sd_utils_path_equal (const char *a, const char *b);
gboolean nm_sd_utils_path_equal(const char *a, const char *b);
char *nm_sd_utils_path_simplify (char *path, gboolean kill_dots);
char *nm_sd_utils_path_simplify(char *path, gboolean kill_dots);
const char *nm_sd_utils_path_startswith (const char *path, const char *prefix);
const char *nm_sd_utils_path_startswith(const char *path, const char *prefix);
/*****************************************************************************/
int nm_sd_utils_unbase64char (char ch, gboolean accept_padding_equal);
int nm_sd_utils_unbase64char(char ch, gboolean accept_padding_equal);
int nm_sd_utils_unbase64mem (const char *p,
size_t l,
gboolean secure,
guint8 **mem,
size_t *len);
int nm_sd_utils_unbase64mem(const char *p, size_t l, gboolean secure, guint8 **mem, size_t *len);
/*****************************************************************************/
int nm_sd_dns_name_to_wire_format (const char *domain,
guint8 *buffer,
size_t len,
gboolean canonical);
int
nm_sd_dns_name_to_wire_format(const char *domain, guint8 *buffer, size_t len, gboolean canonical);
int nm_sd_dns_name_is_valid (const char *s);
int nm_sd_dns_name_is_valid(const char *s);
gboolean nm_sd_hostname_is_valid(const char *s, bool allow_trailing_dot);
/*****************************************************************************/
gboolean nm_sd_http_url_is_valid_https (const char *url);
gboolean nm_sd_http_url_is_valid_https(const char *url);
/*****************************************************************************/
int nmtst_systemd_extract_first_word_all (const char *str, char ***out_strv);
int nmtst_systemd_extract_first_word_all(const char *str, char ***out_strv);
#endif /* __NM_SD_UTILS_SHARED_H__ */

View File

@@ -13,7 +13,7 @@
/*****************************************************************************/
/* strerror() is not thread-safe. Patch systemd-sources via a define. */
#define strerror(errsv) nm_strerror_native (errsv)
#define strerror(errsv) nm_strerror_native(errsv)
/*****************************************************************************/
@@ -29,49 +29,91 @@
/*****************************************************************************/
static inline int
_nm_log_get_max_level_realm (void)
_nm_log_get_max_level_realm(void)
{
/* inline function, to avoid coverity warning about constant expression. */
return 7 /* LOG_DEBUG */;
/* 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_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_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(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_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; \
})
#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
#define VALGRIND 0
#endif
#define ENABLE_DEBUG_HASHMAP 0
@@ -83,68 +125,71 @@ G_STMT_START { \
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_SYSTEMD
#include <sys/syscall.h>
#include <sys/ioctl.h>
#include <sys/syscall.h>
#include <sys/ioctl.h>
#define ENABLE_GSHADOW FALSE
#define ENABLE_GSHADOW FALSE
#define HAVE_SECCOMP 0
#define HAVE_SECCOMP 0
/*****************************************************************************/
/* systemd cannot be compiled with "-Wdeclaration-after-statement". In particular
* in combination with assert_cc(). */
NM_PRAGMA_WARNING_DISABLE ("-Wdeclaration-after-statement")
NM_PRAGMA_WARNING_DISABLE("-Wdeclaration-after-statement")
/*****************************************************************************/
static inline pid_t
raw_getpid (void) {
#if defined(__alpha__)
return (pid_t) syscall (__NR_getxpid);
#else
return (pid_t) syscall (__NR_getpid);
#endif
raw_getpid(void)
{
#if defined(__alpha__)
return (pid_t) syscall(__NR_getxpid);
#else
return (pid_t) syscall(__NR_getpid);
#endif
}
static inline pid_t _nm_gettid(void) {
return (pid_t) syscall(SYS_gettid);
static inline pid_t
_nm_gettid(void)
{
return (pid_t) syscall(SYS_gettid);
}
#define gettid() _nm_gettid ()
#define gettid() _nm_gettid()
/* we build with C11 and thus <uchar.h> provides char32_t,char16_t. */
#define HAVE_CHAR32_T 1
#define HAVE_CHAR16_T 1
/* we build with C11 and thus <uchar.h> provides char32_t,char16_t. */
#define HAVE_CHAR32_T 1
#define HAVE_CHAR16_T 1
#if defined(HAVE_DECL_REALLOCARRAY) && HAVE_DECL_REALLOCARRAY == 1
#define HAVE_REALLOCARRAY 1
#else
#define HAVE_REALLOCARRAY 0
#endif
#if defined(HAVE_DECL_REALLOCARRAY) && HAVE_DECL_REALLOCARRAY == 1
#define HAVE_REALLOCARRAY 1
#else
#define HAVE_REALLOCARRAY 0
#endif
#if defined(HAVE_DECL_EXPLICIT_BZERO) && HAVE_DECL_EXPLICIT_BZERO == 1
#define HAVE_EXPLICIT_BZERO 1
#else
#define HAVE_EXPLICIT_BZERO 0
#endif
#if defined(HAVE_DECL_EXPLICIT_BZERO) && HAVE_DECL_EXPLICIT_BZERO == 1
#define HAVE_EXPLICIT_BZERO 1
#else
#define HAVE_EXPLICIT_BZERO 0
#endif
#if defined(HAVE_DECL_PIDFD_OPEN) && HAVE_DECL_PIDFD_OPEN == 1
#define HAVE_PIDFD_OPEN 1
#else
#define HAVE_PIDFD_OPEN 0
#endif
#if defined(HAVE_DECL_PIDFD_OPEN) && HAVE_DECL_PIDFD_OPEN == 1
#define HAVE_PIDFD_OPEN 1
#else
#define HAVE_PIDFD_OPEN 0
#endif
#if defined(HAVE_DECL_PIDFD_SEND_SIGNAL) && HAVE_DECL_PIDFD_SEND_SIGNAL == 1
#define HAVE_PIDFD_SEND_SIGNAL 1
#else
#define HAVE_PIDFD_SEND_SIGNAL 0
#endif
#if defined(HAVE_DECL_PIDFD_SEND_SIGNAL) && HAVE_DECL_PIDFD_SEND_SIGNAL == 1
#define HAVE_PIDFD_SEND_SIGNAL 1
#else
#define HAVE_PIDFD_SEND_SIGNAL 0
#endif
#if defined(HAVE_DECL_RT_SIGQUEUEINFO) && HAVE_DECL_RT_SIGQUEUEINFO == 1
#define HAVE_RT_SIGQUEUEINFO 1
#else
#define HAVE_RT_SIGQUEUEINFO 0
#endif
#if defined(HAVE_DECL_RT_SIGQUEUEINFO) && HAVE_DECL_RT_SIGQUEUEINFO == 1
#define HAVE_RT_SIGQUEUEINFO 1
#else
#define HAVE_RT_SIGQUEUEINFO 0
#endif
#endif /* (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_SYSTEMD */