elog mop-up: bring some straggling fprintf(stderr)'s into the elog world.
authorTom Lane <[email protected]>
Sun, 27 Jul 2003 21:49:55 +0000 (21:49 +0000)
committerTom Lane <[email protected]>
Sun, 27 Jul 2003 21:49:55 +0000 (21:49 +0000)
18 files changed:
src/backend/bootstrap/bootstrap.c
src/backend/libpq/be-secure.c
src/backend/libpq/pqcomm.c
src/backend/main/main.c
src/backend/port/ipc_test.c
src/backend/port/posix_sema.c
src/backend/port/sysv_sema.c
src/backend/port/sysv_shmem.c
src/backend/postmaster/postmaster.c
src/backend/storage/lmgr/s_lock.c
src/backend/tcop/postgres.c
src/backend/utils/error/elog.c
src/backend/utils/init/miscinit.c
src/include/miscadmin.h
src/include/utils/errcodes.h
src/pl/plpgsql/src/gram.y
src/pl/plpgsql/src/pl_comp.c
src/test/regress/regress.c

index e30e5c513c0ac41254460ac30751891eb2db1c35..b02fa775dedd7690147c728f34b6d9568b7e9c03 100644 (file)
@@ -8,7 +8,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -359,7 +359,7 @@ BootstrapMain(int argc, char *argv[])
                    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);
        }
@@ -414,8 +414,7 @@ BootstrapMain(int argc, char *argv[])
        /*
         * Create lockfile for data directory.
         */
-       if (!CreateDataDirLockFile(DataDir, false))
-           proc_exit(1);
+       CreateDataDirLockFile(DataDir, false);
    }
 
    SetProcessingMode(BootstrapProcessing);
index 4d482ce73e0439a2f29f441a7e6444baea824bca..0bd4f7874148d23b3ff8d0b82e8b206ad572a81d 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * 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);
@@ -126,6 +118,7 @@ static const char *SSLerrmessage(void);
  */
 #define RENEGOTIATION_LIMIT (512 * 1024 * 1024)
 #define CA_PATH NULL
+
 static SSL_CTX *SSL_context = NULL;
 #endif
 
@@ -607,7 +600,7 @@ info_cb(const SSL *ssl, int type, int args)
 static int
 initialize_SSL(void)
 {
-   char        fnbuf[2048];
+   char        fnbuf[MAXPGPATH];
    struct stat buf;
 
    if (!SSL_context)
@@ -616,50 +609,43 @@ initialize_SSL(void)
        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 */
@@ -668,25 +654,22 @@ initialize_SSL(void)
 
    /* 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;
 }
@@ -716,7 +699,7 @@ open_server_SSL(Port *port)
    {
        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;
@@ -739,7 +722,8 @@ open_server_SSL(Port *port)
                   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);
index 6f2a9d8e6ed2c1ba337b2bf4644ccb4939ce0f72..2f6d0245bf509f99d02f8ee001cd94c4871661a7 100644 (file)
@@ -30,7 +30,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -389,8 +389,7 @@ Lock_AF_UNIX(unsigned short portNumber, char *unixSocketName)
    /*
     * 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
index e03633a3261762499f9c62c89f7d75dbb2bf4117..862194b17d57aaf2dc3433994209e2bc9e1ab110 100644 (file)
@@ -13,7 +13,7 @@
  *
  *
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -81,7 +81,8 @@ main(int argc, char *argv[])
 #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 */
 
@@ -170,12 +171,12 @@ main(int argc, char *argv[])
         */
        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__ */
@@ -191,7 +192,8 @@ main(int argc, char *argv[])
         */
        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);
        }
@@ -236,7 +238,7 @@ main(int argc, char *argv[])
    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);
    }
@@ -249,7 +251,8 @@ main(int argc, char *argv[])
        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);
        }
    }
index b14eeef716f27dc1167d96f60478fa16add47c2e..6d10d3bb8f2f8c23a29db0286e5d829f3f950a9f 100644 (file)
@@ -21,7 +21,7 @@
  *
  *
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -46,6 +46,8 @@ volatile bool ImmediateInterruptOK = false;
 volatile uint32 InterruptHoldoffCount = 0;
 volatile uint32 CritSectionCount = 0;
 
+const bool ExecBackend = false;
+
 bool       IsUnderPostmaster = false;
 
 int            MaxBackends = DEF_MAXBACKENDS;
@@ -128,14 +130,60 @@ ExceptionalCondition(char *conditionName,
    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 */
 }
 
 
index 26788667a493b97b099a4dd7422f41ee3e22d3df..ae73eff02401b02de77525746a70b76b50034a74 100644 (file)
@@ -11,7 +11,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -89,9 +89,7 @@ PosixSemaphoreCreate(void)
        /*
         * 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);
    }
 
    /*
@@ -114,12 +112,9 @@ static void
 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 */
 
 
@@ -132,13 +127,11 @@ PosixSemaphoreKill(sem_t * sem)
 #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
 }
 
@@ -235,9 +228,7 @@ PGSemaphoreReset(PGSemaphore sema)
                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");
        }
    }
 }
@@ -295,11 +286,7 @@ PGSemaphoreLock(PGSemaphore sema, bool interruptOK)
    } 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");
 }
 
 /*
@@ -324,11 +311,7 @@ PGSemaphoreUnlock(PGSemaphore sema)
    } 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");
 }
 
 /*
@@ -356,9 +339,7 @@ PGSemaphoreTryLock(PGSemaphore sema)
        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;
index f9a00d4bedba8b7016e42d24ca0d1bcfc386595f..23131f8a67065b634c6ecb639389aae7a4463f3d 100644 (file)
@@ -8,7 +8,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -113,26 +113,22 @@ InternalIpcSemaphoreCreate(IpcSemaphoreKey semKey, int numSems)
        /*
         * 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;
@@ -148,18 +144,13 @@ IpcSemaphoreInitialize(IpcSemaphoreId semId, int semNum, int value)
 
    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));
 }
 
 /*
@@ -173,13 +164,7 @@ IpcSemaphoreKill(IpcSemaphoreId semId)
    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 */
@@ -436,11 +421,7 @@ PGSemaphoreLock(PGSemaphore sema, bool interruptOK)
    } 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);
 }
 
 /*
@@ -470,11 +451,7 @@ PGSemaphoreUnlock(PGSemaphore sema)
    } 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);
 }
 
 /*
@@ -514,9 +491,7 @@ PGSemaphoreTryLock(PGSemaphore sema)
            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;
index cccfe22d5a5ac6d0391857ac5c0a84c269d3c00d..3f31f21d8e6857609d48280a6f578d5149efbb52 100644 (file)
@@ -10,7 +10,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -88,56 +88,45 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size)
        /*
         * 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 */
@@ -152,11 +141,7 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size)
 #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));
@@ -177,13 +162,7 @@ static void
 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));
 }
 
 /****************************************************************************/
@@ -194,13 +173,8 @@ static void
 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);
 }
 
 /*
@@ -274,11 +248,8 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
    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;
    }
 
index fb64781bf8c09f0ba70506b70f973306875df076..688b13bba56ab251dde922f92bd3a334ce4ac644 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  * 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
  *
@@ -271,7 +271,7 @@ static void CleanupProc(int pid, int exitstatus);
 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);
@@ -290,8 +290,7 @@ static void SignalChildren(int signal);
 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)));
 
@@ -299,29 +298,21 @@ __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);
    }
@@ -353,7 +344,7 @@ checkDataDir(const char *checkdir)
                (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 */
@@ -364,10 +355,10 @@ checkDataDir(const char *checkdir)
    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);
    }
@@ -464,7 +455,7 @@ PostmasterMain(int argc, char *argv[])
 #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':
@@ -589,7 +580,9 @@ PostmasterMain(int argc, char *argv[])
                }
 
            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);
        }
    }
@@ -599,8 +592,9 @@ PostmasterMain(int argc, char *argv[])
     */
    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);
    }
@@ -626,13 +620,13 @@ PostmasterMain(int argc, char *argv[])
         * 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);
    }
 
@@ -641,7 +635,7 @@ PostmasterMain(int argc, char *argv[])
     */
    if (!CheckDateTokenTables())
    {
-       postmaster_error("Invalid datetoken tables, please fix.");
+       postmaster_error("invalid datetoken tables, please fix");
        ExitPostmaster(1);
    }
 
@@ -680,8 +674,7 @@ PostmasterMain(int argc, char *argv[])
 #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)
@@ -713,8 +706,7 @@ PostmasterMain(int argc, char *argv[])
     * :-(). 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
@@ -754,10 +746,9 @@ PostmasterMain(int argc, char *argv[])
                                          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;
@@ -774,9 +765,8 @@ PostmasterMain(int argc, char *argv[])
                                      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                   
@@ -799,10 +789,8 @@ PostmasterMain(int argc, char *argv[])
                              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();
@@ -922,9 +910,9 @@ pmdaemonize(int argc, char *argv[])
    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 */
@@ -944,7 +932,7 @@ pmdaemonize(int argc, char *argv[])
 #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);
    }
@@ -1553,7 +1541,6 @@ ConnCreate(int serverFd)
        ereport(LOG,
                (errcode(ERRCODE_OUT_OF_MEMORY),
                 errmsg("out of memory")));
-       SignalChildren(SIGQUIT);
        ExitPostmaster(1);
    }
 
@@ -1842,6 +1829,7 @@ reaper(SIGNAL_ARGS)
                             pid, exitstatus);
                ExitPostmaster(1);
            }
+           /* Normal postmaster exit is here */
            ExitPostmaster(0);
        }
 
@@ -2545,7 +2533,7 @@ BackendFork(Port *port)
  *
  * Do NOT call exit() directly --- always go through here!
  */
-void
+static void
 ExitPostmaster(int status)
 {
    /* should cleanup shared memory and kill all backends */
@@ -2922,20 +2910,18 @@ static bool
 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;
    }
 
@@ -2944,9 +2930,10 @@ CreateOptsFile(int argc, char *argv[])
        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;
    }
@@ -2956,10 +2943,12 @@ CreateOptsFile(int argc, char *argv[])
 }
 
 /*
- * 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;
index 962ee17a077be86f5d842b8e7fa84519cd94fbd7..08896f01955191da1da0e6baae784ab831f41433 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * 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
 }
 
 
@@ -238,7 +240,6 @@ main()
 
    printf("S_LOCK_TEST: failed, lock not locked~\n");
    exit(3);
-
 }
 
 #endif   /* S_LOCK_TEST */
index ae4a50629f3c868d28453f7ad97d63d45cb4e79c..9b2324b220f9fc31e048b7e461dc57bbab6f917e 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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
@@ -2446,10 +2446,11 @@ PostgresMain(int argc, char *argv[], const char *username)
    {
        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);
        }
@@ -2567,8 +2568,7 @@ PostgresMain(int argc, char *argv[], const char *username)
        /*
         * Create lockfile for data directory.
         */
-       if (!CreateDataDirLockFile(DataDir, false))
-           proc_exit(1);
+       CreateDataDirLockFile(DataDir, false);
 
        XLOGPathInit();
        BaseInit();
@@ -2626,7 +2626,7 @@ PostgresMain(int argc, char *argv[], const char *username)
    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");
    }
 
    /*
index 4564a9f9f2155f95c0df0b48010c3e041c008f18..33b2a720491e6d8b23e710c8ab78c61e7b131c34 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -69,8 +69,8 @@ ErrorContextCallback *error_context_stack = NULL;
 
 /* 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
 /*
@@ -1344,11 +1344,7 @@ useful_strerror(int errnum)
    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.
index f974cf939d099e2964cb4ae5042719411d97d163..4868ec23a33e7c1a4544f1c2d57d1f6102811736 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -697,15 +697,13 @@ UnlinkLockFile(int status, Datum filename)
 }
 
 /*
- * 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)
 {
@@ -786,19 +784,17 @@ CreateLockFile(const char *filename, bool amPostmaster,
                 ))
            {
                /* 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)));
            }
        }
 
@@ -823,15 +819,16 @@ CreateLockFile(const char *filename, bool amPostmaster,
                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)));
                }
            }
        }
@@ -876,34 +873,28 @@ CreateLockFile(const char *filename, bool amPostmaster,
     * 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;
 }
 
 /*
@@ -1062,7 +1053,7 @@ ValidatePgVersion(const char *path)
    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)
index d6ded84abd7e61c4db4cb07064ed52000ca56dd2..5fee7fc25f94d6d20de26e90b913bd6e964a8b55 100644 (file)
@@ -12,7 +12,7 @@
  * 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
@@ -286,8 +286,8 @@ extern void InitPostgres(const char *dbname, const char *username);
 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);
index 818b38318a58aef7e11e5c5b50e4c489b1c61ad9..a6f540fc42cbb3ce7c47ab43ba72527fb73ddbe0 100644 (file)
@@ -11,7 +11,7 @@
  *
  * 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) */
index 8f0f76a4eab696db1a07766a8801c717d9be03f2..97fb17f1b6cd380f1addb3c27d25f8ae8bb66004 100644 (file)
@@ -4,7 +4,7 @@
  *                       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.
  *
@@ -553,7 +553,7 @@ decl_aliasitem  : T_WORD
 
                        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);
@@ -647,10 +647,10 @@ decl_defval       : ';'
                        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);
@@ -1201,7 +1201,7 @@ stmt_return       : K_RETURN lno
                                    break;
                            }
                            if (yylex() != ';')
-                               yyerror("expected ';'");
+                               yyerror("expected \";\"");
                        }
                        else
                            new->expr = plpgsql_read_expression(';', ";");
@@ -1232,10 +1232,10 @@ stmt_return_next: K_RETURN_NEXT lno
                            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(';', ";");
@@ -1467,7 +1467,7 @@ stmt_open     : K_OPEN lno cursor_varptr
                                cp += strlen(cp) - 1;
 
                                if (*cp != ')')
-                                   yyerror("missing )");
+                                   yyerror("expected \")\"");
                                *cp = '\0';
                            }
                            else
@@ -2096,7 +2096,7 @@ check_assignable(PLpgSQL_datum *datum)
            yyerror("cannot assign to tg_argv");
            break;
        default:
-           yyerror("check_assignable: unexpected datum type");
+           elog(ERROR, "unrecognized dtype: %d", datum->dtype);
            break;
    }
 }
index a423e0be5aae215413184589a9ae372d569ab4eb..8ede81d061ec726e9b76a2a0f0e19cfa2c62a54e 100644 (file)
@@ -3,7 +3,7 @@
  *           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.
  *
@@ -755,7 +755,7 @@ plpgsql_parse_word(char *word)
            trigarg->dtype = PLPGSQL_DTYPE_TRIGARG;
 
            if (plpgsql_yylex() != '[')
-               plpgsql_yyerror("expected [");
+               plpgsql_yyerror("expected \"[\"");
 
            trigarg->argnum = plpgsql_read_expression(']', "]");
 
index 17830b91433b3dd10a1476480e361f7883eebab0..04b1a9d7864d9071ab637b989137b82cd52120cf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $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"
@@ -297,11 +297,7 @@ reverse_name(char *string)
    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])