Advertisement
Guest User

3325_codestyle.diff

a guest
Feb 17th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.73 KB | None | 0 0
  1. diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
  2. index a96514ea8ca..3f4da817a0c 100644
  3. --- a/src/backend/utils/init/miscinit.c
  4. +++ b/src/backend/utils/init/miscinit.c
  5. @@ -1460,25 +1460,14 @@ RecheckDataDirLockFile(void)
  6.   *-------------------------------------------------------------------------
  7.   */
  8.  
  9. -/*
  10. - * Determine whether the PG_VERSION file in directory `path' indicates
  11. - * a data version compatible with the version of this program.
  12. - *
  13. - * If compatible, return. Otherwise, ereport(FATAL).
  14. - */
  15. -void
  16. -ValidatePgVersion(const char *path)
  17. +long
  18. +ReadPgVersionFromFile(const char *path, char *file_version_string)
  19.  {
  20.     char        full_path[MAXPGPATH];
  21.     FILE       *file;
  22.     int         ret;
  23. -   long        file_major;
  24. -   long        my_major;
  25.     char       *endptr;
  26. -   char        file_version_string[64];
  27. -   const char *my_version_string = PG_VERSION;
  28. -
  29. -   my_major = strtol(my_version_string, &endptr, 10);
  30. +   long        major;
  31.  
  32.     snprintf(full_path, sizeof(full_path), "%s/PG_VERSION", path);
  33.  
  34. @@ -1499,7 +1488,7 @@ ValidatePgVersion(const char *path)
  35.  
  36.     file_version_string[0] = '\0';
  37.     ret = fscanf(file, "%63s", file_version_string);
  38. -   file_major = strtol(file_version_string, &endptr, 10);
  39. +   major = strtol(file_version_string, &endptr, 10);
  40.  
  41.     if (ret != 1 || endptr == file_version_string)
  42.         ereport(FATAL,
  43. @@ -1511,6 +1500,20 @@ ValidatePgVersion(const char *path)
  44.                  errhint("You might need to initdb.")));
  45.  
  46.     FreeFile(file);
  47. +   return major;
  48. +}
  49. +
  50. +void
  51. +ValidatePgVersion(const char *path)
  52. +{
  53. +   long        file_major;
  54. +   long        my_major;
  55. +   char       *endptr;
  56. +   char        file_version_string[PG_VERSION_STRING_MAXLEN];
  57. +   const char *my_version_string = PG_VERSION;
  58. +
  59. +   my_major = strtol(my_version_string, &endptr, 10);
  60. +   file_major = ReadPgVersionFromFile(path, file_version_string);
  61.  
  62.     if (my_major != file_major)
  63.         ereport(FATAL,
  64. diff --git a/src/common/controldata_legacy.c b/src/common/controldata_legacy.c
  65. index 6e6b1b9a7a0..56c51d0c9b5 100644
  66. --- a/src/common/controldata_legacy.c
  67. +++ b/src/common/controldata_legacy.c
  68. @@ -22,6 +22,7 @@
  69.  
  70.  #include <fcntl.h>
  71.  #include <unistd.h>
  72. +#include <miscadmin.h>
  73.  #if defined(USE_ICU) && !defined(FRONTEND)
  74.  #include <unicode/uversion.h>
  75.  #endif
  76. @@ -425,13 +426,12 @@ PrintClusterCompatibilityInfo(const char *DataDir)
  77.     bool        crc_ok;
  78.     bool        server_uses_icu = false;
  79.     bool        data_uses_icu = false;
  80. -   char        server_icu_version_str[20] = "";
  81. -   char        data_icu_version_str[20] = "";
  82.     CompatibilityInfo compat_info;
  83.     ControlFileDataGeneric *ControlFile = GetGenericControlFile(DataDir,
  84.                                     &crc_ok, &compat_info, NULL, NULL, NULL);
  85.     uint32      control_ver = GET_PG_CONTROL_VERSION(ControlFile);
  86.     uint32      catalog_ver = GET_CATALOG_VERSION_NO(ControlFile);
  87. +   char        major_version_string[PG_VERSION_STRING_MAXLEN];
  88.  
  89.  #define COMPARE_AND_PRINT_STRINGS(description, arg1, arg2) \
  90.     (printf("%-38s%25s||%25s%s\n", description, arg1, arg2, \
  91. @@ -447,24 +447,19 @@ PrintClusterCompatibilityInfo(const char *DataDir)
  92.  
  93.  /* Prepare info about ICU usage by the server and by the cluster */
  94.  #ifdef USE_ICU
  95. -   UVersionInfo icu_version;
  96. -   u_getVersion(icu_version);
  97. -   icu_version_to_string(icu_version, server_icu_version_str);
  98.     server_uses_icu = true;
  99.  #endif
  100.     if (compat_info.p_icu_version)
  101. -   {
  102.         data_uses_icu = icu_version_is_valid(*compat_info.p_icu_version);
  103. -       if (data_uses_icu)
  104. -           icu_version_to_string(*compat_info.p_icu_version,
  105. -                                   data_icu_version_str);
  106. -   }
  107.  
  108.     if (!crc_ok)
  109.         printf(_("WARNING: Calculated CRC checksum does not match value stored in file.\n"
  110.                  "Either the file is corrupt, or it has a different layout than this program\n"
  111.                  "is expecting.  The results below are untrustworthy.\n\n"));
  112.  
  113. +   /* Getting major version from PG_VERSION */
  114. +   ReadPgVersionFromFile(DataDir, major_version_string);
  115. +
  116.     /*
  117.      * Now print all the info that xlog.c usually checks for deciding
  118.      * whether the cluster and the postgres binary are compatible.
  119. @@ -472,6 +467,8 @@ PrintClusterCompatibilityInfo(const char *DataDir)
  120.      * src/backend/access/transam/xlog.c => ReadControlFile()
  121.      */
  122.     printf("%38s%25s||%25s\n", "", _("Server binary"), _("Database files"));
  123. +   COMPARE_AND_PRINT_STRINGS(_("Postgres major version:"),
  124. +           PG_MAJORVERSION, major_version_string);
  125.     COMPARE_AND_PRINT_STRINGS(_("pg_control edition:"),
  126.             ControlEditionString(PG_CONTROL_VERSION / 65536),
  127.             ControlEditionString(compat_info.edition));
  128. @@ -517,10 +514,6 @@ PrintClusterCompatibilityInfo(const char *DataDir)
  129.     COMPARE_AND_PRINT_STRINGS(_("Uses ICU:"),
  130.             server_uses_icu ? _("yes") : _("no"),
  131.             data_uses_icu ? _("yes") : _("no"));
  132. -   /* Only show ICU version if there is at least one version to show */
  133. -   if (server_uses_icu || data_uses_icu)
  134. -       COMPARE_AND_PRINT_STRINGS(_("ICU library version:"),
  135. -               server_icu_version_str, data_icu_version_str);
  136.  
  137.     if (is_compatible)
  138.         printf(_("\nRESULT: Compatibility tests passed.\n"));
  139. diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
  140. index dc0c8875dcc..48a37cbc85f 100644
  141. --- a/src/include/miscadmin.h
  142. +++ b/src/include/miscadmin.h
  143. @@ -29,6 +29,7 @@
  144.  
  145.  
  146.  #define InvalidPid             (-1)
  147. +#define PG_VERSION_STRING_MAXLEN 64
  148.  
  149.  
  150.  /*****************************************************************************
  151. @@ -458,6 +459,7 @@ extern void CreateSocketLockFile(const char *socketfile, bool amPostmaster,
  152.  extern void TouchSocketLockFiles(void);
  153.  extern void AddToDataDirLockFile(int target_line, const char *str);
  154.  extern bool RecheckDataDirLockFile(void);
  155. +extern long ReadPgVersionFromFile(const char *path, char *file_version_string);
  156.  extern void ValidatePgVersion(const char *path);
  157.  extern void process_shared_preload_libraries(void);
  158.  extern void process_session_preload_libraries(void);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement