core: merge branch 'af/settings-add-matches' (part 1)

https://gitlab.freedesktop.org/afreof/NetworkManager/-/tree/af/settings-add-matches
This commit is contained in:
Thomas Haller 2020-03-24 20:59:51 +01:00
commit 1704507c49
3 changed files with 61 additions and 1 deletions

View file

@ -1479,7 +1479,12 @@ _NM_BACKPORT_SYMBOL_IMPL(version, return_type, func, _##func##_##version, args_t
/*****************************************************************************/
/* mirrors g_ascii_isspace() and what we consider spaces in general. */
#define NM_ASCII_SPACES "\t\n\f\r "
#define NM_ASCII_SPACES " \n\t\r\f"
/* Like NM_ASCII_SPACES, but without "\f" (0x0c, Formfeed Page Break).
* This is what for example systemd calls WHITESPACE and what it uses to tokenize
* the kernel command line. */
#define NM_ASCII_WHITESPACES " \n\t\r"
#define nm_str_skip_leading_spaces(str) \
({ \

View file

@ -2741,6 +2741,59 @@ nm_utils_boot_id_bin (void)
/*****************************************************************************/
const char *
nm_utils_proc_cmdline (void)
{
static const char *volatile proc_cmdline_cached = NULL;
const char *proc_cmdline;
again:
proc_cmdline = g_atomic_pointer_get (&proc_cmdline_cached);
if (G_UNLIKELY (!proc_cmdline)) {
gs_free char *str = NULL;
g_file_get_contents ("/proc/cmdline", &str, NULL, NULL);
str = nm_str_realloc (str);
proc_cmdline = str ?: "";
if (!g_atomic_pointer_compare_and_exchange (&proc_cmdline_cached, NULL, proc_cmdline))
goto again;
g_steal_pointer (&str);
}
return proc_cmdline;
}
const char *const*
nm_utils_proc_cmdline_split (void)
{
static const char *const*volatile proc_cmdline_cached = NULL;
const char *const*proc_cmdline;
again:
proc_cmdline = g_atomic_pointer_get (&proc_cmdline_cached);
if (G_UNLIKELY (!proc_cmdline)) {
gs_free const char **split = NULL;
/* TODO: support quotation, like systemd's proc_cmdline_extract_first().
* For that, add a new NMUtilsStrsplitSetFlags flag. */
split = nm_utils_strsplit_set_full (nm_utils_proc_cmdline (),
NM_ASCII_WHITESPACES,
NM_UTILS_STRSPLIT_SET_FLAGS_NONE);
proc_cmdline = split
?: NM_PTRARRAY_EMPTY (const char *);
if (!g_atomic_pointer_compare_and_exchange (&proc_cmdline_cached, NULL, proc_cmdline))
goto again;
g_steal_pointer (&split);
}
return proc_cmdline;
}
/*****************************************************************************/
/**
* nm_utils_arp_type_detect_from_hwaddrlen:
* @hwaddr_len: the length of the hardware address in bytes.

View file

@ -267,6 +267,8 @@ gboolean nm_utils_machine_id_is_fake (void);
const char *nm_utils_boot_id_str (void);
const struct _NMUuid *nm_utils_boot_id_bin (void);
const char *nm_utils_proc_cmdline (void);
const char *const*nm_utils_proc_cmdline_split (void);
gboolean nm_utils_host_id_get (const guint8 **out_host_id,
gsize *out_host_id_len);