Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support kargs.d directories for default kargs (rebased) #2217

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile-tests.am
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ _installed_or_uninstalled_test_scripts = \
tests/test-admin-deploy-syslinux.sh \
tests/test-admin-deploy-2.sh \
tests/test-admin-deploy-karg.sh \
tests/test-admin-deploy-karg-default.sh \
tests/test-admin-deploy-switch.sh \
tests/test-admin-deploy-etcmerge-cornercases.sh \
tests/test-admin-deploy-uboot.sh \
Expand Down
56 changes: 49 additions & 7 deletions src/libostree/ostree-kernel-args.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "libglnx.h"
#include "otutil.h"

#include <ctype.h>
#include <string.h>

struct _OstreeKernelArgs {
Expand Down Expand Up @@ -652,6 +653,49 @@ ostree_kernel_args_append_proc_cmdline (OstreeKernelArgs *kargs,
return TRUE;
}

/* Parse a single KEY=VALUE pair (karg), from a space-separated string of
* kargs, args, which is modified in place to terminate parsed kargs. Spaces
* are protected by quotation marks ("") around the value. The parsed karg
* string is returned in out_arg. A pointer to the remaining string to parse
* is returned.
*
* Based on the implementation in the Linux kernel:
* https://github.com/torvalds/linux/blob/8a05452ca460b05c985eadc7b5a4f040f124463e/lib/cmdline.c#L204
*/
static char *
next_arg(char *args,
char** out_arg)
{
g_strchomp (args);
*out_arg = args;
gboolean in_quote = FALSE;
gboolean past_quote = FALSE;
gboolean past_equals = FALSE;
Comment on lines +672 to +673
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these variables here meant for handling errors if the input string (args) weren't formatted properly? Otherwise, if we can assume that args is formatted properly, these two variables seem unnecessary.

while (*args != '\0')
{
if (in_quote)
{
in_quote = *args != '\"';
past_quote = TRUE;
}
else
{
past_equals = *args == '=' || past_equals;
in_quote = past_equals && (*args == '\"') && !past_quote;
if (isspace(*args))
{
*args = '\0';
args++;
break;
}
}
if (*args == '\0')
break;
args++;
}
return args;
}

/**
* ostree_kernel_args_parse_append:
* @kargs: a OstreeKernelArgs instance
Expand All @@ -665,19 +709,17 @@ void
ostree_kernel_args_parse_append (OstreeKernelArgs *kargs,
const char *options)
{
char **args = NULL;
char **iter;

if (!options)
return;

args = g_strsplit (options, " ", -1);
for (iter = args; *iter; iter++)
g_autofree char *args = g_strdup (options);
char *args_ptr = args;
while (*args_ptr)
{
char *arg = *iter;
char *arg = NULL;
args_ptr = next_arg (args_ptr, &arg);
ostree_kernel_args_append (kargs, arg);
}
g_strfreev (args);
}

/**
Expand Down
Loading