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) |
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 */ |
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 |
chptr = strchr(second, '='); |
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(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 */ |