utils: use nm_utils_strsplit_set_full() in nm_utils_proc_cmdline_split()

We should handle kernel command line like systemd does, with its
ConditionKernelCommandLine= setting.

For example, it tokenizes words between various white space characters,
not only space. Use nm_utils_strsplit_set_full() for that.

Note that we currently don't yet have a tokenizer that supports
quotation, like systemd does. We should extend
nm_utils_strsplit_set_full() for that.
This commit is contained in:
Thomas Haller
2020-03-24 20:43:29 +01:00
parent 999c569585
commit f2fd1614f5

View File

@@ -2768,17 +2768,25 @@ again:
const char *const* const char *const*
nm_utils_proc_cmdline_split (void) nm_utils_proc_cmdline_split (void)
{ {
static const char *const* volatile proc_cmdline_cached = NULL; static const char *const*volatile proc_cmdline_cached = NULL;
const char *const* proc_cmdline; const char *const*proc_cmdline;
again: again:
proc_cmdline = g_atomic_pointer_get (&proc_cmdline_cached); proc_cmdline = g_atomic_pointer_get (&proc_cmdline_cached);
if (G_UNLIKELY (!proc_cmdline)) { if (G_UNLIKELY (!proc_cmdline)) {
const char *proc_cl_str = nm_utils_proc_cmdline(); gs_free const char **split = NULL;
proc_cmdline = (const char *const*) g_strsplit (proc_cl_str, " ", -1);
/* 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)) if (!g_atomic_pointer_compare_and_exchange (&proc_cmdline_cached, NULL, proc_cmdline))
goto again; goto again;
g_steal_pointer (&split);
} }
return proc_cmdline; return proc_cmdline;