Commit e8f43854 authored by Bruce Momjian's avatar Bruce Momjian

pq/signal() portability patch. Also psql copy prompt fix.

parent 7f00f11c
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.12 1996/11/22 04:32:41 bryanh Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.13 1996/12/26 22:06:59 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "access/skey.h" #include "access/skey.h"
#include "access/strat.h" #include "access/strat.h"
#include "utils/rel.h" #include "utils/rel.h"
#include "libpq/pqsignal.h"
#include "storage/block.h" #include "storage/block.h"
#include "storage/off.h" #include "storage/off.h"
...@@ -291,10 +292,10 @@ BootstrapMain(int argc, char *argv[]) ...@@ -291,10 +292,10 @@ BootstrapMain(int argc, char *argv[])
* initialize signal handlers * initialize signal handlers
* ---------------- * ----------------
*/ */
signal(SIGINT, (sig_func) die); pqsignal(SIGINT, (sig_func) die);
#ifndef win32 #ifndef win32
signal(SIGHUP, (sig_func) die); pqsignal(SIGHUP, (sig_func) die);
signal(SIGTERM, (sig_func) die); pqsignal(SIGTERM, (sig_func) die);
#endif /* win32 */ #endif /* win32 */
/* -------------------- /* --------------------
...@@ -406,7 +407,7 @@ BootstrapMain(int argc, char *argv[]) ...@@ -406,7 +407,7 @@ BootstrapMain(int argc, char *argv[])
* ---------------- * ----------------
*/ */
#ifndef win32 #ifndef win32
signal(SIGHUP, handle_warn); pqsignal(SIGHUP, handle_warn);
if (sigsetjmp(Warn_restart, 1) != 0) { if (sigsetjmp(Warn_restart, 1) != 0) {
#else #else
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.9 1996/11/24 04:05:20 bryanh Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.10 1996/12/26 22:07:03 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#ifndef WIN32 #ifndef WIN32
...@@ -57,7 +58,7 @@ ...@@ -57,7 +58,7 @@
#include <postgres.h> #include <postgres.h>
#include <libpq/pqsignal.h> /* substitute for <signal.h> */ #include <libpq/pqsignal.h>
#include <libpq/auth.h> #include <libpq/auth.h>
#include <libpq/libpq.h> /* where the declarations go */ #include <libpq/libpq.h> /* where the declarations go */
...@@ -496,7 +497,7 @@ pq_regoob(void (*fptr)()) ...@@ -496,7 +497,7 @@ pq_regoob(void (*fptr)())
#else /* hpux */ #else /* hpux */
fcntl(fd, F_SETOWN, getpid()); fcntl(fd, F_SETOWN, getpid());
#endif /* hpux */ #endif /* hpux */
(void) signal(SIGURG,fptr); (void) pqsignal(SIGURG,fptr);
#endif /* WIN32 */ #endif /* WIN32 */
} }
...@@ -504,7 +505,7 @@ void ...@@ -504,7 +505,7 @@ void
pq_unregoob() pq_unregoob()
{ {
#ifndef WIN32 #ifndef WIN32
signal(SIGURG,SIG_DFL); pqsignal(SIGURG,SIG_DFL);
#endif /* WIN32 */ #endif /* WIN32 */
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.4 1996/11/18 02:25:09 bryanh Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.5 1996/12/26 22:07:08 momjian Exp $
* *
* NOTES * NOTES
* This shouldn't be in libpq, but the monitor and some other * This shouldn't be in libpq, but the monitor and some other
...@@ -39,12 +39,16 @@ ...@@ -39,12 +39,16 @@
* ------------------------------------------------------------------------*/ * ------------------------------------------------------------------------*/
#include <postgres.h> #include <postgres.h>
#include <signal.h>
#include <libpq/pqsignal.h> #include <libpq/pqsignal.h>
pqsigfunc pqsigfunc
pqsignal(int signo, pqsigfunc func) pqsignal(int signo, pqsigfunc func)
{ {
#if defined(USE_POSIX_SIGNALS) #if !defined(USE_POSIX_SIGNALS)
return signal(signo, func);
#else
struct sigaction act, oact; struct sigaction act, oact;
act.sa_handler = func; act.sa_handler = func;
...@@ -56,8 +60,5 @@ pqsignal(int signo, pqsigfunc func) ...@@ -56,8 +60,5 @@ pqsignal(int signo, pqsigfunc func)
if (sigaction(signo, &act, &oact) < 0) if (sigaction(signo, &act, &oact) < 0)
return(SIG_ERR); return(SIG_ERR);
return(oact.sa_handler); return(oact.sa_handler);
#else /* !USE_POSIX_SIGNALS */
Assert(0);
return 0;
#endif /* !USE_POSIX_SIGNALS */ #endif /* !USE_POSIX_SIGNALS */
} }
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.29 1996/12/26 17:49:05 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.30 1996/12/26 22:07:17 momjian Exp $
* *
* NOTES * NOTES
* *
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#include "postgres.h" #include "postgres.h"
#include "libpq/pqsignal.h" /* substitute for <signal.h> */ #include <signal.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
#include "libpq/libpq.h" #include "libpq/libpq.h"
#include "libpq/auth.h" #include "libpq/auth.h"
#include "libpq/pqcomm.h" #include "libpq/pqcomm.h"
#include "libpq/pqsignal.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "version.h" #include "version.h"
#include "lib/dllist.h" #include "lib/dllist.h"
...@@ -394,14 +395,14 @@ PostmasterMain(int argc, char *argv[]) ...@@ -394,14 +395,14 @@ PostmasterMain(int argc, char *argv[])
if (silentflag) if (silentflag)
pmdaemonize(); pmdaemonize();
signal(SIGINT, pmdie); pqsignal(SIGINT, pmdie);
#ifndef WIN32 #ifndef WIN32
signal(SIGCHLD, reaper); pqsignal(SIGCHLD, reaper);
signal(SIGTTIN, SIG_IGN); pqsignal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN); pqsignal(SIGTTOU, SIG_IGN);
signal(SIGHUP, pmdie); pqsignal(SIGHUP, pmdie);
signal(SIGTERM, pmdie); pqsignal(SIGTERM, pmdie);
signal(SIGCONT, dumpstatus); pqsignal(SIGCONT, dumpstatus);
#endif /* WIN32 */ #endif /* WIN32 */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.11 1996/11/27 07:17:48 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.12 1996/12/26 22:07:28 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
* This is so that we can support more backends. (system-wide semaphore * This is so that we can support more backends. (system-wide semaphore
* sets run out pretty fast.) -ay 4/95 * sets run out pretty fast.) -ay 4/95
* *
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.11 1996/11/27 07:17:48 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.12 1996/12/26 22:07:28 momjian Exp $
*/ */
#include <sys/time.h> #include <sys/time.h>
#ifndef WIN32 #ifndef WIN32
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
#include "postgres.h" #include "postgres.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "libpq/pqsignal.h" /* substitute for <signal.h> */ #include "libpq/pqsignal.h"
#include "access/xact.h" #include "access/xact.h"
#include "utils/hsearch.h" #include "utils/hsearch.h"
...@@ -157,7 +157,7 @@ InitProcess(IPCKey key) ...@@ -157,7 +157,7 @@ InitProcess(IPCKey key)
* ------------------ * ------------------
*/ */
#ifndef WIN32 #ifndef WIN32
signal(SIGALRM, HandleDeadLock); pqsignal(SIGALRM, HandleDeadLock);
#endif /* WIN32 we'll have to figure out how to handle this later */ #endif /* WIN32 we'll have to figure out how to handle this later */
SpinAcquire(ProcStructLock); SpinAcquire(ProcStructLock);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.23 1996/12/07 04:39:06 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.24 1996/12/26 22:07:40 momjian Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "libpq/pqsignal.h" /* substitute for <signal.h> */
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h>
#include <time.h> #include <time.h>
#include <setjmp.h> #include <setjmp.h>
#include <sys/time.h> #include <sys/time.h>
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
#include "tcop/fastpath.h" #include "tcop/fastpath.h"
#include "libpq/libpq.h" #include "libpq/libpq.h"
#include "libpq/pqsignal.h"
#include "rewrite/rewriteHandler.h" /* for QueryRewrite() */ #include "rewrite/rewriteHandler.h" /* for QueryRewrite() */
/* ---------------- /* ----------------
...@@ -820,15 +821,15 @@ PostgresMain(int argc, char *argv[]) ...@@ -820,15 +821,15 @@ PostgresMain(int argc, char *argv[])
* register signal handlers. * register signal handlers.
* ---------------- * ----------------
*/ */
signal(SIGINT, die); pqsignal(SIGINT, die);
#ifndef WIN32 #ifndef WIN32
signal(SIGHUP, die); pqsignal(SIGHUP, die);
signal(SIGTERM, die); pqsignal(SIGTERM, die);
signal(SIGPIPE, die); pqsignal(SIGPIPE, die);
signal(SIGUSR1, quickdie); pqsignal(SIGUSR1, quickdie);
signal(SIGUSR2, Async_NotifyHandler); pqsignal(SIGUSR2, Async_NotifyHandler);
signal(SIGFPE, FloatExceptionHandler); pqsignal(SIGFPE, FloatExceptionHandler);
#endif /* WIN32 */ #endif /* WIN32 */
/* -------------------- /* --------------------
...@@ -1246,7 +1247,7 @@ PostgresMain(int argc, char *argv[]) ...@@ -1246,7 +1247,7 @@ PostgresMain(int argc, char *argv[])
*/ */
#ifndef WIN32 #ifndef WIN32
signal(SIGHUP, handle_warn); pqsignal(SIGHUP, handle_warn);
if (sigsetjmp(Warn_restart, 1) != 0) { if (sigsetjmp(Warn_restart, 1) != 0) {
#else #else
...@@ -1271,7 +1272,7 @@ PostgresMain(int argc, char *argv[]) ...@@ -1271,7 +1272,7 @@ PostgresMain(int argc, char *argv[])
*/ */
if (IsUnderPostmaster == false) { if (IsUnderPostmaster == false) {
puts("\nPOSTGRES backend interactive interface"); puts("\nPOSTGRES backend interactive interface");
puts("$Revision: 1.23 $ $Date: 1996/12/07 04:39:06 $"); puts("$Revision: 1.24 $ $Date: 1996/12/26 22:07:40 $");
} }
/* ---------------- /* ----------------
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.41 1996/12/26 20:56:40 bryanh Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.42 1996/12/26 22:07:57 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <ctype.h> #include <ctype.h>
#include "postgres.h" #include "postgres.h"
#include "libpq-fe.h" #include "libpq-fe.h"
#include "pqsignal.h"
#include "stringutils.h" #include "stringutils.h"
#include "psqlHelp.h" #include "psqlHelp.h"
#ifdef NEED_STRDUP #ifdef NEED_STRDUP
...@@ -513,19 +514,10 @@ SendQuery(bool * success_p, PsqlSettings * settings, const char *query, ...@@ -513,19 +514,10 @@ SendQuery(bool * success_p, PsqlSettings * settings, const char *query,
break; break;
case PGRES_COPY_IN: case PGRES_COPY_IN:
*success_p = true; *success_p = true;
if (copy_in) { if (copy_in)
handleCopyIn(results, false, copystream); handleCopyIn(results, false, copystream);
} else { else
char c;
/*
* eat extra newline still in input buffer
*
*/
fflush(stdin);
if ((c = getc(stdin)) != '\n' && c != EOF)
(void) ungetc(c, stdin);
handleCopyIn(results, !settings->quiet, stdin); handleCopyIn(results, !settings->quiet, stdin);
}
break; break;
case PGRES_NONFATAL_ERROR: case PGRES_NONFATAL_ERROR:
case PGRES_FATAL_ERROR: case PGRES_FATAL_ERROR:
...@@ -1676,15 +1668,18 @@ setFout(PsqlSettings * ps, char *fname) ...@@ -1676,15 +1668,18 @@ setFout(PsqlSettings * ps, char *fname)
else else
fclose(ps->queryFout); fclose(ps->queryFout);
} }
if (!fname) if (!fname) {
ps->queryFout = stdout; ps->queryFout = stdout;
pqsignal(SIGPIPE, SIG_DFL);
}
else { else {
if (*fname == '|') { if (*fname == '|') {
signal(SIGPIPE, SIG_IGN); pqsignal(SIGPIPE, SIG_IGN);
ps->queryFout = popen(fname + 1, "w"); ps->queryFout = popen(fname + 1, "w");
ps->pipe = 1; ps->pipe = 1;
} else { } else {
ps->queryFout = fopen(fname, "w"); ps->queryFout = fopen(fname, "w");
pqsignal(SIGPIPE, SIG_DFL);
ps->pipe = 0; ps->pipe = 0;
} }
if (!ps->queryFout) { if (!ps->queryFout) {
......
...@@ -85,8 +85,7 @@ ...@@ -85,8 +85,7 @@
#if defined(dgux) #if defined(dgux)
# define LINUX_ELF # define LINUX_ELF
# define NEED_UNION_SEMUN # define NEED_UNION_SEMUN
# define __USE_POSIX_SIGNALS # define USE_POSIX_SIGNALS
# define -DUSE_POSIX_SIGNALS
#endif #endif
#if defined(hpux) #if defined(hpux)
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: pqsignal.h,v 1.4 1996/11/24 04:07:17 bryanh Exp $ * $Id: pqsignal.h,v 1.5 1996/12/26 22:08:13 momjian Exp $
* *
* NOTES * NOTES
* This shouldn't be in libpq, but the monitor and some other * This shouldn't be in libpq, but the monitor and some other
...@@ -17,14 +17,8 @@ ...@@ -17,14 +17,8 @@
#ifndef PQSIGNAL_H #ifndef PQSIGNAL_H
#define PQSIGNAL_H #define PQSIGNAL_H
#include <signal.h>
typedef void (*pqsigfunc)(int); typedef void (*pqsigfunc)(int);
extern pqsigfunc pqsignal(int signo, pqsigfunc func); extern pqsigfunc pqsignal(int signo, pqsigfunc func);
#if defined(USE_POSIX_SIGNALS)
#define signal(signo, handler) pqsignal(signo, (pqsigfunc)(handler))
#endif /* USE_POSIX_SIGNALS */
#endif /* PQSIGNAL_H */ #endif /* PQSIGNAL_H */
...@@ -7,22 +7,24 @@ ...@@ -7,22 +7,24 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.23 1996/12/24 09:03:16 bryanh Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.24 1996/12/26 22:08:21 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "postgres.h" #include "postgres.h"
#include "libpq/pqcomm.h" #include "libpq/pqcomm.h"
#include "libpq/pqsignal.h"
#include "libpq-fe.h" #include "libpq-fe.h"
#include <signal.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include TERMIOS_H_LOCATION #include TERMIOS_H_LOCATION
#ifdef TIOCGWINSZ #ifdef TIOCGWINSZ
struct winsize screen_size; struct winsize screen_size;
#else #else
...@@ -1125,7 +1127,7 @@ PQprint(FILE *fout, ...@@ -1125,7 +1127,7 @@ PQprint(FILE *fout,
fout = popen(pagerenv, "w"); fout = popen(pagerenv, "w");
if (fout) { if (fout) {
usePipe = 1; usePipe = 1;
signal(SIGPIPE, SIG_IGN); pqsignal(SIGPIPE, SIG_IGN);
} else } else
fout = stdout; fout = stdout;
} }
...@@ -1217,7 +1219,7 @@ PQprint(FILE *fout, ...@@ -1217,7 +1219,7 @@ PQprint(FILE *fout,
free(fieldNames); free(fieldNames);
if (usePipe) { if (usePipe) {
pclose(fout); pclose(fout);
signal(SIGPIPE, SIG_DFL); pqsignal(SIGPIPE, SIG_DFL);
} }
if (border) if (border)
free(border); free(border);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/pqsignal.c,v 1.2 1996/11/08 06:02:30 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/pqsignal.c,v 1.3 1996/12/26 22:08:30 momjian Exp $
* *
* NOTES * NOTES
* This shouldn't be in libpq, but the monitor and some other * This shouldn't be in libpq, but the monitor and some other
...@@ -18,12 +18,16 @@ ...@@ -18,12 +18,16 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <signal.h>
#include "libpq/pqsignal.h" #include "libpq/pqsignal.h"
pqsigfunc pqsigfunc
pqsignal(int signo, pqsigfunc func) pqsignal(int signo, pqsigfunc func)
{ {
#if defined(USE_POSIX_SIGNALS) #if !defined(USE_POSIX_SIGNALS)
return signal(signo, func);
#else
struct sigaction act, oact; struct sigaction act, oact;
act.sa_handler = func; act.sa_handler = func;
...@@ -35,8 +39,5 @@ pqsignal(int signo, pqsigfunc func) ...@@ -35,8 +39,5 @@ pqsignal(int signo, pqsigfunc func)
if (sigaction(signo, &act, &oact) < 0) if (sigaction(signo, &act, &oact) < 0)
return(SIG_ERR); return(SIG_ERR);
return(oact.sa_handler); return(oact.sa_handler);
#else /* !USE_POSIX_SIGNALS */
exit(1); /* this should never be reached, pqsignal should only
be called if USE_POSIX_SIGNALS is true*/
#endif /* !USE_POSIX_SIGNALS */ #endif /* !USE_POSIX_SIGNALS */
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: pqsignal.h,v 1.1.1.1 1996/07/09 06:22:17 scrappy Exp $ * $Id: pqsignal.h,v 1.2 1996/12/26 22:08:34 momjian Exp $
* *
* NOTES * NOTES
* This shouldn't be in libpq, but the monitor and some other * This shouldn't be in libpq, but the monitor and some other
...@@ -17,16 +17,10 @@ ...@@ -17,16 +17,10 @@
#ifndef PQSIGNAL_H #ifndef PQSIGNAL_H
#define PQSIGNAL_H #define PQSIGNAL_H
#include <signal.h>
#include "c.h" #include "c.h"
typedef void (*pqsigfunc)(int); typedef void (*pqsigfunc)(int);
extern pqsigfunc pqsignal(int signo, pqsigfunc func); extern pqsigfunc pqsignal(int signo, pqsigfunc func);
#if defined(USE_POSIX_SIGNALS)
#define signal(signo, handler) pqsignal(signo, (pqsigfunc)(handler))
#endif /* USE_POSIX_SIGNALS */
#endif /* PQSIGNAL_H */ #endif /* PQSIGNAL_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment