mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
elog mop-up: bring some straggling fprintf(stderr)'s into the elog world.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
void
|
||||
elog(int lev, const char *fmt,...)
|
||||
|
||||
|
||||
bool
|
||||
errstart(int elevel, const char *filename, int lineno,
|
||||
const char *funcname)
|
||||
{
|
||||
if (lev >= ERROR)
|
||||
{
|
||||
fprintf(stderr, "elog(%s)\n", fmt);
|
||||
abort();
|
||||
}
|
||||
return (elevel >= ERROR);
|
||||
}
|
||||
|
||||
void
|
||||
errfinish(int dummy, ...)
|
||||
{
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user