--- trunk/grubby/grubby.c 2016/06/29 14:07:33 2959 +++ trunk/grubby/grubby.c 2016/06/29 14:07:59 2960 @@ -3309,7 +3309,8 @@ } int addMBInitrd(struct grubConfig * cfg, const char *newMBKernel, - const char * image, const char * prefix, const char * initrd) { + const char * image, const char * prefix, const char * initrd, + const char * title) { struct singleEntry * entry; struct singleLine * line, * kernelLine, *endLine = NULL; int index = 0; @@ -3320,6 +3321,20 @@ kernelLine = getLineByType(LT_MBMODULE, entry->lines); if (!kernelLine) continue; + /* if title is supplied, the entry's title must match it. */ + if (title) { + line = getLineByType(LT_TITLE|LT_MENUENTRY, entry->lines); + char *linetitle = extractTitle(line); + + if (!linetitle) + continue; + if (strcmp(title, linetitle)) { + free(linetitle); + continue; + } + free(linetitle); + } + if (prefix) { int prefixLen = strlen(prefix); if (!strncmp(initrd, prefix, prefixLen)) @@ -3345,7 +3360,7 @@ } int updateInitrd(struct grubConfig * cfg, const char * image, - const char * prefix, const char * initrd) { + const char * prefix, const char * initrd, const char * title) { struct singleEntry * entry; struct singleLine * line, * kernelLine, *endLine = NULL; int index = 0; @@ -3356,6 +3371,20 @@ kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); if (!kernelLine) continue; + /* if title is supplied, the entry's title must match it. */ + if (title) { + line = getLineByType(LT_TITLE|LT_MENUENTRY, entry->lines); + char *linetitle = extractTitle(line); + + if (!linetitle) + continue; + if (strcmp(title, linetitle)) { + free(linetitle); + continue; + } + free(linetitle); + } + line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines); if (line) removeLine(entry, line); @@ -4414,7 +4443,7 @@ if (newKernelPath && !newKernelTitle) { fprintf(stderr, _("grubby: kernel title must be specified\n")); return 1; - } else if (!newKernelPath && (newKernelTitle || copyDefault || + } else if (!newKernelPath && (copyDefault || (newKernelInitrd && !updateKernelPath)|| makeDefault || extraInitrdCount > 0)) { fprintf(stderr, _("grubby: kernel path expected\n")); @@ -4636,11 +4665,12 @@ if (updateKernelPath && newKernelInitrd) { if (newMBKernel) { if (addMBInitrd(config, newMBKernel, updateKernelPath, - bootPrefix, newKernelInitrd)) + bootPrefix, newKernelInitrd, + newKernelTitle)) return 1; } else { if (updateInitrd(config, updateKernelPath, bootPrefix, - newKernelInitrd)) + newKernelInitrd, newKernelTitle)) return 1; } }