|
37 | 37 | * |
38 | 38 | * |
39 | 39 | * IDENTIFICATION |
40 | | - * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.577 2009/04/05 04:19:58 tgl Exp $ |
| 40 | + * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.578 2009/05/02 22:02:37 tgl Exp $ |
41 | 41 | * |
42 | 42 | * NOTES |
43 | 43 | * |
@@ -315,6 +315,7 @@ extern int optreset; /* might not be declared by system headers */ |
315 | 315 | /* |
316 | 316 | * postmaster.c - function prototypes |
317 | 317 | */ |
| 318 | +static void getInstallationPaths(const char *argv0); |
318 | 319 | static void checkDataDir(void); |
319 | 320 |
|
320 | 321 | #ifdef USE_BONJOUR |
@@ -493,11 +494,8 @@ PostmasterMain(int argc, char *argv[]) |
493 | 494 | ALLOCSET_DEFAULT_MAXSIZE); |
494 | 495 | MemoryContextSwitchTo(PostmasterContext); |
495 | 496 |
|
496 | | - if (find_my_exec(argv[0], my_exec_path) < 0) |
497 | | - elog(FATAL, "%s: could not locate my own executable path", |
498 | | - argv[0]); |
499 | | - |
500 | | - get_pkglib_path(my_exec_path, pkglib_path); |
| 497 | + /* Initialize paths to installation files */ |
| 498 | + getInstallationPaths(argv[0]); |
501 | 499 |
|
502 | 500 | /* |
503 | 501 | * Options setup |
@@ -690,15 +688,6 @@ PostmasterMain(int argc, char *argv[]) |
690 | 688 | ExitPostmaster(1); |
691 | 689 | } |
692 | 690 |
|
693 | | -#ifdef EXEC_BACKEND |
694 | | - /* Locate executable backend before we change working directory */ |
695 | | - if (find_other_exec(argv[0], "postgres", PG_BACKEND_VERSIONSTR, |
696 | | - postgres_exec_path) < 0) |
697 | | - ereport(FATAL, |
698 | | - (errmsg("%s: could not locate matching postgres executable", |
699 | | - progname))); |
700 | | -#endif |
701 | | - |
702 | 691 | /* |
703 | 692 | * Locate the proper configuration files and data directory, and read |
704 | 693 | * postgresql.conf for the first time. |
@@ -1062,6 +1051,58 @@ PostmasterMain(int argc, char *argv[]) |
1062 | 1051 | } |
1063 | 1052 |
|
1064 | 1053 |
|
| 1054 | +/* |
| 1055 | + * Compute and check the directory paths to files that are part of the |
| 1056 | + * installation (as deduced from the postgres executable's own location) |
| 1057 | + */ |
| 1058 | +static void |
| 1059 | +getInstallationPaths(const char *argv0) |
| 1060 | +{ |
| 1061 | + DIR *pdir; |
| 1062 | + |
| 1063 | + /* Locate the postgres executable itself */ |
| 1064 | + if (find_my_exec(argv0, my_exec_path) < 0) |
| 1065 | + elog(FATAL, "%s: could not locate my own executable path", argv0); |
| 1066 | + |
| 1067 | +#ifdef EXEC_BACKEND |
| 1068 | + /* Locate executable backend before we change working directory */ |
| 1069 | + if (find_other_exec(argv0, "postgres", PG_BACKEND_VERSIONSTR, |
| 1070 | + postgres_exec_path) < 0) |
| 1071 | + ereport(FATAL, |
| 1072 | + (errmsg("%s: could not locate matching postgres executable", |
| 1073 | + argv0))); |
| 1074 | +#endif |
| 1075 | + |
| 1076 | + /* |
| 1077 | + * Locate the pkglib directory --- this has to be set early in case we try |
| 1078 | + * to load any modules from it in response to postgresql.conf entries. |
| 1079 | + */ |
| 1080 | + get_pkglib_path(my_exec_path, pkglib_path); |
| 1081 | + |
| 1082 | + /* |
| 1083 | + * Verify that there's a readable directory there; otherwise the |
| 1084 | + * Postgres installation is incomplete or corrupt. (A typical cause |
| 1085 | + * of this failure is that the postgres executable has been moved or |
| 1086 | + * hardlinked to some directory that's not a sibling of the installation |
| 1087 | + * lib/ directory.) |
| 1088 | + */ |
| 1089 | + pdir = AllocateDir(pkglib_path); |
| 1090 | + if (pdir == NULL) |
| 1091 | + ereport(ERROR, |
| 1092 | + (errcode_for_file_access(), |
| 1093 | + errmsg("could not open directory \"%s\": %m", |
| 1094 | + pkglib_path), |
| 1095 | + errhint("This may indicate an incomplete PostgreSQL installation, or that the file \"%s\" has been moved away from its proper location.", |
| 1096 | + my_exec_path))); |
| 1097 | + FreeDir(pdir); |
| 1098 | + |
| 1099 | + /* |
| 1100 | + * XXX is it worth similarly checking the share/ directory? If the |
| 1101 | + * lib/ directory is there, then share/ probably is too. |
| 1102 | + */ |
| 1103 | +} |
| 1104 | + |
| 1105 | + |
1065 | 1106 | /* |
1066 | 1107 | * Validate the proposed data directory |
1067 | 1108 | */ |
|
0 commit comments