243 |
} |
} |
244 |
|
|
245 |
int sizeOfSingleLine(struct singleLine * line) { |
int sizeOfSingleLine(struct singleLine * line) { |
|
int i; |
|
246 |
int count = 0; |
int count = 0; |
247 |
|
|
248 |
for (i = 0; i < line->numElements; i++) { |
for (int i = 0; i < line->numElements; i++) { |
249 |
int indentSize = 0; |
int indentSize = 0; |
250 |
|
|
251 |
count = count + strlen(line->elements[i].item); |
count = count + strlen(line->elements[i].item); |
264 |
return count; |
return count; |
265 |
} |
} |
266 |
|
|
267 |
|
static int isquote(char q) |
268 |
|
{ |
269 |
|
if (q == '\'' || q == '\"') |
270 |
|
return 1; |
271 |
|
return 0; |
272 |
|
} |
273 |
|
|
274 |
char *grub2ExtractTitle(struct singleLine * line) { |
char *grub2ExtractTitle(struct singleLine * line) { |
275 |
char * current; |
char * current; |
276 |
char * current_indent; |
char * current_indent; |
287 |
current_len = strlen(current); |
current_len = strlen(current); |
288 |
|
|
289 |
/* if second word is quoted, strip the quotes and return single word */ |
/* if second word is quoted, strip the quotes and return single word */ |
290 |
if ((*current == '\'') && (*(current + current_len - 1) == '\'')) { |
if (isquote(*current) && isquote(current[current_len - 1])) { |
291 |
char *tmp; |
char *tmp; |
292 |
|
|
293 |
tmp = strdup(current); |
tmp = strdup(current); |
294 |
*(tmp + current_len - 1) = '\0'; |
*(tmp + current_len - 1) = '\0'; |
295 |
return ++tmp; |
return ++tmp; |
296 |
} |
} |
297 |
|
|
298 |
/* if no quotes, return second word verbatim */ |
/* if no quotes, return second word verbatim */ |
299 |
if (*current != '\'') { |
if (!isquote(*current)) |
300 |
return current; |
return current; |
|
} |
|
301 |
|
|
302 |
/* second element start with a quote, so we have to find the element |
/* second element start with a quote, so we have to find the element |
303 |
* whose last character is also quote (assuming it's the closing one) */ |
* whose last character is also quote (assuming it's the closing one) */ |
304 |
if (*current == '\'') { |
int resultMaxSize; |
305 |
int resultMaxSize; |
char * result; |
306 |
char * result; |
|
307 |
|
resultMaxSize = sizeOfSingleLine(line); |
308 |
resultMaxSize = sizeOfSingleLine(line); |
result = malloc(resultMaxSize); |
309 |
result = malloc(resultMaxSize); |
snprintf(result, resultMaxSize, "%s", ++current); |
310 |
snprintf(result, resultMaxSize, "%s", ++current); |
|
311 |
|
i++; |
312 |
i++; |
for (; i < line->numElements; ++i) { |
|
for (; i < line->numElements; ++i) { |
|
313 |
current = line->elements[i].item; |
current = line->elements[i].item; |
314 |
current_len = strlen(current); |
current_len = strlen(current); |
315 |
current_indent = line->elements[i].indent; |
current_indent = line->elements[i].indent; |
316 |
current_indent_len = strlen(current_indent); |
current_indent_len = strlen(current_indent); |
317 |
|
|
318 |
strncat(result, current_indent, current_indent_len); |
strncat(result, current_indent, current_indent_len); |
319 |
if (*(current + current_len - 1) != '\'') { |
if (!isquote(current[current_len-1])) { |
320 |
strncat(result, current, current_len); |
strncat(result, current, current_len); |
321 |
} else { |
} else { |
322 |
strncat(result, current, current_len - 1); |
strncat(result, current, current_len - 1); |
323 |
break; |
break; |
324 |
} |
} |
|
} |
|
|
return result; |
|
325 |
} |
} |
326 |
|
return result; |
|
return NULL; |
|
327 |
} |
} |
328 |
|
|
329 |
struct configFileInfo grub2ConfigType = { |
struct configFileInfo grub2ConfigType = { |
572 |
|
|
573 |
static struct keywordTypes * getKeywordByType(enum lineType_e type, |
static struct keywordTypes * getKeywordByType(enum lineType_e type, |
574 |
struct configFileInfo * cfi) { |
struct configFileInfo * cfi) { |
575 |
struct keywordTypes * kw; |
for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) { |
|
for (kw = cfi->keywords; kw->key; kw++) { |
|
576 |
if (kw->type == type) |
if (kw->type == type) |
577 |
return kw; |
return kw; |
578 |
} |
} |
602 |
|
|
603 |
static enum lineType_e getTypeByKeyword(char * keyword, |
static enum lineType_e getTypeByKeyword(char * keyword, |
604 |
struct configFileInfo * cfi) { |
struct configFileInfo * cfi) { |
605 |
struct keywordTypes * kw; |
for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) { |
|
for (kw = cfi->keywords; kw->key; kw++) { |
|
606 |
if (!strcmp(keyword, kw->key)) |
if (!strcmp(keyword, kw->key)) |
607 |
return kw->type; |
return kw->type; |
608 |
} |
} |
689 |
} |
} |
690 |
|
|
691 |
struct singleLine * lineDup(struct singleLine * line) { |
struct singleLine * lineDup(struct singleLine * line) { |
|
int i; |
|
692 |
struct singleLine * newLine = malloc(sizeof(*newLine)); |
struct singleLine * newLine = malloc(sizeof(*newLine)); |
693 |
|
|
694 |
newLine->indent = strdup(line->indent); |
newLine->indent = strdup(line->indent); |
698 |
newLine->elements = malloc(sizeof(*newLine->elements) * |
newLine->elements = malloc(sizeof(*newLine->elements) * |
699 |
newLine->numElements); |
newLine->numElements); |
700 |
|
|
701 |
for (i = 0; i < newLine->numElements; i++) { |
for (int i = 0; i < newLine->numElements; i++) { |
702 |
newLine->elements[i].indent = strdup(line->elements[i].indent); |
newLine->elements[i].indent = strdup(line->elements[i].indent); |
703 |
newLine->elements[i].item = strdup(line->elements[i].item); |
newLine->elements[i].item = strdup(line->elements[i].item); |
704 |
} |
} |
707 |
} |
} |
708 |
|
|
709 |
static void lineFree(struct singleLine * line) { |
static void lineFree(struct singleLine * line) { |
|
int i; |
|
|
|
|
710 |
if (line->indent) free(line->indent); |
if (line->indent) free(line->indent); |
711 |
|
|
712 |
for (i = 0; i < line->numElements; i++) { |
for (int i = 0; i < line->numElements; i++) { |
713 |
free(line->elements[i].item); |
free(line->elements[i].item); |
714 |
free(line->elements[i].indent); |
free(line->elements[i].indent); |
715 |
} |
} |
720 |
|
|
721 |
static int lineWrite(FILE * out, struct singleLine * line, |
static int lineWrite(FILE * out, struct singleLine * line, |
722 |
struct configFileInfo * cfi) { |
struct configFileInfo * cfi) { |
|
int i; |
|
|
|
|
723 |
if (fprintf(out, "%s", line->indent) == -1) return -1; |
if (fprintf(out, "%s", line->indent) == -1) return -1; |
724 |
|
|
725 |
for (i = 0; i < line->numElements; i++) { |
for (int i = 0; i < line->numElements; i++) { |
726 |
|
/* Need to handle this, because we strip the quotes from |
727 |
|
* menuentry when read it. */ |
728 |
|
if (line->type == LT_MENUENTRY && i == 1) { |
729 |
|
if(!isquote(*line->elements[i].item)) |
730 |
|
fprintf(out, "\'%s\'", line->elements[i].item); |
731 |
|
else |
732 |
|
fprintf(out, "%s", line->elements[i].item); |
733 |
|
fprintf(out, "%s", line->elements[i].indent); |
734 |
|
|
735 |
|
continue; |
736 |
|
} |
737 |
|
|
738 |
if (i == 1 && line->type == LT_KERNELARGS && cfi->argsInQuotes) |
if (i == 1 && line->type == LT_KERNELARGS && cfi->argsInQuotes) |
739 |
if (fputc('"', out) == EOF) return -1; |
if (fputc('"', out) == EOF) return -1; |
740 |
|
|
828 |
if (*line->elements[0].item == '#') { |
if (*line->elements[0].item == '#') { |
829 |
char * fullLine; |
char * fullLine; |
830 |
int len; |
int len; |
|
int i; |
|
831 |
|
|
832 |
len = strlen(line->indent); |
len = strlen(line->indent); |
833 |
for (i = 0; i < line->numElements; i++) |
for (int i = 0; i < line->numElements; i++) |
834 |
len += strlen(line->elements[i].item) + |
len += strlen(line->elements[i].item) + |
835 |
strlen(line->elements[i].indent); |
strlen(line->elements[i].indent); |
836 |
|
|
839 |
free(line->indent); |
free(line->indent); |
840 |
line->indent = fullLine; |
line->indent = fullLine; |
841 |
|
|
842 |
for (i = 0; i < line->numElements; i++) { |
for (int i = 0; i < line->numElements; i++) { |
843 |
strcat(fullLine, line->elements[i].item); |
strcat(fullLine, line->elements[i].item); |
844 |
strcat(fullLine, line->elements[i].indent); |
strcat(fullLine, line->elements[i].indent); |
845 |
free(line->elements[i].item); |
free(line->elements[i].item); |
858 |
* elements up more |
* elements up more |
859 |
*/ |
*/ |
860 |
if (!isspace(kw->separatorChar)) { |
if (!isspace(kw->separatorChar)) { |
|
int i; |
|
861 |
char indent[2] = ""; |
char indent[2] = ""; |
862 |
indent[0] = kw->separatorChar; |
indent[0] = kw->separatorChar; |
863 |
for (i = 1; i < line->numElements; i++) { |
for (int i = 1; i < line->numElements; i++) { |
864 |
char *p; |
char *p; |
|
int j; |
|
865 |
int numNewElements; |
int numNewElements; |
866 |
|
|
867 |
numNewElements = 0; |
numNewElements = 0; |
877 |
sizeof(*line->elements) * elementsAlloced); |
sizeof(*line->elements) * elementsAlloced); |
878 |
} |
} |
879 |
|
|
880 |
for (j = line->numElements; j > i; j--) { |
for (int j = line->numElements; j > i; j--) { |
881 |
line->elements[j + numNewElements] = line->elements[j]; |
line->elements[j + numNewElements] = line->elements[j]; |
882 |
} |
} |
883 |
line->numElements += numNewElements; |
line->numElements += numNewElements; |
890 |
break; |
break; |
891 |
} |
} |
892 |
|
|
893 |
free(line->elements[i].indent); |
line->elements[i + 1].indent = line->elements[i].indent; |
894 |
line->elements[i].indent = strdup(indent); |
line->elements[i].indent = strdup(indent); |
895 |
*p++ = '\0'; |
*p++ = '\0'; |
896 |
i++; |
i++; |
897 |
line->elements[i].item = strdup(p); |
line->elements[i].item = strdup(p); |
|
line->elements[i].indent = strdup(""); |
|
|
p = line->elements[i].item; |
|
898 |
} |
} |
899 |
} |
} |
900 |
} |
} |
915 |
struct singleLine * last = NULL, * line, * defaultLine = NULL; |
struct singleLine * last = NULL, * line, * defaultLine = NULL; |
916 |
char * end; |
char * end; |
917 |
struct singleEntry * entry = NULL; |
struct singleEntry * entry = NULL; |
918 |
int i, len; |
int len; |
919 |
char * buf; |
char * buf; |
920 |
|
|
921 |
if (!strcmp(inName, "-")) { |
if (!strcmp(inName, "-")) { |
978 |
} |
} |
979 |
|
|
980 |
if (line->type == LT_SET_VARIABLE) { |
if (line->type == LT_SET_VARIABLE) { |
|
int i; |
|
981 |
dbgPrintf("found 'set' command (%d elements): ", line->numElements); |
dbgPrintf("found 'set' command (%d elements): ", line->numElements); |
982 |
dbgPrintf("%s", line->indent); |
dbgPrintf("%s", line->indent); |
983 |
for (i = 0; i < line->numElements; i++) |
for (int i = 0; i < line->numElements; i++) |
984 |
dbgPrintf("%s\"%s\"", line->elements[i].indent, line->elements[i].item); |
dbgPrintf("\"%s\"%s", line->elements[i].item, line->elements[i].indent); |
985 |
dbgPrintf("\n"); |
dbgPrintf("\n"); |
986 |
struct keywordTypes *kwType = getKeywordByType(LT_DEFAULT, cfi); |
struct keywordTypes *kwType = getKeywordByType(LT_DEFAULT, cfi); |
987 |
if (kwType && line->numElements == 3 && |
if (kwType && line->numElements == 3 && |
1008 |
* This only applies to grub, but that's the only place we |
* This only applies to grub, but that's the only place we |
1009 |
* should find LT_MBMODULE lines anyway. |
* should find LT_MBMODULE lines anyway. |
1010 |
*/ |
*/ |
1011 |
struct singleLine * l; |
for (struct singleLine *l = entry->lines; l; l = l->next) { |
|
for (l = entry->lines; l; l = l->next) { |
|
1012 |
if (l->type == LT_HYPER) |
if (l->type == LT_HYPER) |
1013 |
break; |
break; |
1014 |
else if (l->type == LT_KERNEL) { |
else if (l->type == LT_KERNEL) { |
1028 |
} else if (line->type == LT_TITLE && line->numElements > 1) { |
} else if (line->type == LT_TITLE && line->numElements > 1) { |
1029 |
/* make the title a single argument (undoing our parsing) */ |
/* make the title a single argument (undoing our parsing) */ |
1030 |
len = 0; |
len = 0; |
1031 |
for (i = 1; i < line->numElements; i++) { |
for (int i = 1; i < line->numElements; i++) { |
1032 |
len += strlen(line->elements[i].item); |
len += strlen(line->elements[i].item); |
1033 |
len += strlen(line->elements[i].indent); |
len += strlen(line->elements[i].indent); |
1034 |
} |
} |
1035 |
buf = malloc(len + 1); |
buf = malloc(len + 1); |
1036 |
*buf = '\0'; |
*buf = '\0'; |
1037 |
|
|
1038 |
for (i = 1; i < line->numElements; i++) { |
for (int i = 1; i < line->numElements; i++) { |
1039 |
strcat(buf, line->elements[i].item); |
strcat(buf, line->elements[i].item); |
1040 |
free(line->elements[i].item); |
free(line->elements[i].item); |
1041 |
|
|
1049 |
line->elements[line->numElements - 1].indent; |
line->elements[line->numElements - 1].indent; |
1050 |
line->elements[1].item = buf; |
line->elements[1].item = buf; |
1051 |
line->numElements = 2; |
line->numElements = 2; |
1052 |
|
} else if (line->type == LT_MENUENTRY && line->numElements > 3) { |
1053 |
|
/* let --remove-kernel="TITLE=what" work */ |
1054 |
|
len = 0; |
1055 |
|
char *extras; |
1056 |
|
char *title; |
1057 |
|
|
1058 |
|
for (int i = 1; i < line->numElements; i++) { |
1059 |
|
len += strlen(line->elements[i].item); |
1060 |
|
len += strlen(line->elements[i].indent); |
1061 |
|
} |
1062 |
|
buf = malloc(len + 1); |
1063 |
|
*buf = '\0'; |
1064 |
|
|
1065 |
|
/* allocate mem for extra flags. */ |
1066 |
|
extras = malloc(len + 1); |
1067 |
|
*extras = '\0'; |
1068 |
|
|
1069 |
|
/* get title. */ |
1070 |
|
for (int i = 0; i < line->numElements; i++) { |
1071 |
|
if (!strcmp(line->elements[i].item, "menuentry")) |
1072 |
|
continue; |
1073 |
|
if (isquote(*line->elements[i].item)) |
1074 |
|
title = line->elements[i].item + 1; |
1075 |
|
else |
1076 |
|
title = line->elements[i].item; |
1077 |
|
|
1078 |
|
len = strlen(title); |
1079 |
|
if (isquote(title[len-1])) { |
1080 |
|
strncat(buf, title,len-1); |
1081 |
|
break; |
1082 |
|
} else { |
1083 |
|
strcat(buf, title); |
1084 |
|
strcat(buf, line->elements[i].indent); |
1085 |
|
} |
1086 |
|
} |
1087 |
|
|
1088 |
|
/* get extras */ |
1089 |
|
int count = 0; |
1090 |
|
for (int i = 0; i < line->numElements; i++) { |
1091 |
|
if (count >= 2) { |
1092 |
|
strcat(extras, line->elements[i].item); |
1093 |
|
strcat(extras, line->elements[i].indent); |
1094 |
|
} |
1095 |
|
|
1096 |
|
if (!strcmp(line->elements[i].item, "menuentry")) |
1097 |
|
continue; |
1098 |
|
|
1099 |
|
/* count ' or ", there should be two in menuentry line. */ |
1100 |
|
if (isquote(*line->elements[i].item)) |
1101 |
|
count++; |
1102 |
|
|
1103 |
|
len = strlen(line->elements[i].item); |
1104 |
|
|
1105 |
|
if (isquote(line->elements[i].item[len -1])) |
1106 |
|
count++; |
1107 |
|
|
1108 |
|
/* ok, we get the final ' or ", others are extras. */ |
1109 |
|
} |
1110 |
|
line->elements[1].indent = |
1111 |
|
line->elements[line->numElements - 2].indent; |
1112 |
|
line->elements[1].item = buf; |
1113 |
|
line->elements[2].indent = |
1114 |
|
line->elements[line->numElements - 2].indent; |
1115 |
|
line->elements[2].item = extras; |
1116 |
|
line->numElements = 3; |
1117 |
} else if (line->type == LT_KERNELARGS && cfi->argsInQuotes) { |
} else if (line->type == LT_KERNELARGS && cfi->argsInQuotes) { |
1118 |
/* Strip off any " which may be present; they'll be put back |
/* Strip off any " which may be present; they'll be put back |
1119 |
on write. This is one of the few (the only?) places that grubby |
on write. This is one of the few (the only?) places that grubby |
1122 |
if (line->numElements >= 2) { |
if (line->numElements >= 2) { |
1123 |
int last, len; |
int last, len; |
1124 |
|
|
1125 |
if (*line->elements[1].item == '"') |
if (isquote(*line->elements[1].item)) |
1126 |
memmove(line->elements[1].item, line->elements[1].item + 1, |
memmove(line->elements[1].item, line->elements[1].item + 1, |
1127 |
strlen(line->elements[1].item + 1) + 1); |
strlen(line->elements[1].item + 1) + 1); |
1128 |
|
|
1129 |
last = line->numElements - 1; |
last = line->numElements - 1; |
1130 |
len = strlen(line->elements[last].item) - 1; |
len = strlen(line->elements[last].item) - 1; |
1131 |
if (line->elements[last].item[len] == '"') |
if (isquote(line->elements[last].item[len])) |
1132 |
line->elements[last].item[len] = '\0'; |
line->elements[last].item[len] = '\0'; |
1133 |
} |
} |
1134 |
} |
} |
1208 |
cfg->defaultImage = strtol(defaultLine->elements[1].item, &end, 10); |
cfg->defaultImage = strtol(defaultLine->elements[1].item, &end, 10); |
1209 |
if (*end) cfg->defaultImage = -1; |
if (*end) cfg->defaultImage = -1; |
1210 |
} else if (defaultLine->numElements >= 2) { |
} else if (defaultLine->numElements >= 2) { |
1211 |
i = 0; |
int i = 0; |
1212 |
while ((entry = findEntryByIndex(cfg, i))) { |
while ((entry = findEntryByIndex(cfg, i))) { |
1213 |
for (line = entry->lines; line; line = line->next) |
for (line = entry->lines; line; line = line->next) |
1214 |
if (line->type == LT_TITLE) break; |
if (line->type == LT_TITLE) break; |
1310 |
|
|
1311 |
/* most likely the symlink is relative, so change our |
/* most likely the symlink is relative, so change our |
1312 |
directory to the dir of the symlink */ |
directory to the dir of the symlink */ |
1313 |
rc = chdir(dirname(strdupa(outName))); |
rc = chdir(dirname(outName)); |
1314 |
do { |
do { |
1315 |
buf = alloca(len + 1); |
buf = alloca(len + 1); |
1316 |
rc = readlink(basename(outName), buf, len); |
rc = readlink(basename(outName), buf, len); |
1448 |
buf[rc] = '\0'; |
buf[rc] = '\0'; |
1449 |
chptr = buf; |
chptr = buf; |
1450 |
|
|
1451 |
|
char *foundanswer = NULL; |
1452 |
|
|
1453 |
while (chptr && chptr != buf+rc) { |
while (chptr && chptr != buf+rc) { |
1454 |
devname = chptr; |
devname = chptr; |
1455 |
|
|
1477 |
* for '/' obviously. |
* for '/' obviously. |
1478 |
*/ |
*/ |
1479 |
if (*(++chptr) == '/' && *(++chptr) == ' ') { |
if (*(++chptr) == '/' && *(++chptr) == ' ') { |
1480 |
/* |
/* remember the last / entry in mtab */ |
1481 |
* Move back 2, which is the first space after the device name, set |
foundanswer = devname; |
|
* it to \0 so strdup will just get the devicename. |
|
|
*/ |
|
|
chptr -= 2; |
|
|
*chptr = '\0'; |
|
|
return strdup(devname); |
|
1482 |
} |
} |
1483 |
|
|
1484 |
/* Next line */ |
/* Next line */ |
1487 |
chptr++; |
chptr++; |
1488 |
} |
} |
1489 |
|
|
1490 |
|
/* Return the last / entry found */ |
1491 |
|
if (foundanswer) { |
1492 |
|
chptr = strchr(foundanswer, ' '); |
1493 |
|
*chptr = '\0'; |
1494 |
|
return strdup(foundanswer); |
1495 |
|
} |
1496 |
|
|
1497 |
return NULL; |
return NULL; |
1498 |
} |
} |
1499 |
|
|
1504 |
for (line = entry->lines; line; line = line->next) { |
for (line = entry->lines; line; line = line->next) { |
1505 |
fprintf(stderr, "DBG: %s", line->indent); |
fprintf(stderr, "DBG: %s", line->indent); |
1506 |
for (i = 0; i < line->numElements; i++) { |
for (i = 0; i < line->numElements; i++) { |
1507 |
fprintf(stderr, "%s%s", |
/* Need to handle this, because we strip the quotes from |
1508 |
|
* menuentry when read it. */ |
1509 |
|
if (line->type == LT_MENUENTRY && i == 1) { |
1510 |
|
if(!isquote(*line->elements[i].item)) |
1511 |
|
fprintf(stderr, "\'%s\'", line->elements[i].item); |
1512 |
|
else |
1513 |
|
fprintf(stderr, "%s", line->elements[i].item); |
1514 |
|
fprintf(stderr, "%s", line->elements[i].indent); |
1515 |
|
|
1516 |
|
continue; |
1517 |
|
} |
1518 |
|
|
1519 |
|
fprintf(stderr, "%s%s", |
1520 |
line->elements[i].item, line->elements[i].indent); |
line->elements[i].item, line->elements[i].indent); |
1521 |
} |
} |
1522 |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
1543 |
{ |
{ |
1544 |
int slen; |
int slen; |
1545 |
|
|
1546 |
if (!s && !s[0]) |
if (!s || !s[0]) |
1547 |
return 0; |
return 0; |
1548 |
slen = strlen(s) - 1; |
slen = strlen(s) - 1; |
1549 |
|
|
1732 |
|
|
1733 |
if (!strncmp(kernel, "TITLE=", 6)) { |
if (!strncmp(kernel, "TITLE=", 6)) { |
1734 |
prefix = ""; |
prefix = ""; |
1735 |
checkType = LT_TITLE; |
checkType = LT_TITLE|LT_MENUENTRY; |
1736 |
kernel += 6; |
kernel += 6; |
1737 |
} |
} |
1738 |
|
|
1748 |
checkType, line); |
checkType, line); |
1749 |
if (!line) break; /* not found in this entry */ |
if (!line) break; /* not found in this entry */ |
1750 |
|
|
1751 |
if (line && line->numElements >= 2) { |
if (line && line->type != LT_MENUENTRY && |
1752 |
|
line->numElements >= 2) { |
1753 |
rootspec = getRootSpecifier(line->elements[1].item); |
rootspec = getRootSpecifier(line->elements[1].item); |
1754 |
if (!strcmp(line->elements[1].item + |
if (!strcmp(line->elements[1].item + |
1755 |
((rootspec != NULL) ? strlen(rootspec) : 0), |
((rootspec != NULL) ? strlen(rootspec) : 0), |
1756 |
kernel + strlen(prefix))) |
kernel + strlen(prefix))) |
1757 |
break; |
break; |
1758 |
} |
} |
1759 |
|
if(line->type == LT_MENUENTRY && |
1760 |
|
!strcmp(line->elements[1].item, kernel)) |
1761 |
|
break; |
1762 |
} |
} |
1763 |
|
|
1764 |
/* make sure this entry has a kernel identifier; this skips |
/* make sure this entry has a kernel identifier; this skips |
1850 |
const char * prefix) { |
const char * prefix) { |
1851 |
struct singleEntry * entry; |
struct singleEntry * entry; |
1852 |
|
|
1853 |
if (!image) return; |
if (!image) |
1854 |
|
return; |
1855 |
|
|
1856 |
|
/* check and see if we're removing the default image */ |
1857 |
|
if (isdigit(*image)) { |
1858 |
|
entry = findEntryByPath(cfg, image, prefix, NULL); |
1859 |
|
if(entry) |
1860 |
|
entry->skip = 1; |
1861 |
|
return; |
1862 |
|
} |
1863 |
|
|
1864 |
while ((entry = findEntryByPath(cfg, image, prefix, NULL))) |
while ((entry = findEntryByPath(cfg, image, prefix, NULL))) |
1865 |
entry->skip = 1; |
entry->skip = 1; |
1954 |
return; |
return; |
1955 |
} |
} |
1956 |
|
|
1957 |
printf("kernel=%s%s\n", prefix, line->elements[1].item); |
if (!strncmp(prefix, line->elements[1].item, strlen(prefix))) |
1958 |
|
printf("kernel=%s\n", line->elements[1].item); |
1959 |
|
else |
1960 |
|
printf("kernel=%s%s\n", prefix, line->elements[1].item); |
1961 |
|
|
1962 |
if (line->numElements >= 3) { |
if (line->numElements >= 3) { |
1963 |
printf("args=\""); |
printf("args=\""); |
2016 |
line = getLineByType(LT_INITRD, entry->lines); |
line = getLineByType(LT_INITRD, entry->lines); |
2017 |
|
|
2018 |
if (line && line->numElements >= 2) { |
if (line && line->numElements >= 2) { |
2019 |
printf("initrd=%s", prefix); |
if (!strncmp(prefix, line->elements[1].item, strlen(prefix))) |
2020 |
|
printf("initrd="); |
2021 |
|
else |
2022 |
|
printf("initrd=%s", prefix); |
2023 |
|
|
2024 |
for (i = 1; i < line->numElements; i++) |
for (i = 1; i < line->numElements; i++) |
2025 |
printf("%s%s", line->elements[i].item, line->elements[i].indent); |
printf("%s%s", line->elements[i].item, line->elements[i].indent); |
2026 |
printf("\n"); |
printf("\n"); |
2027 |
} |
} |
2028 |
|
|
2029 |
|
line = getLineByType(LT_TITLE, entry->lines); |
2030 |
|
if (line) { |
2031 |
|
printf("title=%s\n", line->elements[1].item); |
2032 |
|
} else { |
2033 |
|
char * title; |
2034 |
|
line = getLineByType(LT_MENUENTRY, entry->lines); |
2035 |
|
title = grub2ExtractTitle(line); |
2036 |
|
if (title) |
2037 |
|
printf("title=%s\n", title); |
2038 |
|
} |
2039 |
} |
} |
2040 |
|
|
2041 |
int parseSysconfigGrub(int * lbaPtr, char ** bootPtr) { |
int parseSysconfigGrub(int * lbaPtr, char ** bootPtr) { |
2290 |
free(line); |
free(line); |
2291 |
} |
} |
2292 |
|
|
|
static int isquote(char q) |
|
|
{ |
|
|
if (q == '\'' || q == '\"') |
|
|
return 1; |
|
|
return 0; |
|
|
} |
|
|
|
|
2293 |
static void requote(struct singleLine *tmplLine, struct configFileInfo * cfi) |
static void requote(struct singleLine *tmplLine, struct configFileInfo * cfi) |
2294 |
{ |
{ |
2295 |
struct singleLine newLine = { |
struct singleLine newLine = { |
2973 |
static char * getInitrdVal(struct grubConfig * config, |
static char * getInitrdVal(struct grubConfig * config, |
2974 |
const char * prefix, struct singleLine *tmplLine, |
const char * prefix, struct singleLine *tmplLine, |
2975 |
const char * newKernelInitrd, |
const char * newKernelInitrd, |
2976 |
char ** extraInitrds, int extraInitrdCount) |
const char ** extraInitrds, int extraInitrdCount) |
2977 |
{ |
{ |
2978 |
char *initrdVal, *end; |
char *initrdVal, *end; |
2979 |
int i; |
int i; |
3018 |
|
|
3019 |
int addNewKernel(struct grubConfig * config, struct singleEntry * template, |
int addNewKernel(struct grubConfig * config, struct singleEntry * template, |
3020 |
const char * prefix, |
const char * prefix, |
3021 |
char * newKernelPath, char * newKernelTitle, |
const char * newKernelPath, const char * newKernelTitle, |
3022 |
char * newKernelArgs, char * newKernelInitrd, |
const char * newKernelArgs, const char * newKernelInitrd, |
3023 |
char ** extraInitrds, int extraInitrdCount, |
const char ** extraInitrds, int extraInitrdCount, |
3024 |
char * newMBKernel, char * newMBKernelArgs) { |
const char * newMBKernel, const char * newMBKernelArgs) { |
3025 |
struct singleEntry * new; |
struct singleEntry * new; |
3026 |
struct singleLine * newLine = NULL, * tmplLine = NULL, * masterLine = NULL; |
struct singleLine * newLine = NULL, * tmplLine = NULL, * masterLine = NULL; |
3027 |
int needs; |
int needs; |
3583 |
} |
} |
3584 |
|
|
3585 |
if (!cfi) { |
if (!cfi) { |
3586 |
|
if (grub2FindConfig(&grub2ConfigType)) |
3587 |
|
cfi = &grub2ConfigType; |
3588 |
|
else |
3589 |
#ifdef __ia64__ |
#ifdef __ia64__ |
3590 |
cfi = &eliloConfigType; |
cfi = &eliloConfigType; |
3591 |
#elif __powerpc__ |
#elif __powerpc__ |
3592 |
cfi = &yabootConfigType; |
cfi = &yabootConfigType; |
3593 |
#elif __sparc__ |
#elif __sparc__ |
3594 |
cfi = &siloConfigType; |
cfi = &siloConfigType; |
3595 |
#elif __s390__ |
#elif __s390__ |
3596 |
cfi = &ziplConfigType; |
cfi = &ziplConfigType; |
3597 |
#elif __s390x__ |
#elif __s390x__ |
3598 |
cfi = &ziplConfigtype; |
cfi = &ziplConfigtype; |
3599 |
#else |
#else |
|
if (grub2FindConfig(&grub2ConfigType)) |
|
|
cfi = &grub2ConfigType; |
|
|
else |
|
3600 |
cfi = &grubConfigType; |
cfi = &grubConfigType; |
3601 |
#endif |
#endif |
3602 |
} |
} |
3807 |
} |
} |
3808 |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
3809 |
newKernelTitle, newKernelArgs, newKernelInitrd, |
newKernelTitle, newKernelArgs, newKernelInitrd, |
3810 |
extraInitrds, extraInitrdCount, |
(const char **)extraInitrds, extraInitrdCount, |
3811 |
newMBKernel, newMBKernelArgs)) return 1; |
newMBKernel, newMBKernelArgs)) return 1; |
3812 |
|
|
3813 |
|
|