diff options
| author | Marc G. Fournier | 1998-07-09 03:29:11 +0000 |
|---|---|---|
| committer | Marc G. Fournier | 1998-07-09 03:29:11 +0000 |
| commit | a0659e3e2c79be49feb4aa527d823c71d7bcaf07 (patch) | |
| tree | 7dc58e872cdfce999dd0848000fcd3f2e4edbafa /src/backend/libpq | |
| parent | 8bf61820f033d7df0e89433a0272d7b2567378b8 (diff) | |
From: Tom Lane <tgl@sss.pgh.pa.us>
Making PQrequestCancel safe to call in a signal handler turned out to be
much easier than I feared. So here are the diffs.
Some notes:
* I modified the postmaster's packet "iodone" callback interface to allow
the callback routine to return a continue-or-drop-connection return
code; this was necessary to allow the connection to be closed after
receiving a Cancel, rather than proceeding to launch a new backend...
Being a neatnik, I also made the iodone proc have a typechecked
parameter list.
* I deleted all code I could find that had to do with OOB.
* I made some edits to ensure that all signals mentioned in the code
are referred to symbolically not by numbers ("SIGUSR2" not "2").
I think Bruce may have already done at least some of the same edits;
I hope that merging these patches is not too painful.
Diffstat (limited to 'src/backend/libpq')
| -rw-r--r-- | src/backend/libpq/auth.c | 72 | ||||
| -rw-r--r-- | src/backend/libpq/pqcomm.c | 80 | ||||
| -rw-r--r-- | src/backend/libpq/pqpacket.c | 18 |
3 files changed, 55 insertions, 115 deletions
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index 4aee9b9197a..c1cc08f4c79 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.28 1998/06/13 04:27:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.29 1998/07/09 03:28:45 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -40,13 +40,13 @@ #include <libpq/crypt.h> -static void sendAuthRequest(Port *port, AuthRequest areq, void (*handler) ()); -static void handle_done_auth(Port *port); -static void handle_krb4_auth(Port *port); -static void handle_krb5_auth(Port *port); -static void handle_password_auth(Port *port); -static void readPasswordPacket(char *arg, PacketLen len, char *pkt); -static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt); +static void sendAuthRequest(Port *port, AuthRequest areq, PacketDoneProc handler); +static int handle_done_auth(void *arg, PacketLen len, void *pkt); +static int handle_krb4_auth(void *arg, PacketLen len, void *pkt); +static int handle_krb5_auth(void *arg, PacketLen len, void *pkt); +static int handle_password_auth(void *arg, PacketLen len, void *pkt); +static int readPasswordPacket(void *arg, PacketLen len, void *pkt); +static int pg_passwordv0_recvauth(void *arg, PacketLen len, void *pkt); static int checkPassword(Port *port, char *user, char *password); static int old_be_recvauth(Port *port); static int map_old_to_new(Port *port, UserAuth old, int status); @@ -327,8 +327,8 @@ pg_krb5_recvauth(Port *port) * Handle a v0 password packet. */ -static void -pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt) +static int +pg_passwordv0_recvauth(void *arg, PacketLen len, void *pkt) { Port *port; PasswordPacketV0 *pp; @@ -393,6 +393,8 @@ pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt) if (map_old_to_new(port, uaPassword, status) != STATUS_OK) auth_failed(port); } + + return (STATUS_OK); /* don't close the connection yet */ } @@ -433,7 +435,7 @@ be_recvauth(Port *port) else { AuthRequest areq; - void (*auth_handler) (); + PacketDoneProc auth_handler; /* Keep the compiler quiet. */ @@ -499,7 +501,7 @@ be_recvauth(Port *port) */ static void -sendAuthRequest(Port *port, AuthRequest areq, void (*handler) ()) +sendAuthRequest(Port *port, AuthRequest areq, PacketDoneProc handler) { char *dp, *sp; @@ -527,7 +529,7 @@ sendAuthRequest(Port *port, AuthRequest areq, void (*handler) ()) i += 2; } - PacketSendSetup(&port->pktInfo, i, handler, (char *) port); + PacketSendSetup(&port->pktInfo, i, handler, (void *) port); } @@ -535,8 +537,8 @@ sendAuthRequest(Port *port, AuthRequest areq, void (*handler) ()) * Called when we have told the front end that it is authorised. */ -static void -handle_done_auth(Port *port) +static int +handle_done_auth(void *arg, PacketLen len, void *pkt) { /* @@ -544,7 +546,7 @@ handle_done_auth(Port *port) * start. */ - return; + return STATUS_OK; } @@ -553,13 +555,17 @@ handle_done_auth(Port *port) * authentication. */ -static void -handle_krb4_auth(Port *port) +static int +handle_krb4_auth(void *arg, PacketLen len, void *pkt) { + Port *port = (Port *) arg; + if (pg_krb4_recvauth(port) != STATUS_OK) auth_failed(port); else sendAuthRequest(port, AUTH_REQ_OK, handle_done_auth); + + return STATUS_OK; } @@ -568,13 +574,17 @@ handle_krb4_auth(Port *port) * authentication. */ -static void -handle_krb5_auth(Port *port) +static int +handle_krb5_auth(void *arg, PacketLen len, void *pkt) { + Port *port = (Port *) arg; + if (pg_krb5_recvauth(port) != STATUS_OK) auth_failed(port); else sendAuthRequest(port, AUTH_REQ_OK, handle_done_auth); + + return STATUS_OK; } @@ -583,12 +593,16 @@ handle_krb5_auth(Port *port) * authentication. */ -static void -handle_password_auth(Port *port) +static int +handle_password_auth(void *arg, PacketLen len, void *pkt) { + Port *port = (Port *) arg; + /* Set up the read of the password packet. */ - PacketReceiveSetup(&port->pktInfo, readPasswordPacket, (char *) port); + PacketReceiveSetup(&port->pktInfo, readPasswordPacket, (void *) port); + + return STATUS_OK; } @@ -596,13 +610,11 @@ handle_password_auth(Port *port) * Called when we have received the password packet. */ -static void -readPasswordPacket(char *arg, PacketLen len, char *pkt) +static int +readPasswordPacket(void *arg, PacketLen len, void *pkt) { char password[sizeof(PasswordPacket) + 1]; - Port *port; - - port = (Port *) arg; + Port *port = (Port *) arg; /* Silently truncate a password that is too big. */ @@ -615,6 +627,8 @@ readPasswordPacket(char *arg, PacketLen len, char *pkt) auth_failed(port); else sendAuthRequest(port, AUTH_REQ_OK, handle_done_auth); + + return (STATUS_OK); /* don't close the connection yet */ } @@ -662,7 +676,7 @@ old_be_recvauth(Port *port) case STARTUP_PASSWORD_MSG: PacketReceiveSetup(&port->pktInfo, pg_passwordv0_recvauth, - (char *) port); + (void *) port); return STATUS_OK; diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c index a70bbc22e9c..4c5b85b248b 100644 --- a/src/backend/libpq/pqcomm.c +++ b/src/backend/libpq/pqcomm.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.47 1998/06/27 04:53:30 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.48 1998/07/09 03:28:46 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -30,7 +30,6 @@ * pq_getinserv - initialize address from host and service name * pq_connect - create remote input / output connection * pq_accept - accept remote input / output connection - * pq_async_notify - receive notification from backend. * * NOTES * These functions are used by both frontend applications and @@ -79,7 +78,6 @@ FILE *Pfout, *Pfin; FILE *Pfdebug; /* debugging libpq */ -int PQAsyncNotifyWaiting; /* for async. notification */ /* -------------------------------- * pq_init - open portal file descriptors @@ -160,9 +158,7 @@ pq_close() fclose(Pfout); Pfout = NULL; } - PQAsyncNotifyWaiting = 0; PQnotifies_init(); - pq_unregoob(); } /* -------------------------------- @@ -418,29 +414,6 @@ pq_putint(int i, int b) } } -/* --- - * pq_sendoob - send a string over the out-of-band channel - * pq_recvoob - receive a string over the oob channel - * NB: Fortunately, the out-of-band channel doesn't conflict with - * buffered I/O because it is separate from regular com. channel. - * --- - */ -int -pq_sendoob(char *msg, int len) -{ - int fd = fileno(Pfout); - - return send(fd, msg, len, MSG_OOB); -} - -int -pq_recvoob(char *msgPtr, int len) -{ - int fd = fileno(Pfout); - - return recv(fd, msgPtr, len, MSG_OOB); -} - /* -------------------------------- * pq_getinaddr - initialize address from host and port number * -------------------------------- @@ -508,55 +481,6 @@ pq_getinserv(struct sockaddr_in * sin, char *host, char *serv) } /* - * register an out-of-band listener proc--at most one allowed. - * This is used for receiving async. notification from the backend. - */ -void -pq_regoob(void (*fptr) ()) -{ - int fd = fileno(Pfout); - -#if defined(hpux) - ioctl(fd, FIOSSAIOOWN, MyProcPid); -#elif defined(sco) - ioctl(fd, SIOCSPGRP, MyProcPid); -#else - fcntl(fd, F_SETOWN, MyProcPid); -#endif /* hpux */ - pqsignal(SIGURG, fptr); -} - -void -pq_unregoob() -{ - pqsignal(SIGURG, SIG_DFL); -} - - -void -pq_async_notify() -{ - char msg[20]; - - /* int len = sizeof(msg); */ - int len = 20; - - if (pq_recvoob(msg, len) >= 0) - { - /* debugging */ - printf("received notification: %s\n", msg); - PQAsyncNotifyWaiting = 1; - /* PQappendNotify(msg+1); */ - } - else - { - extern int errno; - - printf("SIGURG but no data: len = %d, err=%d\n", len, errno); - } -} - -/* * Streams -- wrapper around Unix socket system calls * * @@ -620,7 +544,7 @@ StreamServerPort(char *hostName, short portName, int *fdP) pqdebug("%s", PQerrormsg); return (STATUS_ERROR); } - bzero(&saddr, sizeof(saddr)); + MemSet((char *) &saddr, 0, sizeof(saddr)); saddr.sa.sa_family = family; if (family == AF_UNIX) { diff --git a/src/backend/libpq/pqpacket.c b/src/backend/libpq/pqpacket.c index 97caae952ac..631af78ce29 100644 --- a/src/backend/libpq/pqpacket.c +++ b/src/backend/libpq/pqpacket.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.15 1998/02/26 04:31:56 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.16 1998/07/09 03:28:46 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -33,7 +33,7 @@ * Set up a packet read for the postmaster event loop. */ -void PacketReceiveSetup(Packet *pkt, void (*iodone) (), char *arg) +void PacketReceiveSetup(Packet *pkt, PacketDoneProc iodone, void *arg) { pkt->nrtodo = sizeof(pkt->len); pkt->ptr = (char *) &pkt->len; @@ -94,8 +94,8 @@ PacketReceiveFragment(Packet *pkt, int sock) if (pkt->iodone == NULL) return STATUS_ERROR; - (*pkt->iodone) (pkt->arg, pkt->len - sizeof(pkt->len), - (char *) &pkt->pkt); + return (*pkt->iodone) (pkt->arg, pkt->len - sizeof(pkt->len), + (void *) &pkt->pkt); } return STATUS_OK; @@ -107,7 +107,7 @@ PacketReceiveFragment(Packet *pkt, int sock) if (errno == EINTR) return STATUS_OK; - fprintf(stderr, "read() system call failed\n"); + perror("PacketReceiveFragment: read() failed"); return STATUS_ERROR; } @@ -117,8 +117,9 @@ PacketReceiveFragment(Packet *pkt, int sock) * Set up a packet write for the postmaster event loop. */ -void PacketSendSetup(Packet *pkt, int nbytes, void (*iodone) (), char *arg) +void PacketSendSetup(Packet *pkt, int nbytes, PacketDoneProc iodone, void *arg) { + pkt->len = (PacketLen) nbytes; pkt->nrtodo = nbytes; pkt->ptr = (char *) &pkt->pkt; pkt->iodone = iodone; @@ -153,7 +154,8 @@ PacketSendFragment(Packet *pkt, int sock) if (pkt->iodone == NULL) return STATUS_ERROR; - (*pkt->iodone) (pkt->arg); + return (*pkt->iodone) (pkt->arg, pkt->len, + (void *) &pkt->pkt); } return STATUS_OK; @@ -165,7 +167,7 @@ PacketSendFragment(Packet *pkt, int sock) if (errno == EINTR) return STATUS_OK; - fprintf(stderr, "write() system call failed\n"); + perror("PacketSendFragment: write() failed"); return STATUS_ERROR; } |
