1792 |
int needs = MAIN_DEFAULT; |
int needs = MAIN_DEFAULT; |
1793 |
struct stat sb; |
struct stat sb; |
1794 |
int i; |
int i; |
1795 |
|
int rc = 0; |
1796 |
|
|
1797 |
if (!strcmp(outName, "-")) { |
if (!strcmp(outName, "-")) { |
1798 |
out = stdout; |
out = stdout; |
1907 |
} |
} |
1908 |
|
|
1909 |
if (tmpOutName) { |
if (tmpOutName) { |
1910 |
if (rename(tmpOutName, outName)) { |
/* write userspace buffers */ |
1911 |
fprintf(stderr, |
if (fflush(out)) |
1912 |
_("grubby: error moving %s to %s: %s\n"), |
rc = 1; |
1913 |
tmpOutName, outName, strerror(errno)); |
|
1914 |
unlink(outName); |
/* purge the write-back cache with fsync() */ |
1915 |
return 1; |
if (fsync(fileno(out))) |
1916 |
|
rc = 1; |
1917 |
|
|
1918 |
|
if (fclose(out)) |
1919 |
|
rc = 1; |
1920 |
|
|
1921 |
|
if (rc == 0 && rename(tmpOutName, outName)) { |
1922 |
|
unlink(tmpOutName); |
1923 |
|
rc = 1; |
1924 |
} |
} |
1925 |
|
|
1926 |
|
/* fsync() the destination directory after rename */ |
1927 |
|
if (rc == 0) { |
1928 |
|
int dirfd; |
1929 |
|
|
1930 |
|
dirfd = open(dirname(strdupa(outName)), O_RDONLY); |
1931 |
|
if (dirfd < 0) |
1932 |
|
rc = 1; |
1933 |
|
else if (fsync(dirfd)) |
1934 |
|
rc = 1; |
1935 |
|
|
1936 |
|
if (dirfd >= 0) |
1937 |
|
close(dirfd); |
1938 |
|
} |
1939 |
|
|
1940 |
|
if (rc == 1) |
1941 |
|
fprintf(stderr, |
1942 |
|
_("grubby: error flushing data: %m\n")); |
1943 |
} |
} |
1944 |
|
|
1945 |
return 0; |
return rc; |
1946 |
} |
} |
1947 |
|
|
1948 |
static int numEntries(struct grubConfig *cfg) |
static int numEntries(struct grubConfig *cfg) |
2552 |
struct singleEntry *bootEntry, *newDefault; |
struct singleEntry *bootEntry, *newDefault; |
2553 |
int indexToVerify, firstKernelEntryIndex, currentLookupIndex; |
int indexToVerify, firstKernelEntryIndex, currentLookupIndex; |
2554 |
|
|
2555 |
|
/* initialize */ |
2556 |
|
currentLookupIndex = FIRST_ENTRY_INDEX; |
2557 |
|
|
2558 |
/* handle the two cases where the user explictly picks the default |
/* handle the two cases where the user explictly picks the default |
2559 |
* boot entry index as it would exist post-modification */ |
* boot entry index as it would exist post-modification */ |
2560 |
|
|
2565 |
} |
} |
2566 |
|
|
2567 |
/* Case 2: user picked an arbitrary index as the default boot entry */ |
/* Case 2: user picked an arbitrary index as the default boot entry */ |
2568 |
if (newDefaultBootEntryIndex >= FIRST_ENTRY_INDEX |
if (newDefaultBootEntryIndex >= FIRST_ENTRY_INDEX) { |
|
&& config->cfi->defaultIsIndex) { |
|
2569 |
indexToVerify = newDefaultBootEntryIndex; |
indexToVerify = newDefaultBootEntryIndex; |
2570 |
|
|
2571 |
/* user chose to make latest boot entry the default */ |
/* user chose to make latest boot entry the default */ |
2598 |
/* check validity of existing default or first-entry-found |
/* check validity of existing default or first-entry-found |
2599 |
selection */ |
selection */ |
2600 |
if (defaultKernelPath) { |
if (defaultKernelPath) { |
2601 |
|
/* we must initialize this */ |
2602 |
|
firstKernelEntryIndex = 0; |
2603 |
/* user requested first-entry-found */ |
/* user requested first-entry-found */ |
2604 |
if (!findEntryByPath(config, defaultKernelPath, |
if (!findEntryByPath(config, defaultKernelPath, |
2605 |
prefix, &firstKernelEntryIndex)) { |
prefix, &firstKernelEntryIndex)) { |
2619 |
config->defaultImage++; |
config->defaultImage++; |
2620 |
} |
} |
2621 |
} else { |
} else { |
2622 |
/* use pre-existing default entry */ |
/* check to see if the default is stored in the environment */ |
2623 |
currentLookupIndex = config->defaultImage; |
if (config->defaultImage < FIRST_ENTRY_INDEX) { |
2624 |
|
if (config->defaultImage == DEFAULT_SAVED || config->defaultImage == DEFAULT_SAVED_GRUB2) |
2625 |
|
{ |
2626 |
|
if (config->cfi->defaultIsSaved) { |
2627 |
|
if (config->cfi->getEnv) { |
2628 |
|
char *defaultTitle = config->cfi->getEnv(config->cfi, "saved_entry"); |
2629 |
|
|
2630 |
|
if (defaultTitle) { |
2631 |
|
if (isnumber(defaultTitle)) { |
2632 |
|
currentLookupIndex = atoi(defaultTitle); |
2633 |
|
} else { |
2634 |
|
findEntryByTitle(config, defaultTitle, ¤tLookupIndex); |
2635 |
|
} |
2636 |
|
/* set the default Image to an actual index */ |
2637 |
|
config->defaultImage = currentLookupIndex; |
2638 |
|
} |
2639 |
|
} |
2640 |
|
} |
2641 |
|
} |
2642 |
|
} else { |
2643 |
|
/* use pre-existing default entry from the file*/ |
2644 |
|
currentLookupIndex = config->defaultImage; |
2645 |
|
} |
2646 |
|
|
2647 |
if (isAddingBootEntry |
if (isAddingBootEntry |
2648 |
&& (newBootEntryIndex <= config->defaultImage)) { |
&& (newBootEntryIndex <= config->defaultImage)) { |
2713 |
} |
} |
2714 |
} |
} |
2715 |
|
|
2716 |
void displayEntry(struct singleEntry *entry, const char *prefix, int index) |
void displayEntry(struct grubConfig *config, struct singleEntry *entry, const char *prefix, int index) |
2717 |
{ |
{ |
2718 |
struct singleLine *line; |
struct singleLine *line; |
2719 |
char *root = NULL; |
char *root = NULL; |
2809 |
|
|
2810 |
line = getLineByType(LT_TITLE, entry->lines); |
line = getLineByType(LT_TITLE, entry->lines); |
2811 |
if (line) { |
if (line) { |
2812 |
printf("title=%s\n", line->elements[1].item); |
char *entryTitle; |
2813 |
|
/* if we can extractTitle, then it's a zipl config and |
2814 |
|
* if not then we go ahead with what's existed prior */ |
2815 |
|
entryTitle = extractTitle(config, line); |
2816 |
|
if (!entryTitle) { |
2817 |
|
entryTitle=line->elements[1].item; |
2818 |
|
} |
2819 |
|
printf("title=%s\n", entryTitle); |
2820 |
} else { |
} else { |
2821 |
char *title; |
char *title; |
2822 |
line = getLineByType(LT_MENUENTRY, entry->lines); |
line = getLineByType(LT_MENUENTRY, entry->lines); |
3232 |
printf("lba\n"); |
printf("lba\n"); |
3233 |
} |
} |
3234 |
|
|
3235 |
displayEntry(entry, prefix, i); |
displayEntry(config, entry, prefix, i); |
3236 |
|
|
3237 |
i++; |
i++; |
3238 |
while ((entry = findEntryByPath(config, kernel, prefix, &i))) { |
while ((entry = findEntryByPath(config, kernel, prefix, &i))) { |
3239 |
displayEntry(entry, prefix, i); |
displayEntry(config, entry, prefix, i); |
3240 |
i++; |
i++; |
3241 |
} |
} |
3242 |
|
|
3566 |
line->numElements--; |
line->numElements--; |
3567 |
} |
} |
3568 |
|
|
3569 |
int argMatch(const char *one, const char *two) |
static int argNameMatch(const char *one, const char *two) |
3570 |
{ |
{ |
3571 |
char *first, *second; |
char *first, *second; |
3572 |
char *chptr; |
char *chptra, *chptrb; |
3573 |
|
int rc; |
3574 |
|
|
3575 |
first = strcpy(alloca(strlen(one) + 1), one); |
first = strcpy(alloca(strlen(one) + 1), one); |
3576 |
second = strcpy(alloca(strlen(two) + 1), two); |
second = strcpy(alloca(strlen(two) + 1), two); |
3577 |
|
|
3578 |
chptr = strchr(first, '='); |
chptra = strchr(first, '='); |
3579 |
if (chptr) |
if (chptra) |
3580 |
*chptr = '\0'; |
*chptra = '\0'; |
3581 |
|
|
3582 |
|
chptrb = strchr(second, '='); |
3583 |
|
if (chptrb) |
3584 |
|
*chptrb = '\0'; |
3585 |
|
|
3586 |
|
rc = strcmp(first, second); |
3587 |
|
|
3588 |
|
if (chptra) |
3589 |
|
*chptra = '='; |
3590 |
|
if (chptrb) |
3591 |
|
*chptrb = '='; |
3592 |
|
|
3593 |
|
return rc; |
3594 |
|
} |
3595 |
|
|
3596 |
|
static int argHasValue(const char *arg) |
3597 |
|
{ |
3598 |
|
char *chptr; |
3599 |
|
|
3600 |
chptr = strchr(second, '='); |
chptr = strchr(arg, '='); |
3601 |
if (chptr) |
if (chptr) |
3602 |
*chptr = '\0'; |
return 1; |
3603 |
|
return 0; |
3604 |
|
} |
3605 |
|
|
3606 |
return strcmp(first, second); |
static int argValueMatch(const char *one, const char *two) |
3607 |
|
{ |
3608 |
|
char *first, *second; |
3609 |
|
char *chptra, *chptrb; |
3610 |
|
|
3611 |
|
first = strcpy(alloca(strlen(one) + 1), one); |
3612 |
|
second = strcpy(alloca(strlen(two) + 1), two); |
3613 |
|
|
3614 |
|
chptra = strchr(first, '='); |
3615 |
|
if (chptra) |
3616 |
|
chptra += 1; |
3617 |
|
|
3618 |
|
chptrb = strchr(second, '='); |
3619 |
|
if (chptrb) |
3620 |
|
chptrb += 1; |
3621 |
|
|
3622 |
|
if (!chptra && !chptrb) |
3623 |
|
return 0; |
3624 |
|
else if (!chptra) |
3625 |
|
return *chptrb - 0; |
3626 |
|
else if (!chptrb) |
3627 |
|
return 0 - *chptra; |
3628 |
|
else |
3629 |
|
return strcmp(chptra, chptrb); |
3630 |
} |
} |
3631 |
|
|
3632 |
int updateActualImage(struct grubConfig *cfg, const char *image, |
int updateActualImage(struct grubConfig *cfg, const char *image, |
3770 |
} |
} |
3771 |
if (usedElements[i]) |
if (usedElements[i]) |
3772 |
continue; |
continue; |
3773 |
if (!argMatch(line->elements[i].item, *arg)) { |
if (!argNameMatch(line->elements[i].item, *arg)) { |
3774 |
usedElements[i] = 1; |
usedElements[i] = 1; |
3775 |
break; |
break; |
3776 |
} |
} |
3829 |
!strcmp(line->elements[i].item, "--")) |
!strcmp(line->elements[i].item, "--")) |
3830 |
/* reached the end of hyper args, stop here */ |
/* reached the end of hyper args, stop here */ |
3831 |
break; |
break; |
3832 |
if (!argMatch(line->elements[i].item, *arg)) { |
if (!argNameMatch(line->elements[i].item, *arg)) { |
3833 |
removeElement(line, i); |
if (!argHasValue(*arg) || |
3834 |
break; |
!argValueMatch(line->elements[i].item, *arg)) { |
3835 |
|
removeElement(line, i); |
3836 |
|
break; |
3837 |
|
} |
3838 |
} |
} |
3839 |
} |
} |
3840 |
/* handle removing LT_ROOT line too */ |
/* handle removing LT_ROOT line too */ |
5154 |
if (!cfi) { |
if (!cfi) { |
5155 |
if (grub2FindConfig(&grub2ConfigType)) { |
if (grub2FindConfig(&grub2ConfigType)) { |
5156 |
cfi = &grub2ConfigType; |
cfi = &grub2ConfigType; |
5157 |
|
configureGrub2 = 1; |
5158 |
if (envPath) |
if (envPath) |
5159 |
cfi->envFile = envPath; |
cfi->envFile = envPath; |
5160 |
} else |
} else { |
5161 |
#ifdef __ia64__ |
#ifdef __ia64__ |
5162 |
cfi = &eliloConfigType; |
cfi = &eliloConfigType; |
5163 |
#elif __powerpc__ |
configureLilo = 1; |
5164 |
|
#elif defined(__powerpc__) |
5165 |
cfi = &yabootConfigType; |
cfi = &yabootConfigType; |
5166 |
#elif __sparc__ |
configureYaboot = 1; |
5167 |
|
#elif defined(__sparc__) |
5168 |
cfi = &siloConfigType; |
cfi = &siloConfigType; |
5169 |
#elif __s390__ |
configureSilo = 1; |
5170 |
|
#elif defined(__s390__) || defined(__s390x__) |
5171 |
cfi = &ziplConfigType; |
cfi = &ziplConfigType; |
5172 |
#elif __s390x__ |
configureZipl = 1; |
|
cfi = &ziplConfigtype; |
|
5173 |
#else |
#else |
5174 |
cfi = &grubConfigType; |
cfi = &grubConfigType; |
5175 |
|
configureGrub = 1; |
5176 |
#endif |
#endif |
5177 |
|
} |
5178 |
} |
} |
5179 |
|
|
5180 |
if (!grubConfig) { |
if (!grubConfig) { |