* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.162 2003/07/22 23:30:37 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.163 2003/07/27 21:49:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
gettext("%s does not know where to find the database system data.\n"
"You must specify the directory that contains the database system\n"
"either by specifying the -D invocation option or by setting the\n"
- "PGDATA environment variable.\n\n"),
+ "PGDATA environment variable.\n"),
argv[0]);
proc_exit(1);
}
/*
* Create lockfile for data directory.
*/
- if (!CreateDataDirLockFile(DataDir, false))
- proc_exit(1);
+ CreateDataDirLockFile(DataDir, false);
}
SetProcessingMode(BootstrapProcessing);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.36 2003/07/22 19:00:10 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.37 2003/07/27 21:49:53 tgl Exp $
*
* Since the server static private key ($DataDir/server.key)
* will normally be stored unencrypted so that the database
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
-
-#include "libpq/libpq.h"
-#include "miscadmin.h"
-
#include <sys/socket.h>
#include <unistd.h>
#include <netdb.h>
#include <arpa/inet.h>
#endif
-#ifndef HAVE_STRDUP
-#include "strdup.h"
-#endif
-
#ifdef USE_SSL
#include <openssl/ssl.h>
#include <openssl/dh.h>
#endif
-extern void ExitPostmaster(int);
-extern void postmaster_error(const char *fmt,...);
+#include "libpq/libpq.h"
+#include "miscadmin.h"
#ifdef USE_SSL
static DH *load_dh_file(int keylength);
*/
#define RENEGOTIATION_LIMIT (512 * 1024 * 1024)
#define CA_PATH NULL
+
static SSL_CTX *SSL_context = NULL;
#endif
static int
initialize_SSL(void)
{
- char fnbuf[2048];
+ char fnbuf[MAXPGPATH];
struct stat buf;
if (!SSL_context)
SSL_load_error_strings();
SSL_context = SSL_CTX_new(SSLv23_method());
if (!SSL_context)
- {
- postmaster_error("failed to create SSL context: %s",
- SSLerrmessage());
- ExitPostmaster(1);
- }
+ ereport(FATAL,
+ (errmsg("could not create SSL context: %s",
+ SSLerrmessage())));
/*
* Load and verify certificate and private key
*/
snprintf(fnbuf, sizeof(fnbuf), "%s/server.crt", DataDir);
if (!SSL_CTX_use_certificate_file(SSL_context, fnbuf, SSL_FILETYPE_PEM))
- {
- postmaster_error("failed to load server certificate (%s): %s",
- fnbuf, SSLerrmessage());
- ExitPostmaster(1);
- }
+ ereport(FATAL,
+ (errcode(ERRCODE_CONFIG_FILE_ERROR),
+ errmsg("could not load server certificate file \"%s\": %s",
+ fnbuf, SSLerrmessage())));
snprintf(fnbuf, sizeof(fnbuf), "%s/server.key", DataDir);
- if (lstat(fnbuf, &buf) == -1)
- {
- postmaster_error("failed to stat private key file (%s): %s",
- fnbuf, strerror(errno));
- ExitPostmaster(1);
- }
- if (!S_ISREG(buf.st_mode) || (buf.st_mode & 0077) ||
+ if (stat(fnbuf, &buf) == -1)
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not access private key file \"%s\": %m",
+ fnbuf)));
+ if (!S_ISREG(buf.st_mode) || (buf.st_mode & (S_IRWXG | S_IRWXO)) ||
buf.st_uid != getuid())
- {
- postmaster_error("bad permissions on private key file (%s)\n"
-"File must be owned by the proper user and must have no permissions for\n"
-"\"group\" or \"other\".", fnbuf);
- ExitPostmaster(1);
- }
+ ereport(FATAL,
+ (errcode(ERRCODE_CONFIG_FILE_ERROR),
+ errmsg("unsafe permissions on private key file \"%s\"",
+ fnbuf),
+ errdetail("File must be owned by the database user and must have no permissions for \"group\" or \"other\".")));
+
if (!SSL_CTX_use_PrivateKey_file(SSL_context, fnbuf, SSL_FILETYPE_PEM))
- {
- postmaster_error("failed to load private key file (%s): %s",
- fnbuf, SSLerrmessage());
- ExitPostmaster(1);
- }
+ ereport(FATAL,
+ (errmsg("could not load private key file \"%s\": %s",
+ fnbuf, SSLerrmessage())));
+
if (!SSL_CTX_check_private_key(SSL_context))
- {
- postmaster_error("check of private key failed: %s",
- SSLerrmessage());
- ExitPostmaster(1);
- }
+ ereport(FATAL,
+ (errmsg("check of private key failed: %s",
+ SSLerrmessage())));
}
/* set up empheral DH keys */
/* setup the allowed cipher list */
if (SSL_CTX_set_cipher_list(SSL_context, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH") != 1)
- {
- postmaster_error("unable to set the cipher list (no valid ciphers available)");
- ExitPostmaster(1);
- }
+ elog(FATAL, "could not set the cipher list (no valid ciphers available)");
/* accept client certificates, but don't require them. */
- snprintf(fnbuf, sizeof fnbuf, "%s/root.crt", DataDir);
+ snprintf(fnbuf, sizeof(fnbuf), "%s/root.crt", DataDir);
if (!SSL_CTX_load_verify_locations(SSL_context, fnbuf, CA_PATH))
{
+ /* Not fatal - we do not require client certificates */
+ ereport(LOG,
+ (errmsg("could not load root cert file \"%s\": %s",
+ fnbuf, SSLerrmessage()),
+ errdetail("Will not verify client certificates.")));
return 0;
-#ifdef NOT_USED
- /* CLIENT CERTIFICATES NOT REQUIRED bjm 2002-09-26 */
- postmaster_error("could not read root cert file (%s): %s",
- fnbuf, SSLerrmessage());
- ExitPostmaster(1);
-#endif
}
SSL_CTX_set_verify(SSL_context,
- SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, verify_cb);
+ SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE,
+ verify_cb);
return 0;
}
{
ereport(COMMERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION),
- errmsg("failed to initialize SSL connection: %s",
+ errmsg("could not initialize SSL connection: %s",
SSLerrmessage())));
close_SSL(port);
return -1;
NID_commonName, port->peer_cn, sizeof(port->peer_cn));
port->peer_cn[sizeof(port->peer_cn) - 1] = '\0';
}
- elog(DEBUG2, "secure connection from \"%s\"", port->peer_cn);
+ ereport(DEBUG2,
+ (errmsg("secure connection from \"%s\"", port->peer_cn)));
/* set up debugging/info callback */
SSL_CTX_set_info_callback(SSL_context, info_cb);
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.160 2003/07/24 00:02:53 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.161 2003/07/27 21:49:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Grab an interlock file associated with the socket file.
*/
- if (!CreateSocketLockFile(sock_path, true))
- return STATUS_ERROR;
+ CreateSocketLockFile(sock_path, true);
/*
* Once we have the interlock, we can safely delete any pre-existing
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.58 2003/07/04 16:41:21 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.59 2003/07/27 21:49:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#if defined(__alpha)
if (setsysinfo(SSI_NVPAIRS, buffer, 1, (caddr_t) NULL,
(unsigned long) NULL) < 0)
- fprintf(stderr, gettext("%s: setsysinfo failed: %s\n"), argv[0], strerror(errno));
+ fprintf(stderr, gettext("%s: setsysinfo failed: %s\n"),
+ argv[0], strerror(errno));
#endif
#endif /* NOFIXADE || NOPRINTADE */
*/
if (geteuid() == 0)
{
- fprintf(stderr, gettext(
- "\"root\" execution of the PostgreSQL server is not permitted.\n\n"
- "The server must be started under an unprivileged user id to prevent\n"
- "a possible system security compromise. See the documentation for\n"
- "more information on how to properly start the server.\n\n"
- ));
+ fprintf(stderr,
+ gettext("\"root\" execution of the PostgreSQL server is not permitted.\n"
+ "The server must be started under an unprivileged user id to prevent\n"
+ "possible system security compromise. See the documentation for\n"
+ "more information on how to properly start the server.\n"
+ ));
exit(1);
}
#endif /* !__BEOS__ */
*/
if (getuid() != geteuid())
{
- fprintf(stderr, gettext("%s: real and effective user ids must match\n"),
+ fprintf(stderr,
+ gettext("%s: real and effective user ids must match\n"),
argv[0]);
exit(1);
}
pw = getpwuid(geteuid());
if (pw == NULL)
{
- fprintf(stderr, gettext("%s: invalid current euid %d\n"),
+ fprintf(stderr, gettext("%s: invalid effective uid: %d\n"),
new_argv[0], (int) geteuid());
exit(1);
}
pw_name_persist = malloc(namesize);
if (!GetUserName(pw_name_persist, &namesize))
{
- fprintf(stderr, "%s: GetUserName failed\n", argv[0]);
+ fprintf(stderr, gettext("%s: GetUserName failed\n"),
+ new_argv[0]);
exit(1);
}
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/port/ipc_test.c,v 1.6 2003/07/22 23:30:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/port/ipc_test.c,v 1.7 2003/07/27 21:49:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
volatile uint32 InterruptHoldoffCount = 0;
volatile uint32 CritSectionCount = 0;
+const bool ExecBackend = false;
+
bool IsUnderPostmaster = false;
int MaxBackends = DEF_MAXBACKENDS;
return 0;
}
+
+
+bool
+errstart(int elevel, const char *filename, int lineno,
+ const char *funcname)
+{
+ return (elevel >= ERROR);
+}
+
void
-elog(int lev, const char *fmt,...)
+errfinish(int dummy, ...)
{
- if (lev >= ERROR)
- {
- fprintf(stderr, "elog(%s)\n", fmt);
- abort();
- }
+ proc_exit(1);
+}
+
+void
+elog_finish(int elevel, const char *fmt, ...)
+{
+ fprintf(stderr, "ERROR: %s\n", fmt);
+ proc_exit(1);
+}
+
+int
+errcode(int sqlerrcode)
+{
+ return 0; /* return value does not matter */
+}
+
+int
+errmsg(const char *fmt, ...)
+{
+ fprintf(stderr, "ERROR: %s\n", fmt);
+ return 0; /* return value does not matter */
+}
+
+int
+errmsg_internal(const char *fmt, ...)
+{
+ fprintf(stderr, "ERROR: %s\n", fmt);
+ return 0; /* return value does not matter */
+}
+
+int
+errdetail(const char *fmt, ...)
+{
+ fprintf(stderr, "DETAIL: %s\n", fmt);
+ return 0; /* return value does not matter */
+}
+
+int
+errhint(const char *fmt, ...)
+{
+ fprintf(stderr, "HINT: %s\n", fmt);
+ return 0; /* return value does not matter */
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/port/posix_sema.c,v 1.7 2003/07/22 23:30:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/port/posix_sema.c,v 1.8 2003/07/27 21:49:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Else complain and abort
*/
- fprintf(stderr, "PosixSemaphoreCreate: sem_open(\"%s\") failed: %s\n",
- semname, strerror(errno));
- proc_exit(1);
+ elog(FATAL, "sem_open(\"%s\") failed: %m", semname);
}
/*
PosixSemaphoreCreate(sem_t * sem)
{
if (sem_init(sem, 1, 1) < 0)
- {
- fprintf(stderr, "PosixSemaphoreCreate: sem_init failed: %s\n",
- strerror(errno));
- proc_exit(1);
- }
+ elog(FATAL, "sem_init failed: %m");
}
+
#endif /* USE_NAMED_POSIX_SEMAPHORES */
#ifdef USE_NAMED_POSIX_SEMAPHORES
/* Got to use sem_close for named semaphores */
if (sem_close(sem) < 0)
- fprintf(stderr, "PosixSemaphoreKill: sem_close failed: %s\n",
- strerror(errno));
+ elog(LOG, "sem_close failed: %m");
#else
/* Got to use sem_destroy for unnamed semaphores */
if (sem_destroy(sem) < 0)
- fprintf(stderr, "PosixSemaphoreKill: sem_destroy failed: %s\n",
- strerror(errno));
+ elog(LOG, "sem_destroy failed: %m");
#endif
}
break; /* got it down to 0 */
if (errno == EINTR)
continue; /* can this happen? */
- fprintf(stderr, "PGSemaphoreReset: sem_trywait failed: %s\n",
- strerror(errno));
- proc_exit(1);
+ elog(FATAL, "sem_trywait failed: %m");
}
}
}
} while (errStatus < 0 && errno == EINTR);
if (errStatus < 0)
- {
- fprintf(stderr, "PGSemaphoreLock: sem_wait failed: %s\n",
- strerror(errno));
- proc_exit(255);
- }
+ elog(FATAL, "sem_wait failed: %m");
}
/*
} while (errStatus < 0 && errno == EINTR);
if (errStatus < 0)
- {
- fprintf(stderr, "PGSemaphoreUnlock: sem_post failed: %s\n",
- strerror(errno));
- proc_exit(255);
- }
+ elog(FATAL, "sem_post failed: %m");
}
/*
if (errno == EAGAIN || errno == EDEADLK)
return false; /* failed to lock it */
/* Otherwise we got trouble */
- fprintf(stderr, "PGSemaphoreTryLock: sem_trywait failed: %s\n",
- strerror(errno));
- proc_exit(255);
+ elog(FATAL, "sem_trywait failed: %m");
}
return true;
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/port/sysv_sema.c,v 1.6 2003/07/22 23:30:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/port/sysv_sema.c,v 1.7 2003/07/27 21:49:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Else complain and abort
*/
- fprintf(stderr, "IpcSemaphoreCreate: semget(key=%d, num=%d, 0%o) failed: %s\n",
- (int) semKey, numSems, (IPC_CREAT | IPC_EXCL | IPCProtection),
- strerror(errno));
-
- if (errno == ENOSPC)
- fprintf(stderr,
- "\nThis error does *not* mean that you have run out of disk space.\n"
- "\n"
- "It occurs when either the system limit for the maximum number of\n"
- "semaphore sets (SEMMNI), or the system wide maximum number of\n"
- "semaphores (SEMMNS), would be exceeded. You need to raise the\n"
- "respective kernel parameter. Alternatively, reduce PostgreSQL's\n"
- "consumption of semaphores by reducing its max_connections parameter\n"
- "(currently %d).\n"
- "\n"
- "The PostgreSQL documentation contains more information about\n"
- "configuring your system for PostgreSQL.\n\n",
- MaxBackends);
-
- proc_exit(1);
+ ereport(FATAL,
+ (errmsg("could not create semaphores: %m"),
+ errdetail("Failed syscall was semget(%d, %d, 0%o).",
+ (int) semKey, numSems,
+ IPC_CREAT | IPC_EXCL | IPCProtection),
+ (errno == ENOSPC) ?
+ errhint("This error does *not* mean that you have run out of disk space.\n"
+ "It occurs when either the system limit for the maximum number of "
+ "semaphore sets (SEMMNI), or the system wide maximum number of "
+ "semaphores (SEMMNS), would be exceeded. You need to raise the "
+ "respective kernel parameter. Alternatively, reduce PostgreSQL's "
+ "consumption of semaphores by reducing its max_connections parameter "
+ "(currently %d).\n"
+ "The PostgreSQL documentation contains more information about "
+ "configuring your system for PostgreSQL.",
+ MaxBackends) : 0));
}
return semId;
semun.val = value;
if (semctl(semId, semNum, SETVAL, semun) < 0)
- {
- fprintf(stderr, "IpcSemaphoreInitialize: semctl(id=%d, %d, SETVAL, %d) failed: %s\n",
- semId, semNum, value, strerror(errno));
-
- if (errno == ERANGE)
- fprintf(stderr,
- "You possibly need to raise your kernel's SEMVMX value to be at least\n"
- "%d. Look into the PostgreSQL documentation for details.\n",
- value);
-
- proc_exit(1);
- }
+ ereport(FATAL,
+ (errmsg_internal("semctl(%d, %d, SETVAL, %d) failed: %m",
+ semId, semNum, value),
+ (errno == ERANGE) ?
+ errhint("You possibly need to raise your kernel's SEMVMX value to be at least "
+ "%d. Look into the PostgreSQL documentation for details.",
+ value) : 0));
}
/*
semun.val = 0; /* unused, but keep compiler quiet */
if (semctl(semId, 0, IPC_RMID, semun) < 0)
- fprintf(stderr, "IpcSemaphoreKill: semctl(%d, 0, IPC_RMID, ...) failed: %s\n",
- semId, strerror(errno));
-
- /*
- * We used to report a failure via ereport(WARNING), but that's pretty
- * pointless considering any client has long since disconnected ...
- */
+ elog(LOG, "semctl(%d, 0, IPC_RMID, ...) failed: %m", semId);
}
/* Get the current value (semval) of the semaphore */
} while (errStatus < 0 && errno == EINTR);
if (errStatus < 0)
- {
- fprintf(stderr, "PGSemaphoreLock: semop(id=%d) failed: %s\n",
- sema->semId, strerror(errno));
- proc_exit(255);
- }
+ elog(FATAL, "semop(id=%d) failed: %m", sema->semId);
}
/*
} while (errStatus < 0 && errno == EINTR);
if (errStatus < 0)
- {
- fprintf(stderr, "PGSemaphoreUnlock: semop(id=%d) failed: %s\n",
- sema->semId, strerror(errno));
- proc_exit(255);
- }
+ elog(FATAL, "semop(id=%d) failed: %m", sema->semId);
}
/*
return false; /* failed to lock it */
#endif
/* Otherwise we got trouble */
- fprintf(stderr, "PGSemaphoreTryLock: semop(id=%d) failed: %s\n",
- sema->semId, strerror(errno));
- proc_exit(255);
+ elog(FATAL, "semop(id=%d) failed: %m", sema->semId);
}
return true;
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/port/sysv_shmem.c,v 1.12 2003/07/22 23:30:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/port/sysv_shmem.c,v 1.13 2003/07/27 21:49:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Else complain and abort
*/
- fprintf(stderr, "IpcMemoryCreate: shmget(key=%d, size=%u, 0%o) failed: %s\n",
- (int) memKey, size, (IPC_CREAT | IPC_EXCL | IPCProtection),
- strerror(errno));
-
- if (errno == EINVAL)
- fprintf(stderr,
- "\nThis error usually means that PostgreSQL's request for a shared memory\n"
- "segment exceeded your kernel's SHMMAX parameter. You can either\n"
- "reduce the request size or reconfigure the kernel with larger SHMMAX.\n"
- "To reduce the request size (currently %u bytes), reduce\n"
- "PostgreSQL's shared_buffers parameter (currently %d) and/or\n"
- "its max_connections parameter (currently %d).\n"
- "\n"
- "If the request size is already small, it's possible that it is less than\n"
- "your kernel's SHMMIN parameter, in which case raising the request size or\n"
- "reconfiguring SHMMIN is called for.\n"
- "\n"
- "The PostgreSQL documentation contains more information about shared\n"
- "memory configuration.\n\n",
- size, NBuffers, MaxBackends);
-
- else if (errno == ENOMEM)
- fprintf(stderr,
- "\nThis error usually means that PostgreSQL's request for a shared\n"
- "memory segment exceeded available memory or swap space.\n"
- "To reduce the request size (currently %u bytes), reduce\n"
- "PostgreSQL's shared_buffers parameter (currently %d) and/or\n"
- "its max_connections parameter (currently %d).\n"
- "\n"
- "The PostgreSQL documentation contains more information about shared\n"
- "memory configuration.\n\n",
- size, NBuffers, MaxBackends);
-
- else if (errno == ENOSPC)
- fprintf(stderr,
- "\nThis error does *not* mean that you have run out of disk space.\n"
- "\n"
- "It occurs either if all available shared memory IDs have been taken,\n"
- "in which case you need to raise the SHMMNI parameter in your kernel,\n"
- "or because the system's overall limit for shared memory has been\n"
- "reached. If you cannot increase the shared memory limit,\n"
- "reduce PostgreSQL's shared memory request (currently %u bytes),\n"
- "by reducing its shared_buffers parameter (currently %d) and/or\n"
- "its max_connections parameter (currently %d).\n"
- "\n"
- "The PostgreSQL documentation contains more information about shared\n"
- "memory configuration.\n\n",
- size, NBuffers, MaxBackends);
-
- proc_exit(1);
+ ereport(FATAL,
+ (errmsg("could not create shared memory segment: %m"),
+ errdetail("Failed syscall was shmget(key=%d, size=%u, 0%o).",
+ (int) memKey, size,
+ IPC_CREAT | IPC_EXCL | IPCProtection),
+ (errno == EINVAL) ?
+ errhint("This error usually means that PostgreSQL's request for a shared memory "
+ "segment exceeded your kernel's SHMMAX parameter. You can either "
+ "reduce the request size or reconfigure the kernel with larger SHMMAX. "
+ "To reduce the request size (currently %u bytes), reduce "
+ "PostgreSQL's shared_buffers parameter (currently %d) and/or "
+ "its max_connections parameter (currently %d).\n"
+ "If the request size is already small, it's possible that it is less than "
+ "your kernel's SHMMIN parameter, in which case raising the request size or "
+ "reconfiguring SHMMIN is called for.\n"
+ "The PostgreSQL documentation contains more information about shared "
+ "memory configuration.",
+ size, NBuffers, MaxBackends) : 0,
+ (errno == ENOMEM) ?
+ errhint("This error usually means that PostgreSQL's request for a shared "
+ "memory segment exceeded available memory or swap space. "
+ "To reduce the request size (currently %u bytes), reduce "
+ "PostgreSQL's shared_buffers parameter (currently %d) and/or "
+ "its max_connections parameter (currently %d).\n"
+ "The PostgreSQL documentation contains more information about shared "
+ "memory configuration.",
+ size, NBuffers, MaxBackends) : 0,
+ (errno == ENOSPC) ?
+ errhint("This error does *not* mean that you have run out of disk space. "
+ "It occurs either if all available shared memory IDs have been taken, "
+ "in which case you need to raise the SHMMNI parameter in your kernel, "
+ "or because the system's overall limit for shared memory has been "
+ "reached. If you cannot increase the shared memory limit, "
+ "reduce PostgreSQL's shared memory request (currently %u bytes), "
+ "by reducing its shared_buffers parameter (currently %d) and/or "
+ "its max_connections parameter (currently %d).\n"
+ "The PostgreSQL documentation contains more information about shared "
+ "memory configuration.",
+ size, NBuffers, MaxBackends) : 0));
}
/* Register on-exit routine to delete the new segment */
#endif
if (memAddress == (void *) -1)
- {
- fprintf(stderr, "IpcMemoryCreate: shmat(id=%d) failed: %s\n",
- shmid, strerror(errno));
- proc_exit(1);
- }
+ elog(FATAL, "shmat(id=%d) failed: %m", shmid);
/* Register on-exit routine to detach new segment before deleting */
on_shmem_exit(IpcMemoryDetach, PointerGetDatum(memAddress));
IpcMemoryDetach(int status, Datum shmaddr)
{
if (shmdt(DatumGetPointer(shmaddr)) < 0)
- fprintf(stderr, "IpcMemoryDetach: shmdt(%p) failed: %s\n",
- DatumGetPointer(shmaddr), strerror(errno));
-
- /*
- * We used to report a failure via ereport(WARNING), but that's pretty
- * pointless considering any client has long since disconnected ...
- */
+ elog(LOG, "shmdt(%p) failed: %m", DatumGetPointer(shmaddr));
}
/****************************************************************************/
IpcMemoryDelete(int status, Datum shmId)
{
if (shmctl(DatumGetInt32(shmId), IPC_RMID, (struct shmid_ds *) NULL) < 0)
- fprintf(stderr, "IpcMemoryDelete: shmctl(%d, %d, 0) failed: %s\n",
- DatumGetInt32(shmId), IPC_RMID, strerror(errno));
-
- /*
- * We used to report a failure via ereport(WARNING), but that's pretty
- * pointless considering any client has long since disconnected ...
- */
+ elog(LOG, "shmctl(%d, %d, 0) failed: %m",
+ DatumGetInt32(shmId), IPC_RMID);
}
/*
if (ExecBackend && UsedShmemSegAddr != NULL && !makePrivate)
{
if ((hdr = PGSharedMemoryAttach(UsedShmemSegID, &shmid)) == NULL)
- {
- fprintf(stderr, "Unable to attach to proper memory at fixed address: shmget(key=%d, addr=%p) failed: %s\n",
- (int) UsedShmemSegID, UsedShmemSegAddr, strerror(errno));
- proc_exit(1);
- }
+ elog(FATAL, "could not attach to proper memory at fixed address: shmget(key=%d, addr=%p) failed: %m",
+ (int) UsedShmemSegID, UsedShmemSegAddr);
return hdr;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.336 2003/07/23 23:30:40 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.337 2003/07/27 21:49:54 tgl Exp $
*
* NOTES
*
static void LogChildExit(int lev, const char *procname,
int pid, int exitstatus);
static int BackendFork(Port *port);
-void ExitPostmaster(int status);
+static void ExitPostmaster(int status);
static void usage(const char *);
static int ServerLoop(void);
static int BackendStartup(Port *port);
static int CountChildren(void);
static bool CreateOptsFile(int argc, char *argv[]);
static pid_t SSDataBase(int xlop);
-void
-postmaster_error(const char *fmt,...)
+static void postmaster_error(const char *fmt,...)
/* This lets gcc check the format string for consistency. */
__attribute__((format(printf, 1, 2)));
#define CheckPointDataBase() SSDataBase(BS_XLOG_CHECKPOINT)
#define ShutdownDataBase() SSDataBase(BS_XLOG_SHUTDOWN)
-#ifdef USE_SSL
-extern int secure_initialize(void);
-extern void secure_destroy(void);
-extern int secure_open_server(Port *);
-extern void secure_close(Port *);
-#endif /* USE_SSL */
-
static void
checkDataDir(const char *checkdir)
{
char path[MAXPGPATH];
FILE *fp;
-
struct stat stat_buf;
if (checkdir == NULL)
{
- fprintf(stderr, gettext(
- "%s does not know where to find the database system data.\n"
- "You must specify the directory that contains the database system\n"
- "either by specifying the -D invocation option or by setting the\n"
- "PGDATA environment variable.\n\n"),
+ fprintf(stderr,
+ gettext("%s does not know where to find the database system data.\n"
+ "You must specify the directory that contains the database system\n"
+ "either by specifying the -D invocation option or by setting the\n"
+ "PGDATA environment variable.\n"),
progname);
ExitPostmaster(2);
}
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("data directory \"%s\" has group or world access",
checkdir),
- errdetail("permissions should be u=rwx (0700)")));
+ errdetail("Permissions should be u=rwx (0700).")));
#endif
/* Look for PG_VERSION before looking for pg_control */
fp = AllocateFile(path, PG_BINARY_R);
if (fp == NULL)
{
- fprintf(stderr, gettext(
- "%s does not find the database system.\n"
- "Expected to find it in the PGDATA directory \"%s\",\n"
- "but unable to open file \"%s\": %s\n\n"),
+ fprintf(stderr,
+ gettext("%s could not find the database system.\n"
+ "Expected to find it in the PGDATA directory \"%s\",\n"
+ "but failed to open file \"%s\": %s\n"),
progname, checkdir, path, strerror(errno));
ExitPostmaster(2);
}
#ifdef USE_ASSERT_CHECKING
SetConfigOption("debug_assertions", optarg, PGC_POSTMASTER, PGC_S_ARGV);
#else
- postmaster_error("Assert checking is not compiled in.");
+ postmaster_error("assert checking is not compiled in");
#endif
break;
case 'a':
}
default:
- fprintf(stderr, gettext("Try '%s --help' for more information.\n"), progname);
+ fprintf(stderr,
+ gettext("Try '%s --help' for more information.\n"),
+ progname);
ExitPostmaster(1);
}
}
*/
if (optind < argc)
{
- postmaster_error("invalid argument -- %s", argv[optind]);
- fprintf(stderr, gettext("Try '%s --help' for more information.\n"),
+ postmaster_error("invalid argument: \"%s\"", argv[optind]);
+ fprintf(stderr,
+ gettext("Try '%s --help' for more information.\n"),
progname);
ExitPostmaster(1);
}
* for lack of buffers. The specific choices here are somewhat
* arbitrary.
*/
- postmaster_error("The number of buffers (-B) must be at least twice the number of allowed connections (-N) and at least 16.");
+ postmaster_error("the number of buffers (-B) must be at least twice the number of allowed connections (-N) and at least 16");
ExitPostmaster(1);
}
if (ReservedBackends >= MaxBackends)
{
- postmaster_error("superuser_reserved_connections must be less than max_connections.");
+ postmaster_error("superuser_reserved_connections must be less than max_connections");
ExitPostmaster(1);
}
*/
if (!CheckDateTokenTables())
{
- postmaster_error("Invalid datetoken tables, please fix.");
+ postmaster_error("invalid datetoken tables, please fix");
ExitPostmaster(1);
}
#ifdef USE_SSL
if (EnableSSL && !NetServer)
{
- postmaster_error("For SSL, TCP/IP connections must be enabled.");
- fprintf(stderr, gettext("Try '%s --help' for more information.\n"), progname);
+ postmaster_error("for SSL, TCP/IP connections must be enabled");
ExitPostmaster(1);
}
if (EnableSSL)
* :-(). For the same reason, it's best to grab the TCP socket before
* the Unix socket.
*/
- if (!CreateDataDirLockFile(DataDir, true))
- ExitPostmaster(1);
+ CreateDataDirLockFile(DataDir, true);
/*
* Remove old temporary files. At this point there can be no other
UnixSocketDir,
ListenSocket, MAXLISTEN);
if (status != STATUS_OK)
- {
- postmaster_error("could not create listen socket for \"%s\"",
- curhost);
- }
+ ereport(LOG,
+ (errmsg("could not create listen socket for \"%s\"",
+ curhost)));
if (endptr)
{
*endptr = c;
UnixSocketDir,
ListenSocket, MAXLISTEN);
if (status != STATUS_OK)
- {
- postmaster_error("could not create TCP/IP listen socket");
- }
+ ereport(LOG,
+ (errmsg("could not create TCP/IP listen socket")));
}
#ifdef USE_RENDEZVOUS
UnixSocketDir,
ListenSocket, MAXLISTEN);
if (status != STATUS_OK)
- {
- postmaster_error("could not create UNIX stream port");
- ExitPostmaster(1);
- }
+ ereport(FATAL,
+ (errmsg("could not create UNIX stream port")));
#endif
XLOGPathInit();
pid = fork();
if (pid == (pid_t) -1)
{
- postmaster_error("fork failed: %s", strerror(errno));
+ postmaster_error("could not fork background process: %s",
+ strerror(errno));
ExitPostmaster(1);
- return; /* not reached */
}
else if (pid)
{ /* parent */
#ifdef HAVE_SETSID
if (setsid() < 0)
{
- postmaster_error("cannot disassociate from controlling TTY: %s",
+ postmaster_error("could not disassociate from controlling TTY: %s",
strerror(errno));
ExitPostmaster(1);
}
ereport(LOG,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
- SignalChildren(SIGQUIT);
ExitPostmaster(1);
}
pid, exitstatus);
ExitPostmaster(1);
}
+ /* Normal postmaster exit is here */
ExitPostmaster(0);
}
*
* Do NOT call exit() directly --- always go through here!
*/
-void
+static void
ExitPostmaster(int status)
{
/* should cleanup shared memory and kill all backends */
CreateOptsFile(int argc, char *argv[])
{
char fullprogname[MAXPGPATH];
- char *filename;
+ char filename[MAXPGPATH];
FILE *fp;
- unsigned i;
+ int i;
if (FindExec(fullprogname, argv[0], "postmaster") < 0)
return false;
- filename = palloc(strlen(DataDir) + 17);
- sprintf(filename, "%s/postmaster.opts", DataDir);
+ snprintf(filename, sizeof(filename), "%s/postmaster.opts", DataDir);
if ((fp = fopen(filename, "w")) == NULL)
{
- postmaster_error("cannot create file \"%s\": %s",
- filename, strerror(errno));
+ elog(LOG, "could not create file \"%s\": %m", filename);
return false;
}
fprintf(fp, " '%s'", argv[i]);
fputs("\n", fp);
+ fflush(fp);
if (ferror(fp))
{
- postmaster_error("writing file %s failed", filename);
+ elog(LOG, "could not write file \"%s\": %m", filename);
fclose(fp);
return false;
}
}
/*
- * This should be used only for reporting "interactive" errors (ie, errors
- * during startup). Once the postmaster is launched, use ereport.
+ * This should be used only for reporting "interactive" errors (essentially,
+ * bogus arguments on the command line). Once the postmaster is launched,
+ * use ereport. In particular, don't use this for anything that occurs
+ * after pmdaemonize.
*/
-void
+static void
postmaster_error(const char *fmt,...)
{
va_list ap;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/s_lock.c,v 1.11 2003/04/20 21:54:34 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/s_lock.c,v 1.12 2003/07/27 21:49:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static void
s_lock_stuck(volatile slock_t *lock, const char *file, int line)
{
+#if defined(S_LOCK_TEST)
fprintf(stderr,
- "\nFATAL: s_lock(%p) at %s:%d, stuck spinlock. Aborting.\n",
- lock, file, line);
- fprintf(stdout,
- "\nFATAL: s_lock(%p) at %s:%d, stuck spinlock. Aborting.\n",
+ "\nFATAL: stuck spinlock (%p) detected at %s:%d.\n",
lock, file, line);
abort();
+#else
+ elog(PANIC, "stuck spinlock (%p) detected at %s:%d",
+ lock, file, line);
+#endif
}
printf("S_LOCK_TEST: failed, lock not locked~\n");
exit(3);
-
}
#endif /* S_LOCK_TEST */
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.351 2003/07/22 19:00:11 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.352 2003/07/27 21:49:54 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
{
if (!potential_DataDir)
{
- fprintf(stderr, "%s does not know where to find the database system "
- "data. You must specify the directory that contains the "
- "database system either by specifying the -D invocation "
- "option or by setting the PGDATA environment variable.\n\n",
+ fprintf(stderr,
+ gettext("%s does not know where to find the database system data.\n"
+ "You must specify the directory that contains the database system\n"
+ "either by specifying the -D invocation option or by setting the\n"
+ "PGDATA environment variable.\n"),
argv[0]);
proc_exit(1);
}
/*
* Create lockfile for data directory.
*/
- if (!CreateDataDirLockFile(DataDir, false))
- proc_exit(1);
+ CreateDataDirLockFile(DataDir, false);
XLOGPathInit();
BaseInit();
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.351 $ $Date: 2003/07/22 19:00:11 $\n");
+ puts("$Revision: 1.352 $ $Date: 2003/07/27 21:49:54 $\n");
}
/*
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.114 2003/07/22 19:00:12 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.115 2003/07/27 21:49:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* GUC parameters */
PGErrorVerbosity Log_error_verbosity = PGERROR_VERBOSE;
-bool Log_timestamp; /* show timestamps in stderr output */
-bool Log_pid; /* show PIDs in stderr output */
+bool Log_timestamp = false; /* show timestamps in stderr output */
+bool Log_pid = false; /* show PIDs in stderr output */
#ifdef HAVE_SYSLOG
/*
static char errorstr_buf[48];
const char *str;
- if (errnum == ERANGE)
- /* small trick to save creating many regression test result files */
- str = gettext("Numerical result out of range");
- else
- str = strerror(errnum);
+ str = strerror(errnum);
/*
* Some strerror()s return an empty string for out-of-range errno.
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.106 2003/07/27 19:39:13 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.107 2003/07/27 21:49:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
}
/*
- * Create a lockfile, if possible
- *
- * Call CreateLockFile with the name of the lockfile to be created.
- * Returns true if successful, false if not (with a message on stderr).
+ * Create a lockfile.
*
+ * filename is the name of the lockfile to create.
* amPostmaster is used to determine how to encode the output PID.
* isDDLock and refName are used to determine what error message to produce.
*/
-static bool
+static void
CreateLockFile(const char *filename, bool amPostmaster,
bool isDDLock, const char *refName)
{
))
{
/* lockfile belongs to a live process */
- fprintf(stderr, "Lock file \"%s\" already exists.\n",
- filename);
- if (isDDLock)
- fprintf(stderr,
- "Is another %s (pid %d) running in \"%s\"?\n",
- (encoded_pid < 0 ? "postgres" : "postmaster"),
- (int) other_pid, refName);
- else
- fprintf(stderr,
- "Is another %s (pid %d) using \"%s\"?\n",
- (encoded_pid < 0 ? "postgres" : "postmaster"),
- (int) other_pid, refName);
- return false;
+ ereport(FATAL,
+ (errcode(ERRCODE_LOCK_FILE_EXISTS),
+ errmsg("lock file \"%s\" already exists",
+ filename),
+ isDDLock ?
+ errhint("Is another %s (pid %d) running in \"%s\"?",
+ (encoded_pid < 0 ? "postgres" : "postmaster"),
+ (int) other_pid, refName) :
+ errhint("Is another %s (pid %d) using \"%s\"?",
+ (encoded_pid < 0 ? "postgres" : "postmaster"),
+ (int) other_pid, refName)));
}
}
if (sscanf(ptr, "%lu %lu", &id1, &id2) == 2)
{
if (PGSharedMemoryIsInUse(id1, id2))
- {
- fprintf(stderr,
- "Found a pre-existing shared memory block (key %lu, id %lu) still in use.\n"
- "If you're sure there are no old backends still running,\n"
- "remove the shared memory block with ipcrm(1), or just\n"
- "delete \"%s\".\n",
- id1, id2, filename);
- return false;
- }
+ ereport(FATAL,
+ (errcode(ERRCODE_LOCK_FILE_EXISTS),
+ errmsg("pre-existing shared memory block "
+ "(key %lu, id %lu) is still in use",
+ id1, id2),
+ errhint("If you're sure there are no old "
+ "backends still running, remove "
+ "the shared memory block with "
+ "ipcrm(1), or just delete \"%s\".",
+ filename)));
}
}
}
* Arrange for automatic removal of lockfile at proc_exit.
*/
on_proc_exit(UnlinkLockFile, PointerGetDatum(strdup(filename)));
-
- return true; /* Success! */
}
-bool
+void
CreateDataDirLockFile(const char *datadir, bool amPostmaster)
{
char lockfile[MAXPGPATH];
snprintf(lockfile, sizeof(lockfile), "%s/postmaster.pid", datadir);
- if (!CreateLockFile(lockfile, amPostmaster, true, datadir))
- return false;
+ CreateLockFile(lockfile, amPostmaster, true, datadir);
/* Save name of lockfile for RecordSharedMemoryInLockFile */
strcpy(directoryLockFile, lockfile);
- return true;
}
-bool
+void
CreateSocketLockFile(const char *socketfile, bool amPostmaster)
{
char lockfile[MAXPGPATH];
snprintf(lockfile, sizeof(lockfile), "%s.lock", socketfile);
- if (!CreateLockFile(lockfile, amPostmaster, false, socketfile))
- return false;
+ CreateLockFile(lockfile, amPostmaster, false, socketfile);
/* Save name of lockfile for TouchSocketLockFile */
strcpy(socketLockFile, lockfile);
- return true;
}
/*
if (*endptr == '.')
my_minor = strtol(endptr + 1, NULL, 10);
- snprintf(full_path, MAXPGPATH, "%s/PG_VERSION", path);
+ snprintf(full_path, sizeof(full_path), "%s/PG_VERSION", path);
file = AllocateFile(full_path, "r");
if (!file)
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: miscadmin.h,v 1.127 2003/07/27 17:10:07 tgl Exp $
+ * $Id: miscadmin.h,v 1.128 2003/07/27 21:49:54 tgl Exp $
*
* NOTES
* some of the information in this file should be moved to
extern void BaseInit(void);
/* in utils/init/miscinit.c */
-extern bool CreateDataDirLockFile(const char *datadir, bool amPostmaster);
-extern bool CreateSocketLockFile(const char *socketfile, bool amPostmaster);
+extern void CreateDataDirLockFile(const char *datadir, bool amPostmaster);
+extern void CreateSocketLockFile(const char *socketfile, bool amPostmaster);
extern void TouchSocketLockFile(void);
extern void RecordSharedMemoryInLockFile(unsigned long id1,
unsigned long id2);
*
* Copyright (c) 2003, PostgreSQL Global Development Group
*
- * $Id: errcodes.h,v 1.1 2003/07/27 18:37:52 tgl Exp $
+ * $Id: errcodes.h,v 1.2 2003/07/27 21:49:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* Class F0 - Configuration File Error (PostgreSQL-specific error class) */
#define ERRCODE_CONFIG_FILE_ERROR MAKE_SQLSTATE('F','0', '0','0','0')
+#define ERRCODE_LOCK_FILE_EXISTS MAKE_SQLSTATE('F','0', '0','0','1')
/* Class XX - Internal Error (PostgreSQL-specific error class) */
/* (this is for "can't-happen" conditions and software bugs) */
* procedural language
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.45 2003/07/25 23:37:28 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.46 2003/07/27 21:49:54 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
plpgsql_convert_ident(yytext, &name, 1);
if (name[0] != '$')
- yyerror("can only alias positional parameters");
+ yyerror("only positional parameters may be aliased");
plpgsql_ns_setlocal(false);
nsi = plpgsql_ns_lookup(name, NULL);
switch (tok)
{
case 0:
- yyerror("unexpected end of file");
+ yyerror("unexpected end of function");
case K_NULL:
if (yylex() != ';')
- yyerror("expected ; after NULL");
+ yyerror("expected \";\" after \"NULL\"");
free(expr);
plpgsql_dstring_free(&ds);
break;
}
if (yylex() != ';')
- yyerror("expected ';'");
+ yyerror("expected \";\"");
}
else
new->expr = plpgsql_read_expression(';', ";");
else if (tok == T_ROW)
new->row = yylval.row;
else
- yyerror("Incorrect argument to RETURN NEXT");
+ yyerror("incorrect argument to RETURN NEXT");
if (yylex() != ';')
- yyerror("Expected ';'");
+ yyerror("expected \";\"");
}
else
new->expr = plpgsql_read_expression(';', ";");
cp += strlen(cp) - 1;
if (*cp != ')')
- yyerror("missing )");
+ yyerror("expected \")\"");
*cp = '\0';
}
else
yyerror("cannot assign to tg_argv");
break;
default:
- yyerror("check_assignable: unexpected datum type");
+ elog(ERROR, "unrecognized dtype: %d", datum->dtype);
break;
}
}
* procedural language
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.62 2003/07/27 18:38:26 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.63 2003/07/27 21:49:54 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
trigarg->dtype = PLPGSQL_DTYPE_TRIGARG;
if (plpgsql_yylex() != '[')
- plpgsql_yyerror("expected [");
+ plpgsql_yyerror("expected \"[\"");
trigarg->argnum = plpgsql_read_expression(']', "]");
/*
- * $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.56 2003/05/27 17:49:47 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.57 2003/07/27 21:49:55 tgl Exp $
*/
#include "postgres.h"
int len;
char *new_string;
- if (!(new_string = palloc0(NAMEDATALEN)))
- {
- fprintf(stderr, "reverse_name: palloc failed\n");
- return NULL;
- }
+ new_string = palloc0(NAMEDATALEN);
for (i = 0; i < NAMEDATALEN && string[i]; ++i)
;
if (i == NAMEDATALEN || !string[i])