forked from ostreedev/ostree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RFE: Add a hidden option to
ostree admin kargs edit-in-place
to
update all existing deployments in place Example: $ sudo ostree admin kargs edit-in-place --append-if-missing=rw See ostreedev#2617 This will not add duplicate key, if there is `TESTARG=VAL1` in the kernel arguments, `--append-if-missing=TESTARG=VAL2` will be ignored.
- Loading branch information
1 parent
b04c436
commit 3bc59a5
Showing
13 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright (C) 2015 Colin Walters <[email protected]> | ||
* Copyright (C) 2022 Huijing Hei <[email protected]> | ||
* | ||
* SPDX-License-Identifier: LGPL-2.0+ | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include "ot-main.h" | ||
#include "ot-admin-builtins.h" | ||
#include "ot-admin-functions.h" | ||
#include "ot-admin-kargs-builtins.h" | ||
#include "otutil.h" | ||
|
||
#include <glib/gi18n.h> | ||
|
||
static OstreeCommand admin_kargs_subcommands[] = { | ||
{ "edit-in-place", OSTREE_BUILTIN_FLAG_NO_REPO | OSTREE_BUILTIN_FLAG_HIDDEN, | ||
ot_admin_kargs_builtin_edit_in_place, | ||
"Set new kernel command line arguments in place (applies to all deployments by default)" }, | ||
{ NULL, 0, NULL, NULL } | ||
}; | ||
|
||
static GOptionContext * | ||
ostree_admin_kargs_option_context_new_with_commands (void) | ||
{ | ||
OstreeCommand *command = admin_kargs_subcommands; | ||
GOptionContext *context = g_option_context_new ("COMMAND"); | ||
|
||
g_autoptr(GString) summary = g_string_new ("Builtin \"admin kargs\" Commands:"); | ||
|
||
while (command->name != NULL) | ||
{ | ||
if ((command->flags & OSTREE_BUILTIN_FLAG_HIDDEN) == 0) | ||
{ | ||
g_string_append_printf (summary, "\n %-24s", command->name); | ||
if (command->description != NULL) | ||
g_string_append_printf (summary, "%s", command->description); | ||
} | ||
|
||
command++; | ||
} | ||
|
||
g_option_context_set_summary (context, summary->str); | ||
|
||
return context; | ||
} | ||
|
||
gboolean | ||
ot_admin_builtin_kargs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) | ||
{ | ||
const char *subcommand_name = NULL; | ||
int in, out; | ||
for (in = 1, out = 1; in < argc; in++, out++) | ||
{ | ||
/* The non-option is the command, take it out of the arguments */ | ||
if (argv[in][0] != '-') | ||
{ | ||
if (subcommand_name == NULL) | ||
{ | ||
subcommand_name = argv[in]; | ||
out--; | ||
continue; | ||
} | ||
} | ||
|
||
else if (g_str_equal (argv[in], "--")) | ||
{ | ||
break; | ||
} | ||
|
||
argv[out] = argv[in]; | ||
} | ||
|
||
argc = out; | ||
|
||
OstreeCommand *subcommand = admin_kargs_subcommands; | ||
while (subcommand->name) | ||
{ | ||
if (g_strcmp0 (subcommand_name, subcommand->name) == 0) | ||
break; | ||
subcommand++; | ||
} | ||
|
||
if (!subcommand->name) | ||
{ | ||
g_autoptr(GOptionContext) context = | ||
ostree_admin_kargs_option_context_new_with_commands (); | ||
|
||
/* This will not return for some options (e.g. --version). */ | ||
if (ostree_admin_option_context_parse (context, NULL, &argc, &argv, | ||
OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, | ||
invocation, NULL, cancellable, error)) | ||
{ | ||
if (subcommand_name == NULL) | ||
{ | ||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, | ||
"No \"admin kargs\" subcommand specified"); | ||
} | ||
else | ||
{ | ||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, | ||
"Unknown \"admin kargs\" subcommand '%s'", subcommand_name); | ||
} | ||
} | ||
|
||
g_autofree char *help = g_option_context_get_help (context, FALSE, NULL); | ||
g_printerr ("%s", help); | ||
return FALSE; | ||
} | ||
|
||
g_autofree char *prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name); | ||
g_set_prgname (prgname); | ||
|
||
OstreeCommandInvocation sub_invocation = { .command = subcommand }; | ||
if (!subcommand->fn (argc, argv, &sub_invocation, cancellable, error)) | ||
return FALSE; | ||
|
||
return TRUE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (C) 2014 Colin Walters <[email protected]> | ||
* Copyright (C) 2022 Huijing Hei <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation; either version 2 of the licence or (at | ||
* your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General | ||
* Public License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include "ot-main.h" | ||
#include "ot-admin-kargs-builtins.h" | ||
|
||
#include "ostree.h" | ||
#include "otutil.h" | ||
|
||
static char **opt_kargs_edit_in_place_append; | ||
|
||
static GOptionEntry options[] = { | ||
{ "append-if-missing", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kargs_edit_in_place_append, "Append kernel arguments if they do not exist", "NAME=VALUE" }, | ||
{ NULL } | ||
}; | ||
|
||
gboolean | ||
ot_admin_kargs_builtin_edit_in_place (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) | ||
{ | ||
g_autoptr(OstreeSysroot) sysroot = NULL; | ||
|
||
g_autoptr(GOptionContext) context = g_option_context_new ("ARGS"); | ||
|
||
if (!ostree_admin_option_context_parse (context, options, &argc, &argv, | ||
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, | ||
invocation, &sysroot, cancellable, error)) | ||
return FALSE; | ||
|
||
g_autoptr(GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot); | ||
if (deployments->len == 0) | ||
{ | ||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, | ||
"Unable to find a deployment in sysroot"); | ||
return FALSE; | ||
} | ||
|
||
// set kargs for each deployment | ||
for (guint i = 0; i < deployments->len; i++) | ||
{ | ||
OstreeDeployment *deployment = deployments->pdata[i]; | ||
OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (deployment); | ||
g_autoptr(OstreeKernelArgs) kargs = ostree_kernel_args_from_string (ostree_bootconfig_parser_get (bootconfig, "options")); | ||
|
||
if (opt_kargs_edit_in_place_append) | ||
{ | ||
for (char **strviter = opt_kargs_edit_in_place_append; strviter && *strviter; strviter++) | ||
{ | ||
const char *arg = *strviter; | ||
ostree_kernel_args_append_if_missing (kargs, arg); | ||
} | ||
} | ||
|
||
g_auto(GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs); | ||
|
||
if (!ostree_sysroot_deployment_set_kargs (sysroot, deployment, | ||
kargs_strv, | ||
cancellable, error)) | ||
return FALSE; | ||
|
||
} | ||
|
||
return TRUE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2014 Colin Walters <[email protected]> | ||
* Copyright (C) 2022 Huijing Hei <[email protected]> | ||
* | ||
* SPDX-License-Identifier: LGPL-2.0+ | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <ostree.h> | ||
|
||
G_BEGIN_DECLS | ||
|
||
#define BUILTINPROTO(name) gboolean ot_admin_kargs_builtin_ ## name (int argc, char **argv, \ | ||
OstreeCommandInvocation *invocation, \ | ||
GCancellable *cancellable, GError **error) | ||
|
||
BUILTINPROTO(edit_in_place); | ||
|
||
#undef BUILTINPROTO | ||
|
||
G_END_DECLS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.