1 /*-------------------------------------------------------------------------
4 * miscellaneous initialization support stuff
6 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.111 2003/08/04 00:43:26 momjian Exp $
13 *-------------------------------------------------------------------------
17 #include <sys/param.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
33 #include "catalog/catname.h"
34 #include "catalog/pg_shadow.h"
35 #include "libpq/libpq-be.h"
36 #include "miscadmin.h"
37 #include "storage/ipc.h"
38 #include "storage/pg_shmem.h"
39 #include "utils/builtins.h"
40 #include "utils/guc.h"
41 #include "utils/lsyscache.h"
42 #include "utils/syscache.h"
45 ProcessingMode Mode = InitProcessing;
47 /* Note: we rely on these to initialize as zeroes */
48 static char directoryLockFile[MAXPGPATH];
49 static char socketLockFile[MAXPGPATH];
52 static unsigned char RecodeForwTable[128];
53 static unsigned char RecodeBackTable[128];
55 static void GetCharSetByHost(char *TableName, int host, const char *DataDir);
59 /* ----------------------------------------------------------------
60 * ignoring system indexes support stuff
61 * ----------------------------------------------------------------
64 static bool isIgnoringSystemIndexes = false;
67 * IsIgnoringSystemIndexes
68 * True if ignoring system indexes.
71 IsIgnoringSystemIndexes()
73 return isIgnoringSystemIndexes;
78 * Set true or false whether PostgreSQL ignores system indexes.
82 IgnoreSystemIndexes(bool mode)
84 isIgnoringSystemIndexes = mode;
87 /* ----------------------------------------------------------------
88 * database path / name support stuff
89 * ----------------------------------------------------------------
93 SetDatabasePath(const char *path)
100 /* use strdup since this is done before memory contexts are set up */
103 DatabasePath = strdup(path);
104 AssertState(DatabasePath);
109 * Set data directory, but make sure it's an absolute path. Use this,
110 * never set DataDir directly.
113 SetDataDir(const char *dir)
120 /* If presented path is relative, convert to absolute */
121 if (!is_absolute_path(dir))
129 buf = malloc(buflen);
132 (errcode(ERRCODE_OUT_OF_MEMORY),
133 errmsg("out of memory")));
135 if (getcwd(buf, buflen))
137 else if (errno == ERANGE)
146 elog(FATAL, "could not get current working directory: %m");
150 new = malloc(strlen(buf) + 1 + strlen(dir) + 1);
153 (errcode(ERRCODE_OUT_OF_MEMORY),
154 errmsg("out of memory")));
155 sprintf(new, "%s/%s", buf, dir);
163 (errcode(ERRCODE_OUT_OF_MEMORY),
164 errmsg("out of memory")));
168 * Strip any trailing slash. Not strictly necessary, but avoids
169 * generating funny-looking paths to individual files.
171 newlen = strlen(new);
172 if (newlen > 1 && new[newlen - 1] == '/'
174 || new[newlen - 1] == '\\'
177 new[newlen - 1] = '\0';
184 /* ----------------------------------------------------------------
186 * ----------------------------------------------------------------
199 unsigned char FromChar,
201 char ChTable[MAX_TOKEN];
203 for (i = 0; i < 128; i++)
205 RecodeForwTable[i] = i + 128;
206 RecodeBackTable[i] = i + 128;
209 if (IsUnderPostmaster)
211 GetCharSetByHost(ChTable, MyProcPort->raddr.in.sin_addr.s_addr, DataDir);
215 filename = getenv("PG_RECODETABLE");
217 if (filename && *filename != '\0')
219 map_file = palloc(strlen(DataDir) + strlen(filename) + 2);
220 sprintf(map_file, "%s/%s", DataDir, filename);
221 file = AllocateFile(map_file, "r");
228 next_token(file, buf, sizeof(buf));
231 FromChar = strtoul(buf, 0, 0);
232 /* Read the ToChar */
233 next_token(file, buf, sizeof(buf));
236 ToChar = strtoul(buf, 0, 0);
237 RecodeForwTable[FromChar - 128] = ToChar;
238 RecodeBackTable[ToChar - 128] = FromChar;
241 while (!feof(file) && buf[0])
243 next_token(file, buf, sizeof(buf));
244 elog(LOG, "unexpected token %s in file %s",
256 convertstr(unsigned char *buff, int len, int dest)
261 for (i = 0; i < len; i++, buff++)
266 *buff = RecodeForwTable[*buff - 128];
268 *buff = RecodeBackTable[*buff - 128];
274 #define CHARSET_FILE "charset.conf"
275 #define MAX_CHARSETS 10
282 char Orig[MAX_TOKEN];
283 char Dest[MAX_TOKEN];
284 char Table[MAX_TOKEN];
289 CharSetInRange(char *buf, int host)
296 struct in_addr file_ip_addr;
298 unsigned int one = 0x80000000,
302 p = strchr(buf, '/');
306 valid = inet_aton(buf, &file_ip_addr);
309 mask = strtoul(p, 0, 0);
310 FromAddr = ntohl(file_ip_addr.s_addr);
311 ToAddr = ntohl(file_ip_addr.s_addr);
312 for (i = 0; i < mask; i++)
318 ToAddr = ToAddr | ~NetMask;
320 return ((unsigned) tmp >= (unsigned) FromAddr &&
321 (unsigned) tmp <= (unsigned) ToAddr);
326 p = strchr(buf, '-');
330 valid = inet_aton(buf, &file_ip_addr);
333 FromAddr = ntohl(file_ip_addr.s_addr);
334 valid = inet_aton(p, &file_ip_addr);
337 ToAddr = ntohl(file_ip_addr.s_addr);
339 return ((unsigned) tmp >= (unsigned) FromAddr &&
340 (unsigned) tmp <= (unsigned) ToAddr);
346 valid = inet_aton(buf, &file_ip_addr);
349 FromAddr = file_ip_addr.s_addr;
350 return (unsigned) FromAddr == (unsigned) host;
359 GetCharSetByHost(char *TableName, int host, const char *DataDir)
363 BaseCharset[MAX_TOKEN],
364 OrigCharset[MAX_TOKEN],
365 DestCharset[MAX_TOKEN],
366 HostCharset[MAX_TOKEN],
372 struct CharsetItem *ChArray[MAX_CHARSETS];
375 bufsize = (strlen(DataDir) + strlen(CHARSET_FILE) + 2) * sizeof(char);
376 map_file = (char *) palloc(bufsize);
377 snprintf(map_file, bufsize, "%s/%s", DataDir, CHARSET_FILE);
378 file = AllocateFile(map_file, "r");
382 /* XXX should we log a complaint? */
388 next_token(file, buf, sizeof(buf));
392 if (strcasecmp(buf, "HostCharset") == 0)
394 else if (strcasecmp(buf, "BaseCharset") == 0)
396 else if (strcasecmp(buf, "RecodeTable") == 0)
399 elog(LOG, "unrecognized tag %s in file %s",
406 next_token(file, buf, sizeof(buf));
409 if (CharSetInRange(buf, host))
411 /* Read the charset */
412 next_token(file, buf, sizeof(buf));
414 strcpy(HostCharset, buf);
419 /* Read the base charset */
420 next_token(file, buf, sizeof(buf));
422 strcpy(BaseCharset, buf);
425 /* Read the original charset */
426 next_token(file, buf, sizeof(buf));
429 strcpy(OrigCharset, buf);
430 /* Read the destination charset */
431 next_token(file, buf, sizeof(buf));
434 strcpy(DestCharset, buf);
435 /* Read the table filename */
436 next_token(file, buf, sizeof(buf));
440 (struct CharsetItem *) palloc(sizeof(struct CharsetItem));
441 strcpy(ChArray[ChIndex]->Orig, OrigCharset);
442 strcpy(ChArray[ChIndex]->Dest, DestCharset);
443 strcpy(ChArray[ChIndex]->Table, buf);
452 while (!feof(file) && buf[0])
454 next_token(file, buf, sizeof(buf));
455 elog(LOG, "unrecognized tag %s in file %s",
462 for (i = 0; i < ChIndex; i++)
464 if (strcasecmp(BaseCharset, ChArray[i]->Orig) == 0 &&
465 strcasecmp(HostCharset, ChArray[i]->Dest) == 0)
466 strncpy(TableName, ChArray[i]->Table, 79);
470 #endif /* CYR_RECODE */
474 /* ----------------------------------------------------------------
477 * The authenticated user is determined at connection start and never
478 * changes. The session user can be changed only by SET SESSION
479 * AUTHORIZATION. The current user may change when "setuid" functions
480 * are implemented. Conceptually there is a stack, whose bottom
481 * is the session user. You are yourself responsible to save and
482 * restore the current user id if you need to change it.
483 * ----------------------------------------------------------------
485 static AclId AuthenticatedUserId = 0;
486 static AclId SessionUserId = 0;
487 static AclId CurrentUserId = 0;
489 static bool AuthenticatedUserIsSuperuser = false;
492 * This function is relevant for all privilege checks.
497 AssertState(AclIdIsValid(CurrentUserId));
498 return CurrentUserId;
503 SetUserId(AclId newid)
505 AssertArg(AclIdIsValid(newid));
506 CurrentUserId = newid;
511 * This value is only relevant for informational purposes.
514 GetSessionUserId(void)
516 AssertState(AclIdIsValid(SessionUserId));
517 return SessionUserId;
522 SetSessionUserId(AclId newid)
524 AssertArg(AclIdIsValid(newid));
525 SessionUserId = newid;
526 /* Current user defaults to session user. */
527 if (!AclIdIsValid(CurrentUserId))
528 CurrentUserId = newid;
533 InitializeSessionUserId(const char *username)
541 * Don't do scans if we're bootstrapping, none of the system catalogs
542 * exist yet, and they should be owned by postgres anyway.
544 AssertState(!IsBootstrapProcessingMode());
547 AssertState(!OidIsValid(AuthenticatedUserId));
549 userTup = SearchSysCache(SHADOWNAME,
550 PointerGetDatum(username),
552 if (!HeapTupleIsValid(userTup))
554 (errcode(ERRCODE_UNDEFINED_OBJECT),
555 errmsg("user \"%s\" does not exist", username)));
557 usesysid = ((Form_pg_shadow) GETSTRUCT(userTup))->usesysid;
559 AuthenticatedUserId = usesysid;
560 AuthenticatedUserIsSuperuser = ((Form_pg_shadow) GETSTRUCT(userTup))->usesuper;
562 SetSessionUserId(usesysid); /* sets CurrentUserId too */
564 /* Record username and superuser status as GUC settings too */
565 SetConfigOption("session_authorization", username,
566 PGC_BACKEND, PGC_S_OVERRIDE);
567 SetConfigOption("is_superuser",
568 AuthenticatedUserIsSuperuser ? "on" : "off",
569 PGC_INTERNAL, PGC_S_OVERRIDE);
572 * Set up user-specific configuration variables. This is a good place
573 * to do it so we don't have to read pg_shadow twice during session
576 datum = SysCacheGetAttr(SHADOWNAME, userTup,
577 Anum_pg_shadow_useconfig, &isnull);
580 ArrayType *a = DatumGetArrayTypeP(datum);
582 ProcessGUCArray(a, PGC_S_USER);
585 ReleaseSysCache(userTup);
590 InitializeSessionUserIdStandalone(void)
592 /* This function should only be called in a single-user backend. */
593 AssertState(!IsUnderPostmaster);
596 AssertState(!OidIsValid(AuthenticatedUserId));
598 AuthenticatedUserId = BOOTSTRAP_USESYSID;
599 AuthenticatedUserIsSuperuser = true;
601 SetSessionUserId(BOOTSTRAP_USESYSID);
606 * Change session auth ID while running
608 * Only a superuser may set auth ID to something other than himself. Note
609 * that in case of multiple SETs in a single session, the original userid's
610 * superuserness is what matters. But we set the GUC variable is_superuser
611 * to indicate whether the *current* session userid is a superuser.
614 SetSessionAuthorization(AclId userid, bool is_superuser)
616 /* Must have authenticated already, else can't make permission check */
617 AssertState(AclIdIsValid(AuthenticatedUserId));
619 if (userid != AuthenticatedUserId &&
620 !AuthenticatedUserIsSuperuser)
622 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
623 errmsg("permission denied to set session authorization")));
625 SetSessionUserId(userid);
628 SetConfigOption("is_superuser",
629 is_superuser ? "on" : "off",
630 PGC_INTERNAL, PGC_S_OVERRIDE);
635 * Get user name from user id
638 GetUserNameFromId(AclId userid)
643 tuple = SearchSysCache(SHADOWSYSID,
644 ObjectIdGetDatum(userid),
646 if (!HeapTupleIsValid(tuple))
648 (errcode(ERRCODE_UNDEFINED_OBJECT),
649 errmsg("invalid user id: %d", userid)));
651 result = pstrdup(NameStr(((Form_pg_shadow) GETSTRUCT(tuple))->usename));
653 ReleaseSysCache(tuple);
659 /*-------------------------------------------------------------------------
660 * Interlock-file support
662 * These routines are used to create both a data-directory lockfile
663 * ($DATADIR/postmaster.pid) and a Unix-socket-file lockfile ($SOCKFILE.lock).
664 * Both kinds of files contain the same info:
666 * Owning process' PID
667 * Data directory path
669 * By convention, the owning process' PID is negated if it is a standalone
670 * backend rather than a postmaster. This is just for informational purposes.
671 * The path is also just for informational purposes (so that a socket lockfile
672 * can be more easily traced to the associated postmaster).
674 * A data-directory lockfile can optionally contain a third line, containing
675 * the key and ID for the shared memory block used by this postmaster.
677 * On successful lockfile creation, a proc_exit callback to remove the
678 * lockfile is automatically created.
679 *-------------------------------------------------------------------------
683 * proc_exit callback to remove a lockfile.
686 UnlinkLockFile(int status, Datum filename)
688 char *fname = (char *) DatumGetPointer(filename);
692 if (unlink(fname) != 0)
694 /* Should we complain if the unlink fails? */
703 * filename is the name of the lockfile to create.
704 * amPostmaster is used to determine how to encode the output PID.
705 * isDDLock and refName are used to determine what error message to produce.
708 CreateLockFile(const char *filename, bool amPostmaster,
709 bool isDDLock, const char *refName)
712 char buffer[MAXPGPATH + 100];
717 pid_t my_pid = getpid();
720 * We need a loop here because of race conditions. But don't loop
721 * forever (for example, a non-writable $PGDATA directory might cause
722 * a failure that won't go away). 100 tries seems like plenty.
724 for (ntries = 0;; ntries++)
727 * Try to create the lock file --- O_EXCL makes this atomic.
729 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
731 break; /* Success; exit the retry loop */
734 * Couldn't create the pid file. Probably it already exists.
736 if ((errno != EEXIST && errno != EACCES) || ntries > 100)
738 (errcode_for_file_access(),
739 errmsg("could not create lock file \"%s\": %m",
743 * Read the file to get the old owner's PID. Note race condition
744 * here: file might have been deleted since we tried to create it.
746 fd = open(filename, O_RDONLY, 0600);
750 continue; /* race condition; try again */
752 (errcode_for_file_access(),
753 errmsg("could not open lock file \"%s\": %m",
756 if ((len = read(fd, buffer, sizeof(buffer) - 1)) <= 0)
758 (errcode_for_file_access(),
759 errmsg("could not read lock file \"%s\": %m",
764 encoded_pid = atoi(buffer);
766 /* if pid < 0, the pid is for postgres, not postmaster */
767 other_pid = (pid_t) (encoded_pid < 0 ? -encoded_pid : encoded_pid);
770 elog(FATAL, "bogus data in lock file \"%s\"", filename);
773 * Check to see if the other process still exists
775 * Normally kill() will fail with ESRCH if the given PID doesn't
776 * exist. BeOS returns EINVAL for some silly reason, however.
778 if (other_pid != my_pid)
780 if (kill(other_pid, 0) == 0 ||
787 /* lockfile belongs to a live process */
789 (errcode(ERRCODE_LOCK_FILE_EXISTS),
790 errmsg("lock file \"%s\" already exists",
793 errhint("Is another %s (pid %d) running in \"%s\"?",
794 (encoded_pid < 0 ? "postgres" : "postmaster"),
795 (int) other_pid, refName) :
796 errhint("Is another %s (pid %d) using \"%s\"?",
797 (encoded_pid < 0 ? "postgres" : "postmaster"),
798 (int) other_pid, refName)));
803 * No, the creating process did not exist. However, it could be
804 * that the postmaster crashed (or more likely was kill -9'd by a
805 * clueless admin) but has left orphan backends behind. Check for
806 * this by looking to see if there is an associated shmem segment
807 * that is still in use.
815 ptr = strchr(buffer, '\n');
817 (ptr = strchr(ptr + 1, '\n')) != NULL)
820 if (sscanf(ptr, "%lu %lu", &id1, &id2) == 2)
822 if (PGSharedMemoryIsInUse(id1, id2))
824 (errcode(ERRCODE_LOCK_FILE_EXISTS),
825 errmsg("pre-existing shared memory block "
826 "(key %lu, id %lu) is still in use",
828 errhint("If you're sure there are no old "
829 "backends still running, remove "
830 "the shared memory block with "
831 "ipcrm(1), or just delete \"%s\".",
838 * Looks like nobody's home. Unlink the file and try again to
839 * create it. Need a loop because of possible race condition
840 * against other would-be creators.
842 if (unlink(filename) < 0)
844 (errcode_for_file_access(),
845 errmsg("could not remove old lock file \"%s\": %m",
847 errhint("The file seems accidentally left over, but "
848 "I couldn't remove it. Please remove the file "
849 "by hand and try again.")));
853 * Successfully created the file, now fill it.
855 snprintf(buffer, sizeof(buffer), "%d\n%s\n",
856 amPostmaster ? (int) my_pid : -((int) my_pid),
859 if (write(fd, buffer, strlen(buffer)) != strlen(buffer))
861 int save_errno = errno;
865 /* if write didn't set errno, assume problem is no disk space */
866 errno = save_errno ? save_errno : ENOSPC;
868 (errcode_for_file_access(),
869 errmsg("could not write lock file \"%s\": %m", filename)));
874 * Arrange for automatic removal of lockfile at proc_exit.
876 on_proc_exit(UnlinkLockFile, PointerGetDatum(strdup(filename)));
880 CreateDataDirLockFile(const char *datadir, bool amPostmaster)
882 char lockfile[MAXPGPATH];
884 snprintf(lockfile, sizeof(lockfile), "%s/postmaster.pid", datadir);
885 CreateLockFile(lockfile, amPostmaster, true, datadir);
886 /* Save name of lockfile for RecordSharedMemoryInLockFile */
887 strcpy(directoryLockFile, lockfile);
891 CreateSocketLockFile(const char *socketfile, bool amPostmaster)
893 char lockfile[MAXPGPATH];
895 snprintf(lockfile, sizeof(lockfile), "%s.lock", socketfile);
896 CreateLockFile(lockfile, amPostmaster, false, socketfile);
897 /* Save name of lockfile for TouchSocketLockFile */
898 strcpy(socketLockFile, lockfile);
902 * TouchSocketLockFile -- mark socket lock file as recently accessed
904 * This routine should be called every so often to ensure that the lock file
905 * has a recent mod or access date. That saves it
906 * from being removed by overenthusiastic /tmp-directory-cleaner daemons.
907 * (Another reason we should never have put the socket file in /tmp...)
910 TouchSocketLockFile(void)
912 /* Do nothing if we did not create a socket... */
913 if (socketLockFile[0] != '\0')
916 * utime() is POSIX standard, utimes() is a common alternative; if
917 * we have neither, fall back to actually reading the file (which
918 * only sets the access time not mod time, but that should be
919 * enough in most cases). In all paths, we ignore errors.
922 utime(socketLockFile, NULL);
923 #else /* !HAVE_UTIME */
925 utimes(socketLockFile, NULL);
926 #else /* !HAVE_UTIMES */
930 fd = open(socketLockFile, O_RDONLY | PG_BINARY, 0);
933 read(fd, buffer, sizeof(buffer));
936 #endif /* HAVE_UTIMES */
937 #endif /* HAVE_UTIME */
942 * Append information about a shared memory segment to the data directory
943 * lock file (if we have created one).
945 * This may be called multiple times in the life of a postmaster, if we
946 * delete and recreate shmem due to backend crash. Therefore, be prepared
947 * to overwrite existing information. (As of 7.1, a postmaster only creates
948 * one shm seg at a time; but for the purposes here, if we did have more than
949 * one then any one of them would do anyway.)
952 RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
960 * Do nothing if we did not create a lockfile (probably because we are
961 * running standalone).
963 if (directoryLockFile[0] == '\0')
966 fd = open(directoryLockFile, O_RDWR | PG_BINARY, 0);
970 (errcode_for_file_access(),
971 errmsg("could not rewrite \"%s\": %m",
972 directoryLockFile)));
975 len = read(fd, buffer, sizeof(buffer) - 100);
979 (errcode_for_file_access(),
980 errmsg("could not read \"%s\": %m",
981 directoryLockFile)));
988 * Skip over first two lines (PID and path).
990 ptr = strchr(buffer, '\n');
992 (ptr = strchr(ptr + 1, '\n')) == NULL)
994 elog(LOG, "bogus data in \"%s\"", directoryLockFile);
1001 * Append key information. Format to try to keep it the same length
1002 * always (trailing junk won't hurt, but might confuse humans).
1004 sprintf(ptr, "%9lu %9lu\n", id1, id2);
1007 * And rewrite the data. Since we write in a single kernel call, this
1008 * update should appear atomic to onlookers.
1010 len = strlen(buffer);
1012 if (lseek(fd, (off_t) 0, SEEK_SET) != 0 ||
1013 (int) write(fd, buffer, len) != len)
1015 /* if write didn't set errno, assume problem is no disk space */
1019 (errcode_for_file_access(),
1020 errmsg("could not write \"%s\": %m",
1021 directoryLockFile)));
1029 /*-------------------------------------------------------------------------
1030 * Version checking support
1031 *-------------------------------------------------------------------------
1035 * Determine whether the PG_VERSION file in directory `path' indicates
1036 * a data version compatible with the version of this program.
1038 * If compatible, return. Otherwise, ereport(FATAL).
1041 ValidatePgVersion(const char *path)
1043 char full_path[MAXPGPATH];
1051 const char *version_string = PG_VERSION;
1053 my_major = strtol(version_string, &endptr, 10);
1055 my_minor = strtol(endptr + 1, NULL, 10);
1057 snprintf(full_path, sizeof(full_path), "%s/PG_VERSION", path);
1059 file = AllocateFile(full_path, "r");
1062 if (errno == ENOENT)
1064 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1065 errmsg("\"%s\" is not a valid data directory",
1067 errdetail("File \"%s\" is missing.", full_path)));
1070 (errcode_for_file_access(),
1071 errmsg("could not open \"%s\": %m", full_path)));
1074 ret = fscanf(file, "%ld.%ld", &file_major, &file_minor);
1077 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1078 errmsg("\"%s\" is not a valid data directory",
1080 errdetail("File \"%s\" does not contain valid data.",
1082 errhint("You may need to initdb.")));
1086 if (my_major != file_major || my_minor != file_minor)
1088 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1089 errmsg("database files are incompatible with server"),
1090 errdetail("The data directory was initialized by PostgreSQL version %ld.%ld, "
1091 "which is not compatible with this version %s.",
1092 file_major, file_minor, version_string)));
1095 /*-------------------------------------------------------------------------
1096 * Library preload support
1097 *-------------------------------------------------------------------------
1100 #if defined(__mc68000__) && defined(__ELF__)
1101 typedef int32 ((*func_ptr) ());
1104 typedef char *((*func_ptr) ());
1108 * process any libraries that should be preloaded and
1109 * optionally pre-initialized
1112 process_preload_libraries(char *preload_libraries_string)
1118 if (preload_libraries_string == NULL)
1121 /* Need a modifiable copy of string */
1122 rawstring = pstrdup(preload_libraries_string);
1124 /* Parse string into list of identifiers */
1125 if (!SplitIdentifierString(rawstring, ',', &elemlist))
1127 /* syntax error in list */
1131 (errcode(ERRCODE_SYNTAX_ERROR),
1132 errmsg("invalid list syntax for preload_libraries configuration option")));
1136 foreach(l, elemlist)
1138 char *tok = (char *) lfirst(l);
1139 char *sep = strstr(tok, ":");
1140 char *filename = NULL;
1141 char *funcname = NULL;
1147 * a colon separator implies there is an initialization
1148 * function that we need to run in addition to loading the
1151 size_t filename_len = sep - tok;
1152 size_t funcname_len = strlen(tok) - filename_len - 1;
1154 filename = (char *) palloc(filename_len + 1);
1155 memcpy(filename, tok, filename_len);
1156 filename[filename_len] = '\0';
1158 funcname = (char *) palloc(funcname_len + 1);
1159 strcpy(funcname, sep + 1);
1164 * no separator -- just load the library
1166 filename = pstrdup(tok);
1170 initfunc = (func_ptr) load_external_function(filename, funcname,
1177 (errmsg("preloaded library \"%s\" with initialization function \"%s\"",
1178 filename, funcname)));
1181 (errmsg("preloaded library \"%s\"",