Re: [PATCH 09/10] Add --set-default-index feature

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/20/2012 05:18 PM, Peter Jones wrote:
On 03/20/2012 02:55 PM, Cleber Rosa wrote:
This pairs with --default-index, allowing the user to specify the
entry to make the default using and index rather than a kernel.

Signed-off-by: Cleber Rosa<crosa@xxxxxxxxxx>
This needs test cases as well.

Sure!


---
  grubby.8 |   11 ++++++++---
  grubby.c |   29 +++++++++++++++++++++++------
  2 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/grubby.8 b/grubby.8
index fe60892..43c141d 100644
--- a/grubby.8
+++ b/grubby.8
@@ -11,9 +11,10 @@ grubby \- command line tool for configuring grub, lilo, and elilo
         [--info=\fIkernel-path\fR] [--initrd=\fIinitrd-path\fR]
         [--make-default] [-o path] [--version]
         [--remove-kernel=\fIkernel-path\fR] [--remove-args=\fIargs\fR]
-       [--set-default=\fIkernel-path\fR] [--title=entry-title]
-       [--add-multiboot=\fImultiboot-path\fR] [--mbargs=\fIargs\fR]
-       [--remove-multiboot=\fImultiboot-path\fR] [--remove-mbargs=\fIargs\fR]
+       [--set-default=\fIkernel-path\fR] [--set-default-index=\fientry-index\fR]
+       [--title=entry-title] [--add-multiboot=\fImultiboot-path\fR]
+       [--mbargs=\fIargs\fR] [--remove-multiboot=\fImultiboot-path\fR]
+       [--remove-mbargs=\fIargs\fR]

  .SH DESCRIPTION
  \fBgrubby\fR is a command line tool for updating and displaying information
@@ -154,6 +155,10 @@ The first entry which boots the specified kernel is made the default
  boot entry.

  .TP
+\fB-\-set-default-index\fR=\fIentry-index\fR
+Makes the given entry number the default boot entry.
+
+.TP
  \fB-\-title\fR=\fIentry-title\fR
  When a new kernel entry is added \fIentry-title\fR is used as the title
  (\fBlilo\fR label) for the entry. If \fIentry-title\fR is longer then maximum
diff --git a/grubby.c b/grubby.c
index ccb11b0..b8380bf 100644
--- a/grubby.c
+++ b/grubby.c
@@ -1774,13 +1774,19 @@ void markRemovedImage(struct grubConfig * cfg, const char * image,

  void setDefaultImage(struct grubConfig * config, int hasNew,
  		     const char * defaultKernelPath, int newIsDefault,
-		     const char * prefix, int flags) {
+		     const char * prefix, int flags, int index) {
      struct singleEntry * entry, * entry2, * newDefault;
      int i, j;

      if (newIsDefault) {
  	config->defaultImage = 0;
  	return;
+    } else if ((index>= 0)&&  config->cfi->defaultIsIndex) {
+	if (findEntryByIndex(config, index))
+	    config->defaultImage = index;
+	else
+	    config->defaultImage = -1;
+	return;

^ BTW, I followed the same logic employed when setting the default entry based on a kernel path that can not be found, that is, set defaultImage to -1 and return immediately. This effectively means that a previously set default will be removed. If you have any comments on this, please let me know.

      } else if (defaultKernelPath) {
  	i = 0;
  	if (findEntryByPath(config, defaultKernelPath, prefix,&i)) {
@@ -3653,6 +3659,7 @@ int main(int argc, const char ** argv) {
      int displayDefault = 0;
      int displayDefaultIndex = 0;
      int displayDefaultTitle = 0;
+    int defaultIndex = -1;
      struct poptOption options[] = {
  	{ "add-kernel", 0, POPT_ARG_STRING,&newKernelPath, 0,
  	    _("add an entry for the specified kernel"), _("kernel-path") },
@@ -3725,6 +3732,9 @@ int main(int argc, const char ** argv) {
  	{ "set-default", 0, POPT_ARG_STRING,&defaultKernel, 0,
  	    _("make the first entry referencing the specified kernel "
  	      "the default"), _("kernel-path") },
+	{ "set-default-index", 0, POPT_ARG_INT,&defaultIndex, 0,
+	    _("make the given entry index the default entry"),
+	    _("entry-index") },
  	{ "silo", 0, POPT_ARG_NONE,&configureSilo, 0,
  	    _("configure silo bootloader") },
  	{ "title", 0, POPT_ARG_STRING,&newKernelTitle, 0,
@@ -3833,8 +3843,9 @@ int main(int argc, const char ** argv) {
      }

      if (bootloaderProbe&&  (displayDefault || kernelInfo || newKernelVersion ||
-			  newKernelPath || removeKernelPath || makeDefault ||
-			  defaultKernel || displayDefaultIndex || displayDefaultTitle)) {
+			    newKernelPath || removeKernelPath || makeDefault ||
+			    defaultKernel || displayDefaultIndex || displayDefaultTitle ||
+			    (defaultIndex>= 0))) {
  	fprintf(stderr, _("grubby: --bootloader-probe may not be used with "
  			  "specified option"));
  	return 1;
@@ -3876,6 +3887,11 @@ int main(int argc, const char ** argv) {
  	makeDefault = 1;
  	defaultKernel = NULL;
      }
+    else if (defaultKernel&&  (defaultIndex>= 0)) {
+	fprintf(stderr, _("grubby: --set-default and --set-default-index "
+			  "may not be used together\n"));
+	return 1;
+    }

      if (grubConfig&&  !strcmp(grubConfig, "-")&&  !outputFile) {
  	fprintf(stderr, _("grubby: output file must be specified if stdin "
@@ -3884,8 +3900,9 @@ int main(int argc, const char ** argv) {
      }

      if (!removeKernelPath&&  !newKernelPath&&  !displayDefault&&  !defaultKernel
-	&&  !kernelInfo&&  !bootloaderProbe&&  !updateKernelPath
-&&  !removeMBKernel&&  !displayDefaultIndex&&  !displayDefaultTitle) {
+	&&  !kernelInfo&&  !bootloaderProbe&&  !updateKernelPath
+	&&  !removeMBKernel&&  !displayDefaultIndex&&  !displayDefaultTitle
+	&&  (defaultIndex == -1)) {
  	fprintf(stderr, _("grubby: no action specified\n"));
  	return 1;
      }
@@ -4044,7 +4061,7 @@ int main(int argc, const char ** argv) {
      markRemovedImage(config, removeKernelPath, bootPrefix);
      markRemovedImage(config, removeMBKernel, bootPrefix);
      setDefaultImage(config, newKernelPath != NULL, defaultKernel, makeDefault,
-		    bootPrefix, flags);
+		    bootPrefix, flags, defaultIndex);
      setFallbackImage(config, newKernelPath != NULL);
      if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs,
                      removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1;


_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux