68 |
|
|
69 |
char *saved_command_line = NULL; |
char *saved_command_line = NULL; |
70 |
|
|
71 |
|
const char *mounts = "/proc/mounts"; |
72 |
|
|
73 |
/* comments get lumped in with indention */ |
/* comments get lumped in with indention */ |
74 |
struct lineElement { |
struct lineElement { |
75 |
char *item; |
char *item; |
482 |
snprintf(result, resultMaxSize, "%s", ++current); |
snprintf(result, resultMaxSize, "%s", ++current); |
483 |
|
|
484 |
i++; |
i++; |
485 |
|
int result_len = 0; |
486 |
for (; i < line->numElements; ++i) { |
for (; i < line->numElements; ++i) { |
487 |
current = line->elements[i].item; |
current = line->elements[i].item; |
488 |
current_len = strlen(current); |
current_len = strlen(current); |
489 |
current_indent = line->elements[i].indent; |
current_indent = line->elements[i].indent; |
490 |
current_indent_len = strlen(current_indent); |
current_indent_len = strlen(current_indent); |
491 |
|
|
492 |
strncat(result, current_indent, current_indent_len); |
memcpy(result + result_len, current_indent, current_indent_len); |
493 |
|
result_len += current_indent_len; |
494 |
|
|
495 |
if (current[current_len - 1] != quote_char) { |
if (current[current_len - 1] != quote_char) { |
496 |
strncat(result, current, current_len); |
memcpy(result + result_len, current_indent, |
497 |
|
current_indent_len); |
498 |
|
result_len += current_len; |
499 |
} else { |
} else { |
500 |
strncat(result, current, current_len - 1); |
memcpy(result + result_len, current_indent, |
501 |
|
current_indent_len); |
502 |
|
result_len += (current_len - 1); |
503 |
break; |
break; |
504 |
} |
} |
505 |
} |
} |
506 |
|
result[result_len] = '\0'; |
507 |
return result; |
return result; |
508 |
} |
} |
509 |
|
|
711 |
struct configFileInfo *cfi); |
struct configFileInfo *cfi); |
712 |
static int getNextLine(char **bufPtr, struct singleLine *line, |
static int getNextLine(char **bufPtr, struct singleLine *line, |
713 |
struct configFileInfo *cfi); |
struct configFileInfo *cfi); |
714 |
static char *getRootSpecifier(char *str); |
static size_t getRootSpecifier(const char *str); |
715 |
static void requote(struct singleLine *line, struct configFileInfo *cfi); |
static void requote(struct singleLine *line, struct configFileInfo *cfi); |
716 |
static void insertElement(struct singleLine *line, |
static void insertElement(struct singleLine *line, |
717 |
const char *item, int insertHere, |
const char *item, int insertHere, |
1448 |
extras = malloc(len + 1); |
extras = malloc(len + 1); |
1449 |
*extras = '\0'; |
*extras = '\0'; |
1450 |
|
|
1451 |
|
int buf_len = 0; |
1452 |
/* get title. */ |
/* get title. */ |
1453 |
for (int i = 0; i < line->numElements; i++) { |
for (int i = 0; i < line->numElements; i++) { |
1454 |
if (!strcmp |
if (!strcmp |
1465 |
|
|
1466 |
len = strlen(title); |
len = strlen(title); |
1467 |
if (title[len - 1] == quote_char) { |
if (title[len - 1] == quote_char) { |
1468 |
strncat(buf, title, len - 1); |
memcpy(buf + buf_len, title, len - 1); |
1469 |
|
buf_len += (len - 1); |
1470 |
break; |
break; |
1471 |
} else { |
} else { |
1472 |
strcat(buf, title); |
memcpy(buf + buf_len, title, len); |
1473 |
strcat(buf, line->elements[i].indent); |
buf_len += len; |
1474 |
|
len = strlen(line->elements[i].indent); |
1475 |
|
memcpy(buf + buf_len, line->elements[i].indent, len); |
1476 |
|
buf_len += len; |
1477 |
} |
} |
1478 |
} |
} |
1479 |
|
buf[buf_len] = '\0'; |
1480 |
|
|
1481 |
/* get extras */ |
/* get extras */ |
1482 |
int count = 0; |
int count = 0; |
1808 |
int needs = MAIN_DEFAULT; |
int needs = MAIN_DEFAULT; |
1809 |
struct stat sb; |
struct stat sb; |
1810 |
int i; |
int i; |
1811 |
|
int rc = 0; |
1812 |
|
|
1813 |
if (!strcmp(outName, "-")) { |
if (!strcmp(outName, "-")) { |
1814 |
out = stdout; |
out = stdout; |
1923 |
} |
} |
1924 |
|
|
1925 |
if (tmpOutName) { |
if (tmpOutName) { |
1926 |
if (rename(tmpOutName, outName)) { |
/* write userspace buffers */ |
1927 |
fprintf(stderr, |
if (fflush(out)) |
1928 |
_("grubby: error moving %s to %s: %s\n"), |
rc = 1; |
1929 |
tmpOutName, outName, strerror(errno)); |
|
1930 |
unlink(outName); |
/* purge the write-back cache with fsync() */ |
1931 |
return 1; |
if (fsync(fileno(out))) |
1932 |
|
rc = 1; |
1933 |
|
|
1934 |
|
if (fclose(out)) |
1935 |
|
rc = 1; |
1936 |
|
|
1937 |
|
if (rc == 0 && rename(tmpOutName, outName)) { |
1938 |
|
unlink(tmpOutName); |
1939 |
|
rc = 1; |
1940 |
} |
} |
1941 |
|
|
1942 |
|
/* fsync() the destination directory after rename */ |
1943 |
|
if (rc == 0) { |
1944 |
|
int dirfd; |
1945 |
|
|
1946 |
|
dirfd = open(dirname(strdupa(outName)), O_RDONLY); |
1947 |
|
if (dirfd < 0) |
1948 |
|
rc = 1; |
1949 |
|
else if (fsync(dirfd)) |
1950 |
|
rc = 1; |
1951 |
|
|
1952 |
|
if (dirfd >= 0) |
1953 |
|
close(dirfd); |
1954 |
|
} |
1955 |
|
|
1956 |
|
if (rc == 1) |
1957 |
|
fprintf(stderr, |
1958 |
|
_("grubby: error flushing data: %m\n")); |
1959 |
} |
} |
1960 |
|
|
1961 |
return 0; |
return rc; |
1962 |
} |
} |
1963 |
|
|
1964 |
static int numEntries(struct grubConfig *cfg) |
static int numEntries(struct grubConfig *cfg) |
2134 |
return s[slen] == c; |
return s[slen] == c; |
2135 |
} |
} |
2136 |
|
|
2137 |
|
typedef struct { |
2138 |
|
const char *start; |
2139 |
|
size_t chars; |
2140 |
|
} field; |
2141 |
|
|
2142 |
|
static int iscomma(int c) |
2143 |
|
{ |
2144 |
|
return c == ','; |
2145 |
|
} |
2146 |
|
|
2147 |
|
static int isequal(int c) |
2148 |
|
{ |
2149 |
|
return c == '='; |
2150 |
|
} |
2151 |
|
|
2152 |
|
static field findField(const field *in, typeof(isspace) *isdelim, field *out) |
2153 |
|
{ |
2154 |
|
field nxt = {}; |
2155 |
|
size_t off = 0; |
2156 |
|
|
2157 |
|
while (off < in->chars && isdelim(in->start[off])) |
2158 |
|
off++; |
2159 |
|
|
2160 |
|
if (off == in->chars) |
2161 |
|
return nxt; |
2162 |
|
|
2163 |
|
out->start = &in->start[off]; |
2164 |
|
out->chars = 0; |
2165 |
|
|
2166 |
|
while (off + out->chars < in->chars && !isdelim(out->start[out->chars])) |
2167 |
|
out->chars++; |
2168 |
|
|
2169 |
|
nxt.start = out->start + out->chars; |
2170 |
|
nxt.chars = in->chars - off - out->chars; |
2171 |
|
return nxt; |
2172 |
|
} |
2173 |
|
|
2174 |
|
static int fieldEquals(const field *in, const char *str) |
2175 |
|
{ |
2176 |
|
return in->chars == strlen(str) && |
2177 |
|
strncmp(in->start, str, in->chars) == 0; |
2178 |
|
} |
2179 |
|
|
2180 |
|
/* Parse /proc/mounts to determine the subvolume prefix. */ |
2181 |
|
static size_t subvolPrefix(const char *str) |
2182 |
|
{ |
2183 |
|
FILE *file = NULL; |
2184 |
|
char *line = NULL; |
2185 |
|
size_t prfx = 0; |
2186 |
|
size_t size = 0; |
2187 |
|
|
2188 |
|
file = fopen(mounts, "r"); |
2189 |
|
if (!file) |
2190 |
|
return 0; |
2191 |
|
|
2192 |
|
for (ssize_t s; (s = getline(&line, &size, file)) >= 0; ) { |
2193 |
|
field nxt = { line, s }; |
2194 |
|
field dev = {}; |
2195 |
|
field path = {}; |
2196 |
|
field type = {}; |
2197 |
|
field opts = {}; |
2198 |
|
field opt = {}; |
2199 |
|
|
2200 |
|
nxt = findField(&nxt, isspace, &dev); |
2201 |
|
if (!nxt.start) |
2202 |
|
continue; |
2203 |
|
|
2204 |
|
nxt = findField(&nxt, isspace, &path); |
2205 |
|
if (!nxt.start) |
2206 |
|
continue; |
2207 |
|
|
2208 |
|
nxt = findField(&nxt, isspace, &type); |
2209 |
|
if (!nxt.start) |
2210 |
|
continue; |
2211 |
|
|
2212 |
|
nxt = findField(&nxt, isspace, &opts); |
2213 |
|
if (!nxt.start) |
2214 |
|
continue; |
2215 |
|
|
2216 |
|
if (!fieldEquals(&type, "btrfs")) |
2217 |
|
continue; |
2218 |
|
|
2219 |
|
/* We have found a btrfs mount point. */ |
2220 |
|
|
2221 |
|
nxt = opts; |
2222 |
|
while ((nxt = findField(&nxt, iscomma, &opt)).start) { |
2223 |
|
field key = {}; |
2224 |
|
field val = {}; |
2225 |
|
|
2226 |
|
opt = findField(&opt, isequal, &key); |
2227 |
|
if (!opt.start) |
2228 |
|
continue; |
2229 |
|
|
2230 |
|
opt = findField(&opt, isequal, &val); |
2231 |
|
if (!opt.start) |
2232 |
|
continue; |
2233 |
|
|
2234 |
|
if (!fieldEquals(&key, "subvol")) |
2235 |
|
continue; |
2236 |
|
|
2237 |
|
/* We have found a btrfs subvolume mount point. */ |
2238 |
|
|
2239 |
|
if (strncmp(val.start, str, val.chars)) |
2240 |
|
continue; |
2241 |
|
|
2242 |
|
if (val.start[val.chars - 1] != '/' && |
2243 |
|
str[val.chars] != '/') |
2244 |
|
continue; |
2245 |
|
|
2246 |
|
/* The subvolume mount point matches our input. */ |
2247 |
|
|
2248 |
|
if (prfx < val.chars) |
2249 |
|
prfx = val.chars; |
2250 |
|
} |
2251 |
|
} |
2252 |
|
|
2253 |
|
dbgPrintf("%s(): str: '%s', prfx: '%s'\n", __FUNCTION__, str, prfx); |
2254 |
|
|
2255 |
|
fclose(file); |
2256 |
|
free(line); |
2257 |
|
return prfx; |
2258 |
|
} |
2259 |
|
|
2260 |
int suitableImage(struct singleEntry *entry, const char *bootPrefix, |
int suitableImage(struct singleEntry *entry, const char *bootPrefix, |
2261 |
int skipRemoved, int flags) |
int skipRemoved, int flags) |
2262 |
{ |
{ |
2264 |
char *fullName; |
char *fullName; |
2265 |
int i; |
int i; |
2266 |
char *dev; |
char *dev; |
2267 |
char *rootspec; |
size_t rs; |
2268 |
char *rootdev; |
char *rootdev; |
2269 |
|
|
2270 |
if (skipRemoved && entry->skip) { |
if (skipRemoved && entry->skip) { |
2292 |
|
|
2293 |
fullName = alloca(strlen(bootPrefix) + |
fullName = alloca(strlen(bootPrefix) + |
2294 |
strlen(line->elements[1].item) + 1); |
strlen(line->elements[1].item) + 1); |
2295 |
rootspec = getRootSpecifier(line->elements[1].item); |
rs = getRootSpecifier(line->elements[1].item); |
|
int rootspec_offset = rootspec ? strlen(rootspec) : 0; |
|
2296 |
int hasslash = endswith(bootPrefix, '/') || |
int hasslash = endswith(bootPrefix, '/') || |
2297 |
beginswith(line->elements[1].item + rootspec_offset, '/'); |
beginswith(line->elements[1].item + rs, '/'); |
2298 |
sprintf(fullName, "%s%s%s", bootPrefix, hasslash ? "" : "/", |
sprintf(fullName, "%s%s%s", bootPrefix, hasslash ? "" : "/", |
2299 |
line->elements[1].item + rootspec_offset); |
line->elements[1].item + rs); |
2300 |
if (access(fullName, R_OK)) { |
if (access(fullName, R_OK)) { |
2301 |
notSuitablePrintf(entry, 0, "access to %s failed\n", fullName); |
notSuitablePrintf(entry, 0, "access to %s failed\n", fullName); |
2302 |
return 0; |
return 0; |
2388 |
struct singleLine *line; |
struct singleLine *line; |
2389 |
int i; |
int i; |
2390 |
char *chptr; |
char *chptr; |
|
char *rootspec = NULL; |
|
2391 |
enum lineType_e checkType = LT_KERNEL; |
enum lineType_e checkType = LT_KERNEL; |
2392 |
|
|
2393 |
if (isdigit(*kernel)) { |
if (isdigit(*kernel)) { |
2492 |
|
|
2493 |
if (line && line->type != LT_MENUENTRY && |
if (line && line->type != LT_MENUENTRY && |
2494 |
line->numElements >= 2) { |
line->numElements >= 2) { |
2495 |
rootspec = |
if (!strcmp(line->elements[1].item + |
2496 |
getRootSpecifier(line->elements[1]. |
getRootSpecifier( |
2497 |
item); |
line->elements[1].item), |
2498 |
if (!strcmp |
kernel + strlen(prefix))) |
|
(line->elements[1].item + |
|
|
((rootspec != |
|
|
NULL) ? strlen(rootspec) : 0), |
|
|
kernel + strlen(prefix))) |
|
2499 |
break; |
break; |
2500 |
} |
} |
2501 |
if (line->type == LT_MENUENTRY && |
if (line->type == LT_MENUENTRY && |
2685 |
struct singleEntry *bootEntry, *newDefault; |
struct singleEntry *bootEntry, *newDefault; |
2686 |
int indexToVerify, firstKernelEntryIndex, currentLookupIndex; |
int indexToVerify, firstKernelEntryIndex, currentLookupIndex; |
2687 |
|
|
2688 |
|
/* initialize */ |
2689 |
|
currentLookupIndex = FIRST_ENTRY_INDEX; |
2690 |
|
|
2691 |
/* handle the two cases where the user explictly picks the default |
/* handle the two cases where the user explictly picks the default |
2692 |
* boot entry index as it would exist post-modification */ |
* boot entry index as it would exist post-modification */ |
2693 |
|
|
2698 |
} |
} |
2699 |
|
|
2700 |
/* Case 2: user picked an arbitrary index as the default boot entry */ |
/* Case 2: user picked an arbitrary index as the default boot entry */ |
2701 |
if (newDefaultBootEntryIndex >= FIRST_ENTRY_INDEX |
if (newDefaultBootEntryIndex >= FIRST_ENTRY_INDEX) { |
|
&& config->cfi->defaultIsIndex) { |
|
2702 |
indexToVerify = newDefaultBootEntryIndex; |
indexToVerify = newDefaultBootEntryIndex; |
2703 |
|
|
2704 |
/* user chose to make latest boot entry the default */ |
/* user chose to make latest boot entry the default */ |
2752 |
config->defaultImage++; |
config->defaultImage++; |
2753 |
} |
} |
2754 |
} else { |
} else { |
2755 |
/* use pre-existing default entry */ |
/* check to see if the default is stored in the environment */ |
2756 |
currentLookupIndex = config->defaultImage; |
if (config->defaultImage < FIRST_ENTRY_INDEX) { |
2757 |
|
if (config->defaultImage == DEFAULT_SAVED || config->defaultImage == DEFAULT_SAVED_GRUB2) |
2758 |
|
{ |
2759 |
|
if (config->cfi->defaultIsSaved) { |
2760 |
|
if (config->cfi->getEnv) { |
2761 |
|
char *defaultTitle = config->cfi->getEnv(config->cfi, "saved_entry"); |
2762 |
|
|
2763 |
|
if (defaultTitle) { |
2764 |
|
if (isnumber(defaultTitle)) { |
2765 |
|
currentLookupIndex = atoi(defaultTitle); |
2766 |
|
} else { |
2767 |
|
findEntryByTitle(config, defaultTitle, ¤tLookupIndex); |
2768 |
|
} |
2769 |
|
/* set the default Image to an actual index */ |
2770 |
|
config->defaultImage = currentLookupIndex; |
2771 |
|
} |
2772 |
|
} |
2773 |
|
} |
2774 |
|
} |
2775 |
|
} else { |
2776 |
|
/* use pre-existing default entry from the file*/ |
2777 |
|
currentLookupIndex = config->defaultImage; |
2778 |
|
} |
2779 |
|
|
2780 |
if (isAddingBootEntry |
if (isAddingBootEntry |
2781 |
&& (newBootEntryIndex <= config->defaultImage)) { |
&& (newBootEntryIndex <= config->defaultImage)) { |
2846 |
} |
} |
2847 |
} |
} |
2848 |
|
|
2849 |
void displayEntry(struct singleEntry *entry, const char *prefix, int index) |
void displayEntry(struct grubConfig *config, struct singleEntry *entry, const char *prefix, int index) |
2850 |
{ |
{ |
2851 |
struct singleLine *line; |
struct singleLine *line; |
2852 |
char *root = NULL; |
char *root = NULL; |
2942 |
|
|
2943 |
line = getLineByType(LT_TITLE, entry->lines); |
line = getLineByType(LT_TITLE, entry->lines); |
2944 |
if (line) { |
if (line) { |
2945 |
printf("title=%s\n", line->elements[1].item); |
char *entryTitle; |
2946 |
|
/* if we can extractTitle, then it's a zipl config and |
2947 |
|
* if not then we go ahead with what's existed prior */ |
2948 |
|
entryTitle = extractTitle(config, line); |
2949 |
|
if (!entryTitle) { |
2950 |
|
entryTitle=line->elements[1].item; |
2951 |
|
} |
2952 |
|
printf("title=%s\n", entryTitle); |
2953 |
} else { |
} else { |
2954 |
char *title; |
char *title; |
2955 |
line = getLineByType(LT_MENUENTRY, entry->lines); |
line = getLineByType(LT_MENUENTRY, entry->lines); |
3365 |
printf("lba\n"); |
printf("lba\n"); |
3366 |
} |
} |
3367 |
|
|
3368 |
displayEntry(entry, prefix, i); |
displayEntry(config, entry, prefix, i); |
3369 |
|
|
3370 |
i++; |
i++; |
3371 |
while ((entry = findEntryByPath(config, kernel, prefix, &i))) { |
while ((entry = findEntryByPath(config, kernel, prefix, &i))) { |
3372 |
displayEntry(entry, prefix, i); |
displayEntry(config, entry, prefix, i); |
3373 |
i++; |
i++; |
3374 |
} |
} |
3375 |
|
|
3404 |
type & (LT_HYPER | LT_KERNEL | LT_MBMODULE | LT_INITRD | |
type & (LT_HYPER | LT_KERNEL | LT_MBMODULE | LT_INITRD | |
3405 |
LT_KERNEL_EFI | LT_INITRD_EFI | LT_KERNEL_16 | |
LT_KERNEL_EFI | LT_INITRD_EFI | LT_KERNEL_16 | |
3406 |
LT_INITRD_16)) { |
LT_INITRD_16)) { |
3407 |
char *rootspec = |
const char *prfx = tmplLine->elements[1].item; |
3408 |
getRootSpecifier(tmplLine->elements[1].item); |
size_t rs = getRootSpecifier(prfx); |
3409 |
if (rootspec != NULL) { |
if (isinitrd(tmplLine->type)) { |
3410 |
|
for (struct singleLine *l = entry->lines; |
3411 |
|
rs == 0 && l; l = l->next) { |
3412 |
|
if (iskernel(l->type)) { |
3413 |
|
prfx = l->elements[1].item; |
3414 |
|
rs = getRootSpecifier(prfx); |
3415 |
|
break; |
3416 |
|
} |
3417 |
|
} |
3418 |
|
} |
3419 |
|
if (rs > 0) { |
3420 |
free(newLine->elements[1].item); |
free(newLine->elements[1].item); |
3421 |
newLine->elements[1].item = |
newLine->elements[1].item = sdupprintf( |
3422 |
sdupprintf("%s%s", rootspec, val); |
"%.*s%s", (int) rs, prfx, val); |
3423 |
} |
} |
3424 |
} |
} |
3425 |
} |
} |
3709 |
line->numElements--; |
line->numElements--; |
3710 |
} |
} |
3711 |
|
|
3712 |
int argMatch(const char *one, const char *two) |
static int argNameMatch(const char *one, const char *two) |
3713 |
{ |
{ |
3714 |
char *first, *second; |
char *first, *second; |
3715 |
char *chptr; |
char *chptra, *chptrb; |
3716 |
|
int rc; |
3717 |
|
|
3718 |
first = strcpy(alloca(strlen(one) + 1), one); |
first = strcpy(alloca(strlen(one) + 1), one); |
3719 |
second = strcpy(alloca(strlen(two) + 1), two); |
second = strcpy(alloca(strlen(two) + 1), two); |
3720 |
|
|
3721 |
chptr = strchr(first, '='); |
chptra = strchr(first, '='); |
3722 |
if (chptr) |
if (chptra) |
3723 |
*chptr = '\0'; |
*chptra = '\0'; |
3724 |
|
|
3725 |
|
chptrb = strchr(second, '='); |
3726 |
|
if (chptrb) |
3727 |
|
*chptrb = '\0'; |
3728 |
|
|
3729 |
|
rc = strcmp(first, second); |
3730 |
|
|
3731 |
|
if (chptra) |
3732 |
|
*chptra = '='; |
3733 |
|
if (chptrb) |
3734 |
|
*chptrb = '='; |
3735 |
|
|
3736 |
chptr = strchr(second, '='); |
return rc; |
3737 |
|
} |
3738 |
|
|
3739 |
|
static int argHasValue(const char *arg) |
3740 |
|
{ |
3741 |
|
char *chptr; |
3742 |
|
|
3743 |
|
chptr = strchr(arg, '='); |
3744 |
if (chptr) |
if (chptr) |
3745 |
*chptr = '\0'; |
return 1; |
3746 |
|
return 0; |
3747 |
|
} |
3748 |
|
|
3749 |
|
static int argValueMatch(const char *one, const char *two) |
3750 |
|
{ |
3751 |
|
char *first, *second; |
3752 |
|
char *chptra, *chptrb; |
3753 |
|
|
3754 |
|
first = strcpy(alloca(strlen(one) + 1), one); |
3755 |
|
second = strcpy(alloca(strlen(two) + 1), two); |
3756 |
|
|
3757 |
return strcmp(first, second); |
chptra = strchr(first, '='); |
3758 |
|
if (chptra) |
3759 |
|
chptra += 1; |
3760 |
|
|
3761 |
|
chptrb = strchr(second, '='); |
3762 |
|
if (chptrb) |
3763 |
|
chptrb += 1; |
3764 |
|
|
3765 |
|
if (!chptra && !chptrb) |
3766 |
|
return 0; |
3767 |
|
else if (!chptra) |
3768 |
|
return *chptrb - 0; |
3769 |
|
else if (!chptrb) |
3770 |
|
return 0 - *chptra; |
3771 |
|
else |
3772 |
|
return strcmp(chptra, chptrb); |
3773 |
} |
} |
3774 |
|
|
3775 |
int updateActualImage(struct grubConfig *cfg, const char *image, |
int updateActualImage(struct grubConfig *cfg, const char *image, |
3913 |
} |
} |
3914 |
if (usedElements[i]) |
if (usedElements[i]) |
3915 |
continue; |
continue; |
3916 |
if (!argMatch(line->elements[i].item, *arg)) { |
if (!argNameMatch(line->elements[i].item, *arg)) { |
3917 |
usedElements[i] = 1; |
usedElements[i] = 1; |
3918 |
break; |
break; |
3919 |
} |
} |
3972 |
!strcmp(line->elements[i].item, "--")) |
!strcmp(line->elements[i].item, "--")) |
3973 |
/* reached the end of hyper args, stop here */ |
/* reached the end of hyper args, stop here */ |
3974 |
break; |
break; |
3975 |
if (!argMatch(line->elements[i].item, *arg)) { |
if (!argNameMatch(line->elements[i].item, *arg)) { |
3976 |
removeElement(line, i); |
if (!argHasValue(*arg) || |
3977 |
break; |
!argValueMatch(line->elements[i].item, *arg)) { |
3978 |
|
removeElement(line, i); |
3979 |
|
break; |
3980 |
|
} |
3981 |
} |
} |
3982 |
} |
} |
3983 |
/* handle removing LT_ROOT line too */ |
/* handle removing LT_ROOT line too */ |
4471 |
return 1; |
return 1; |
4472 |
} |
} |
4473 |
|
|
4474 |
static char *getRootSpecifier(char *str) |
static size_t getRootSpecifier(const char *str) |
4475 |
{ |
{ |
4476 |
char *idx, *rootspec = NULL; |
size_t rs = 0; |
4477 |
|
|
4478 |
if (*str == '(') { |
if (*str == '(') { |
4479 |
idx = rootspec = strdup(str); |
for (; str[rs] != ')' && !isspace(str[rs]); rs++) { |
4480 |
while (*idx && (*idx != ')') && (!isspace(*idx))) |
if (!str[rs]) |
4481 |
idx++; |
return rs; |
4482 |
*(++idx) = '\0'; |
} |
4483 |
|
rs++; |
4484 |
} |
} |
4485 |
return rootspec; |
|
4486 |
|
return rs + subvolPrefix(str + rs); |
4487 |
} |
} |
4488 |
|
|
4489 |
static char *getInitrdVal(struct grubConfig *config, |
static char *getInitrdVal(struct grubConfig *config, |
5115 |
{"mbargs", 0, POPT_ARG_STRING, &newMBKernelArgs, 0, |
{"mbargs", 0, POPT_ARG_STRING, &newMBKernelArgs, 0, |
5116 |
_("default arguments for the new multiboot kernel or " |
_("default arguments for the new multiboot kernel or " |
5117 |
"new arguments for multiboot kernel being updated"), NULL}, |
"new arguments for multiboot kernel being updated"), NULL}, |
5118 |
|
{"mounts", 0, POPT_ARG_STRING, &mounts, 0, |
5119 |
|
_("path to fake /proc/mounts file (for testing only)"), |
5120 |
|
_("mounts")}, |
5121 |
{"bad-image-okay", 0, 0, &badImageOkay, 0, |
{"bad-image-okay", 0, 0, &badImageOkay, 0, |
5122 |
_ |
_ |
5123 |
("don't sanity check images in boot entries (for testing only)"), |
("don't sanity check images in boot entries (for testing only)"), |
5226 |
exit(1); |
exit(1); |
5227 |
} |
} |
5228 |
saved_command_line[0] = '\0'; |
saved_command_line[0] = '\0'; |
5229 |
|
int cmdline_len = 0, arg_len; |
5230 |
for (int j = 1; j < argc; j++) { |
for (int j = 1; j < argc; j++) { |
5231 |
strcat(saved_command_line, argv[j]); |
arg_len = strlen(argv[j]); |
5232 |
strncat(saved_command_line, j == argc - 1 ? "" : " ", 1); |
memcpy(saved_command_line + cmdline_len, argv[j], arg_len); |
5233 |
|
cmdline_len += arg_len; |
5234 |
|
if (j != argc - 1) { |
5235 |
|
memcpy(saved_command_line + cmdline_len, " ", 1); |
5236 |
|
cmdline_len++; |
5237 |
|
} |
5238 |
|
|
5239 |
} |
} |
5240 |
|
saved_command_line[cmdline_len] = '\0'; |
5241 |
|
|
5242 |
optCon = poptGetContext("grubby", argc, argv, options, 0); |
optCon = poptGetContext("grubby", argc, argv, options, 0); |
5243 |
poptReadDefaultConfig(optCon, 1); |
poptReadDefaultConfig(optCon, 1); |
5310 |
if (!cfi) { |
if (!cfi) { |
5311 |
if (grub2FindConfig(&grub2ConfigType)) { |
if (grub2FindConfig(&grub2ConfigType)) { |
5312 |
cfi = &grub2ConfigType; |
cfi = &grub2ConfigType; |
5313 |
|
configureGrub2 = 1; |
5314 |
if (envPath) |
if (envPath) |
5315 |
cfi->envFile = envPath; |
cfi->envFile = envPath; |
5316 |
} else |
} else { |
5317 |
#ifdef __ia64__ |
#ifdef __ia64__ |
5318 |
cfi = &eliloConfigType; |
cfi = &eliloConfigType; |
5319 |
#elif __powerpc__ |
configureLilo = 1; |
5320 |
|
#elif defined(__powerpc__) |
5321 |
cfi = &yabootConfigType; |
cfi = &yabootConfigType; |
5322 |
#elif __sparc__ |
configureYaboot = 1; |
5323 |
|
#elif defined(__sparc__) |
5324 |
cfi = &siloConfigType; |
cfi = &siloConfigType; |
5325 |
#elif __s390__ |
configureSilo = 1; |
5326 |
|
#elif defined(__s390__) || defined(__s390x__) |
5327 |
cfi = &ziplConfigType; |
cfi = &ziplConfigType; |
5328 |
#elif __s390x__ |
configureZipl = 1; |
|
cfi = &ziplConfigtype; |
|
5329 |
#else |
#else |
5330 |
cfi = &grubConfigType; |
cfi = &grubConfigType; |
5331 |
|
configureGrub = 1; |
5332 |
#endif |
#endif |
5333 |
|
} |
5334 |
} |
} |
5335 |
|
|
5336 |
if (!grubConfig) { |
if (!grubConfig) { |
5524 |
if (displayDefault) { |
if (displayDefault) { |
5525 |
struct singleLine *line; |
struct singleLine *line; |
5526 |
struct singleEntry *entry; |
struct singleEntry *entry; |
5527 |
char *rootspec; |
size_t rs; |
5528 |
|
|
5529 |
if (config->defaultImage == NO_DEFAULT_ENTRY) |
if (config->defaultImage == NO_DEFAULT_ENTRY) |
5530 |
return 0; |
return 0; |
5543 |
if (!line) |
if (!line) |
5544 |
return 0; |
return 0; |
5545 |
|
|
5546 |
rootspec = getRootSpecifier(line->elements[1].item); |
rs = getRootSpecifier(line->elements[1].item); |
5547 |
printf("%s%s\n", bootPrefix, line->elements[1].item + |
printf("%s%s\n", bootPrefix, line->elements[1].item + rs); |
|
((rootspec != NULL) ? strlen(rootspec) : 0)); |
|
5548 |
|
|
5549 |
return 0; |
return 0; |
5550 |
|
|