Magellan Linux

Diff of /tags/grubby-8_32/grubby.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2058 by niro, Wed Feb 20 14:06:30 2013 UTC revision 2236 by niro, Mon Oct 21 13:19:07 2013 UTC
# Line 36  Line 36 
36  #include <signal.h>  #include <signal.h>
37  #include <blkid/blkid.h>  #include <blkid/blkid.h>
38    
39    #include "log.h"
40    
41  #ifndef DEBUG  #ifndef DEBUG
42  #define DEBUG 0  #define DEBUG 0
43  #endif  #endif
# Line 58  int debug = 0; /* Currently just for tem Line 60  int debug = 0; /* Currently just for tem
60    
61  int isEfi = 0;  int isEfi = 0;
62    
63    char *saved_command_line = NULL;
64    
65  /* comments get lumped in with indention */  /* comments get lumped in with indention */
66  struct lineElement {  struct lineElement {
67      char * item;      char * item;
# Line 1534  static char *findDiskForRoot() Line 1538  static char *findDiskForRoot()
1538      return NULL;      return NULL;
1539  }  }
1540    
1541  void printEntry(struct singleEntry * entry) {  void printEntry(struct singleEntry * entry, FILE *f) {
1542      int i;      int i;
1543      struct singleLine * line;      struct singleLine * line;
1544    
1545      for (line = entry->lines; line; line = line->next) {      for (line = entry->lines; line; line = line->next) {
1546   fprintf(stderr, "DBG: %s", line->indent);   log_message(f, "DBG: %s", line->indent);
1547   for (i = 0; i < line->numElements; i++) {   for (i = 0; i < line->numElements; i++) {
1548      /* Need to handle this, because we strip the quotes from      /* Need to handle this, because we strip the quotes from
1549       * menuentry when read it. */       * menuentry when read it. */
1550      if (line->type == LT_MENUENTRY && i == 1) {      if (line->type == LT_MENUENTRY && i == 1) {
1551   if(!isquote(*line->elements[i].item))   if(!isquote(*line->elements[i].item))
1552      fprintf(stderr, "\'%s\'", line->elements[i].item);      log_message(f, "\'%s\'", line->elements[i].item);
1553   else   else
1554      fprintf(stderr, "%s", line->elements[i].item);      log_message(f, "%s", line->elements[i].item);
1555   fprintf(stderr, "%s", line->elements[i].indent);   log_message(f, "%s", line->elements[i].indent);
1556    
1557   continue;   continue;
1558      }      }
1559            
1560      fprintf(stderr, "%s%s",      log_message(f, "%s%s",
1561      line->elements[i].item, line->elements[i].indent);      line->elements[i].item, line->elements[i].indent);
1562   }   }
1563   fprintf(stderr, "\n");   log_message(f, "\n");
1564      }      }
1565  }  }
1566    
1567  void notSuitablePrintf(struct singleEntry * entry, const char *fmt, ...)  void notSuitablePrintf(struct singleEntry * entry, int okay, const char *fmt, ...)
1568  {  {
1569      va_list argp;      static int once;
1570        va_list argp, argq;
1571    
1572      if (!debug)      va_start(argp, fmt);
1573    
1574        va_copy(argq, argp);
1575        if (!once) {
1576     log_time(NULL);
1577     log_message(NULL, "command line: %s\n", saved_command_line);
1578        }
1579        log_message(NULL, "DBG: Image entry %s: ", okay ? "succeeded" : "failed");
1580        log_vmessage(NULL, fmt, argq);
1581    
1582        printEntry(entry, NULL);
1583        va_end(argq);
1584    
1585        if (!debug) {
1586     once = 1;
1587         va_end(argp);
1588   return;   return;
1589        }
1590    
1591      va_start(argp, fmt);      if (okay) {
1592     va_end(argp);
1593     return;
1594        }
1595    
1596        if (!once)
1597     log_message(stderr, "DBG: command line: %s\n", saved_command_line);
1598        once = 1;
1599      fprintf(stderr, "DBG: Image entry failed: ");      fprintf(stderr, "DBG: Image entry failed: ");
1600      vfprintf(stderr, fmt, argp);      vfprintf(stderr, fmt, argp);
1601      printEntry(entry);      printEntry(entry, stderr);
1602      va_end(argp);      va_end(argp);
1603  }  }
1604    
# Line 1597  int suitableImage(struct singleEntry * e Line 1625  int suitableImage(struct singleEntry * e
1625      char * rootdev;      char * rootdev;
1626    
1627      if (skipRemoved && entry->skip) {      if (skipRemoved && entry->skip) {
1628   notSuitablePrintf(entry, "marked to skip\n");   notSuitablePrintf(entry, 0, "marked to skip\n");
1629   return 0;   return 0;
1630      }      }
1631    
1632      line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines);      line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines);
1633      if (!line) {      if (!line) {
1634   notSuitablePrintf(entry, "no line found\n");   notSuitablePrintf(entry, 0, "no line found\n");
1635   return 0;   return 0;
1636      }      }
1637      if (line->numElements < 2) {      if (line->numElements < 2) {
1638   notSuitablePrintf(entry, "line has only %d elements\n",   notSuitablePrintf(entry, 0, "line has only %d elements\n",
1639      line->numElements);      line->numElements);
1640   return 0;   return 0;
1641      }      }
1642    
1643      if (flags & GRUBBY_BADIMAGE_OKAY) return 1;      if (flags & GRUBBY_BADIMAGE_OKAY) {
1644        notSuitablePrintf(entry, 1, "\n");
1645        return 1;
1646        }
1647    
1648      fullName = alloca(strlen(bootPrefix) +      fullName = alloca(strlen(bootPrefix) +
1649        strlen(line->elements[1].item) + 1);        strlen(line->elements[1].item) + 1);
# Line 1623  int suitableImage(struct singleEntry * e Line 1654  int suitableImage(struct singleEntry * e
1654      sprintf(fullName, "%s%s%s", bootPrefix, hasslash ? "" : "/",      sprintf(fullName, "%s%s%s", bootPrefix, hasslash ? "" : "/",
1655              line->elements[1].item + rootspec_offset);              line->elements[1].item + rootspec_offset);
1656      if (access(fullName, R_OK)) {      if (access(fullName, R_OK)) {
1657   notSuitablePrintf(entry, "access to %s failed\n", fullName);   notSuitablePrintf(entry, 0, "access to %s failed\n", fullName);
1658   return 0;   return 0;
1659      }      }
1660      for (i = 2; i < line->numElements; i++)      for (i = 2; i < line->numElements; i++)
# Line 1644  int suitableImage(struct singleEntry * e Line 1675  int suitableImage(struct singleEntry * e
1675    
1676              /* failed to find one */              /* failed to find one */
1677              if (!line) {              if (!line) {
1678   notSuitablePrintf(entry, "no line found\n");   notSuitablePrintf(entry, 0, "no line found\n");
1679   return 0;   return 0;
1680              }              }
1681    
# Line 1653  int suitableImage(struct singleEntry * e Line 1684  int suitableImage(struct singleEntry * e
1684      if (i < line->numElements)      if (i < line->numElements)
1685          dev = line->elements[i].item + 5;          dev = line->elements[i].item + 5;
1686      else {      else {
1687   notSuitablePrintf(entry, "no root= entry found\n");   notSuitablePrintf(entry, 0, "no root= entry found\n");
1688   /* it failed too...  can't find root= */   /* it failed too...  can't find root= */
1689          return 0;          return 0;
1690              }              }
# Line 1662  int suitableImage(struct singleEntry * e Line 1693  int suitableImage(struct singleEntry * e
1693    
1694      dev = getpathbyspec(dev);      dev = getpathbyspec(dev);
1695      if (!getpathbyspec(dev)) {      if (!getpathbyspec(dev)) {
1696          notSuitablePrintf(entry, "can't find blkid entry for %s\n", dev);          notSuitablePrintf(entry, 0, "can't find blkid entry for %s\n", dev);
1697          return 0;          return 0;
1698      } else      } else
1699   dev = getpathbyspec(dev);   dev = getpathbyspec(dev);
1700    
1701      rootdev = findDiskForRoot();      rootdev = findDiskForRoot();
1702      if (!rootdev) {      if (!rootdev) {
1703          notSuitablePrintf(entry, "can't find root device\n");          notSuitablePrintf(entry, 0, "can't find root device\n");
1704   return 0;   return 0;
1705      }      }
1706    
1707      if (!getuuidbydev(rootdev) || !getuuidbydev(dev)) {      if (!getuuidbydev(rootdev) || !getuuidbydev(dev)) {
1708          notSuitablePrintf(entry, "uuid missing: rootdev %s, dev %s\n",          notSuitablePrintf(entry, 0, "uuid missing: rootdev %s, dev %s\n",
1709   getuuidbydev(rootdev), getuuidbydev(dev));   getuuidbydev(rootdev), getuuidbydev(dev));
1710          free(rootdev);          free(rootdev);
1711          return 0;          return 0;
1712      }      }
1713    
1714      if (strcmp(getuuidbydev(rootdev), getuuidbydev(dev))) {      if (strcmp(getuuidbydev(rootdev), getuuidbydev(dev))) {
1715          notSuitablePrintf(entry, "uuid mismatch: rootdev %s, dev %s\n",          notSuitablePrintf(entry, 0, "uuid mismatch: rootdev %s, dev %s\n",
1716   getuuidbydev(rootdev), getuuidbydev(dev));   getuuidbydev(rootdev), getuuidbydev(dev));
1717   free(rootdev);   free(rootdev);
1718          return 0;          return 0;
1719      }      }
1720    
1721      free(rootdev);      free(rootdev);
1722        notSuitablePrintf(entry, 1, "\n");
1723    
1724      return 1;      return 1;
1725  }  }
# Line 3899  int main(int argc, const char ** argv) { Line 3931  int main(int argc, const char ** argv) {
3931    
3932      signal(SIGSEGV, traceback);      signal(SIGSEGV, traceback);
3933    
3934        int i = 0;
3935        for (int j = 1; j < argc; j++)
3936     i += strlen(argv[j]) + 1;
3937        saved_command_line = malloc(i);
3938        if (!saved_command_line) {
3939     fprintf(stderr, "grubby: %m\n");
3940     exit(1);
3941        }
3942        saved_command_line[0] = '\0';
3943        for (int j = 1; j < argc; j++) {
3944     strcat(saved_command_line, argv[j]);
3945     strncat(saved_command_line, j == argc -1 ? "" : " ", 1);
3946        }
3947    
3948      optCon = poptGetContext("grubby", argc, argv, options, 0);      optCon = poptGetContext("grubby", argc, argv, options, 0);
3949      poptReadDefaultConfig(optCon, 1);      poptReadDefaultConfig(optCon, 1);
3950    

Legend:
Removed from v.2058  
changed lines
  Added in v.2236