Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
c17fa36d
Commit
c17fa36d
authored
Nov 07, 1997
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Unix domain socket support, from Goran Thyni, goran@bildbasen.se
parent
d3cf6f98
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
187 additions
and
136 deletions
+187
-136
src/backend/libpq/hba.c
src/backend/libpq/hba.c
+8
-5
src/backend/libpq/password.c
src/backend/libpq/password.c
+1
-1
src/backend/libpq/pqcomm.c
src/backend/libpq/pqcomm.c
+70
-41
src/backend/libpq/pqpacket.c
src/backend/libpq/pqpacket.c
+7
-14
src/backend/postmaster/postmaster.c
src/backend/postmaster/postmaster.c
+56
-25
src/backend/tcop/postgres.c
src/backend/tcop/postgres.c
+6
-12
src/backend/utils/init/postinit.c
src/backend/utils/init/postinit.c
+1
-4
src/include/libpq/pqcomm.h
src/include/libpq/pqcomm.h
+10
-4
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/fe-connect.c
+28
-30
No files found.
src/backend/libpq/hba.c
View file @
c17fa36d
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.2
2 1997/09/08 21:43:45
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.2
3 1997/11/07 20:51:27
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -855,8 +855,8 @@ authident(const char DataDir[],
...
@@ -855,8 +855,8 @@ authident(const char DataDir[],
/* The username returned by ident */
/* The username returned by ident */
ident
(
port
.
raddr
.
sin_addr
,
port
.
laddr
.
sin_addr
,
ident
(
port
.
raddr
.
in
.
sin_addr
,
port
.
laddr
.
in
.
sin_addr
,
port
.
raddr
.
sin_port
,
port
.
laddr
.
sin_port
,
port
.
raddr
.
in
.
sin_port
,
port
.
laddr
.
in
.
sin_port
,
&
ident_failed
,
ident_username
);
&
ident_failed
,
ident_username
);
if
(
ident_failed
)
if
(
ident_failed
)
...
@@ -906,10 +906,13 @@ hba_recvauth(const Port *port, const char database[], const char user[],
...
@@ -906,10 +906,13 @@ hba_recvauth(const Port *port, const char database[], const char user[],
*/
*/
int
retvalue
;
int
retvalue
;
/* UNIX socket always OK, for now */
if
(
port
->
raddr
.
in
.
sin_family
==
AF_UNIX
)
return
STATUS_OK
;
/* Our eventual return value */
/* Our eventual return value */
find_hba_entry
(
DataDir
,
port
->
raddr
.
sin_addr
,
database
,
find_hba_entry
(
DataDir
,
port
->
raddr
.
in
.
sin_addr
,
database
,
&
host_ok
,
&
userauth
,
usermap_name
,
&
host_ok
,
&
userauth
,
usermap_name
,
false
/* don't find password entries of type
false
/* don't find password entries of type
'password' */
);
'password' */
);
...
...
src/backend/libpq/password.c
View file @
c17fa36d
...
@@ -26,7 +26,7 @@ verify_password(char *user, char *password, Port *port,
...
@@ -26,7 +26,7 @@ verify_password(char *user, char *password, Port *port,
*
test_pw
;
*
test_pw
;
char
salt
[
3
];
char
salt
[
3
];
find_hba_entry
(
DataDir
,
port
->
raddr
.
sin_addr
,
database
,
find_hba_entry
(
DataDir
,
port
->
raddr
.
in
.
sin_addr
,
database
,
&
host_ok
,
&
userauth
,
pw_file_name
,
true
);
&
host_ok
,
&
userauth
,
pw_file_name
,
true
);
if
(
!
host_ok
)
if
(
!
host_ok
)
...
...
src/backend/libpq/pqcomm.c
View file @
c17fa36d
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.2
3 1997/09/18 20:20:39
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.2
4 1997/11/07 20:51:34
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -571,20 +571,27 @@ pq_async_notify()
...
@@ -571,20 +571,27 @@ pq_async_notify()
*
*
* RETURNS: STATUS_OK or STATUS_ERROR
* RETURNS: STATUS_OK or STATUS_ERROR
*/
*/
static
char
sock_path
[
100
]
=
""
;
static
void
do_unlink
()
{
if
(
sock_path
[
0
])
unlink
(
sock_path
);
}
int
int
StreamServerPort
(
char
*
hostName
,
short
portName
,
int
*
fdP
)
StreamServerPort
(
char
*
hostName
,
short
portName
,
int
*
fdP
)
{
{
struct
sockaddr_in
sin
;
struct
sockaddr_in
sin
;
int
fd
;
struct
sockaddr_un
sun
;
int
fd
,
err
,
family
;
int
one
=
1
;
int
one
=
1
;
family
=
hostName
!=
NULL
?
AF_INET
:
AF_UNIX
;
if
(
!
hostName
)
hostName
=
"localhost"
;
MemSet
((
char
*
)
&
sin
,
0
,
sizeof
sin
);
MemSet
((
char
*
)
&
sin
,
0
,
sizeof
sin
);
if
((
fd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
if
((
fd
=
socket
(
family
,
SOCK_STREAM
,
0
))
<
0
)
{
{
sprintf
(
PQerrormsg
,
sprintf
(
PQerrormsg
,
"FATAL: StreamServerPort: socket() failed: errno=%d
\n
"
,
"FATAL: StreamServerPort: socket() failed: errno=%d
\n
"
,
...
@@ -593,7 +600,7 @@ StreamServerPort(char *hostName, short portName, int *fdP)
...
@@ -593,7 +600,7 @@ StreamServerPort(char *hostName, short portName, int *fdP)
pqdebug
(
"%s"
,
PQerrormsg
);
pqdebug
(
"%s"
,
PQerrormsg
);
return
(
STATUS_ERROR
);
return
(
STATUS_ERROR
);
}
}
if
(
family
==
AF_UNIX
)
on_exitpg
(
do_unlink
,
(
caddr_t
)
0
);
if
((
setsockopt
(
fd
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
char
*
)
&
one
,
if
((
setsockopt
(
fd
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
char
*
)
&
one
,
sizeof
(
one
)))
==
-
1
)
sizeof
(
one
)))
==
-
1
)
{
{
...
@@ -604,11 +611,24 @@ StreamServerPort(char *hostName, short portName, int *fdP)
...
@@ -604,11 +611,24 @@ StreamServerPort(char *hostName, short portName, int *fdP)
pqdebug
(
"%s"
,
PQerrormsg
);
pqdebug
(
"%s"
,
PQerrormsg
);
return
(
STATUS_ERROR
);
return
(
STATUS_ERROR
);
}
}
if
(
family
==
AF_UNIX
)
sin
.
sin_family
=
AF_INET
;
{
size_t
len
;
bzero
(
&
sun
,
sizeof
(
sun
));
sun
.
sun_family
=
family
;
len
=
UNIXSOCK_PATH
(
sun
,
portName
);
strcpy
(
sock_path
,
sun
.
sun_path
);
err
=
bind
(
fd
,
(
struct
sockaddr
*
)
&
sun
,
len
);
}
else
{
bzero
(
&
sin
,
sizeof
(
sin
));
sin
.
sin_family
=
family
;
sin
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
);
sin
.
sin_port
=
htons
(
portName
);
sin
.
sin_port
=
htons
(
portName
);
err
=
bind
(
fd
,
(
struct
sockaddr
*
)
&
sin
,
sizeof
sin
);
if
(
bind
(
fd
,
(
struct
sockaddr
*
)
&
sin
,
sizeof
sin
)
<
0
)
}
if
(
err
<
0
)
{
{
sprintf
(
PQerrormsg
,
sprintf
(
PQerrormsg
,
"FATAL: StreamServerPort: bind() failed: errno=%d
\n
"
,
"FATAL: StreamServerPort: bind() failed: errno=%d
\n
"
,
...
@@ -645,10 +665,13 @@ StreamServerPort(char *hostName, short portName, int *fdP)
...
@@ -645,10 +665,13 @@ StreamServerPort(char *hostName, short portName, int *fdP)
int
int
StreamConnection
(
int
server_fd
,
Port
*
port
)
StreamConnection
(
int
server_fd
,
Port
*
port
)
{
{
int
addrlen
;
int
len
,
addrlen
;
int
family
=
port
->
raddr
.
in
.
sin_family
;
/* accept connection (and fill in the client (remote) address) */
/* accept connection (and fill in the client (remote) address) */
addrlen
=
sizeof
(
struct
sockaddr_in
);
len
=
family
==
AF_INET
?
sizeof
(
struct
sockaddr_in
)
:
sizeof
(
struct
sockaddr_un
);
addrlen
=
len
;
if
((
port
->
sock
=
accept
(
server_fd
,
if
((
port
->
sock
=
accept
(
server_fd
,
(
struct
sockaddr
*
)
&
port
->
raddr
,
(
struct
sockaddr
*
)
&
port
->
raddr
,
&
addrlen
))
<
0
)
&
addrlen
))
<
0
)
...
@@ -658,13 +681,14 @@ StreamConnection(int server_fd, Port *port)
...
@@ -658,13 +681,14 @@ StreamConnection(int server_fd, Port *port)
}
}
/* fill in the server (local) address */
/* fill in the server (local) address */
addrlen
=
sizeof
(
struct
sockaddr_in
)
;
addrlen
=
len
;
if
(
getsockname
(
port
->
sock
,
(
struct
sockaddr
*
)
&
port
->
laddr
,
if
(
getsockname
(
port
->
sock
,
(
struct
sockaddr
*
)
&
port
->
laddr
,
&
addrlen
)
<
0
)
&
addrlen
)
<
0
)
{
{
elog
(
WARN
,
"postmaster: StreamConnection: getsockname: %m"
);
elog
(
WARN
,
"postmaster: StreamConnection: getsockname: %m"
);
return
(
STATUS_ERROR
);
return
(
STATUS_ERROR
);
}
}
if
(
family
==
AF_INET
)
{
{
struct
protoent
*
pe
;
struct
protoent
*
pe
;
int
on
=
1
;
int
on
=
1
;
...
@@ -714,14 +738,14 @@ StreamClose(int sock)
...
@@ -714,14 +738,14 @@ StreamClose(int sock)
int
int
StreamOpen
(
char
*
hostName
,
short
portName
,
Port
*
port
)
StreamOpen
(
char
*
hostName
,
short
portName
,
Port
*
port
)
{
{
int
len
,
err
;
struct
hostent
*
hp
;
struct
hostent
*
hp
;
int
laddrlen
=
sizeof
(
struct
sockaddr_in
);
extern
int
errno
;
extern
int
errno
;
if
(
!
hostName
)
hostName
=
"localhost"
;
/* set up the server (remote) address */
/* set up the server (remote) address */
MemSet
((
char
*
)
&
port
->
raddr
,
0
,
sizeof
(
port
->
raddr
));
if
(
hostName
)
{
if
(
!
(
hp
=
gethostbyname
(
hostName
))
||
hp
->
h_addrtype
!=
AF_INET
)
if
(
!
(
hp
=
gethostbyname
(
hostName
))
||
hp
->
h_addrtype
!=
AF_INET
)
{
{
sprintf
(
PQerrormsg
,
sprintf
(
PQerrormsg
,
...
@@ -731,15 +755,20 @@ StreamOpen(char *hostName, short portName, Port *port)
...
@@ -731,15 +755,20 @@ StreamOpen(char *hostName, short portName, Port *port)
pqdebug
(
"%s"
,
PQerrormsg
);
pqdebug
(
"%s"
,
PQerrormsg
);
return
(
STATUS_ERROR
);
return
(
STATUS_ERROR
);
}
}
MemSet
((
char
*
)
&
port
->
raddr
,
0
,
sizeof
(
port
->
raddr
));
memmove
((
char
*
)
&
(
port
->
raddr
.
in
.
sin_addr
),
memmove
((
char
*
)
&
(
port
->
raddr
.
sin_addr
),
(
char
*
)
hp
->
h_addr
,
(
char
*
)
hp
->
h_addr
,
hp
->
h_length
);
hp
->
h_length
);
port
->
raddr
.
sin_family
=
AF_INET
;
port
->
raddr
.
in
.
sin_family
=
AF_INET
;
port
->
raddr
.
sin_port
=
htons
(
portName
);
port
->
raddr
.
in
.
sin_port
=
htons
(
portName
);
len
=
sizeof
(
struct
sockaddr_in
);
}
else
{
port
->
raddr
.
un
.
sun_family
=
AF_UNIX
;
len
=
UNIXSOCK_PATH
(
port
->
raddr
.
un
,
portName
);
}
/* connect to the server */
/* connect to the server */
if
((
port
->
sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
if
((
port
->
sock
=
socket
(
port
->
raddr
.
in
.
sin_family
,
SOCK_STREAM
,
0
))
<
0
)
{
{
sprintf
(
PQerrormsg
,
sprintf
(
PQerrormsg
,
"FATAL: StreamOpen: socket() failed: errno=%d
\n
"
,
"FATAL: StreamOpen: socket() failed: errno=%d
\n
"
,
...
@@ -748,8 +777,8 @@ StreamOpen(char *hostName, short portName, Port *port)
...
@@ -748,8 +777,8 @@ StreamOpen(char *hostName, short portName, Port *port)
pqdebug
(
"%s"
,
PQerrormsg
);
pqdebug
(
"%s"
,
PQerrormsg
);
return
(
STATUS_ERROR
);
return
(
STATUS_ERROR
);
}
}
if
(
connect
(
port
->
sock
,
(
struct
sockaddr
*
)
&
port
->
raddr
,
err
=
connect
(
port
->
sock
,
(
struct
sockaddr
*
)
&
port
->
raddr
,
len
);
sizeof
(
port
->
raddr
))
<
0
)
if
(
err
<
0
)
{
{
sprintf
(
PQerrormsg
,
sprintf
(
PQerrormsg
,
"FATAL: StreamOpen: connect() failed: errno=%d
\n
"
,
"FATAL: StreamOpen: connect() failed: errno=%d
\n
"
,
...
@@ -761,7 +790,7 @@ StreamOpen(char *hostName, short portName, Port *port)
...
@@ -761,7 +790,7 @@ StreamOpen(char *hostName, short portName, Port *port)
/* fill in the client address */
/* fill in the client address */
if
(
getsockname
(
port
->
sock
,
(
struct
sockaddr
*
)
&
port
->
laddr
,
if
(
getsockname
(
port
->
sock
,
(
struct
sockaddr
*
)
&
port
->
laddr
,
&
laddr
len
)
<
0
)
&
len
)
<
0
)
{
{
sprintf
(
PQerrormsg
,
sprintf
(
PQerrormsg
,
"FATAL: StreamOpen: getsockname() failed: errno=%d
\n
"
,
"FATAL: StreamOpen: getsockname() failed: errno=%d
\n
"
,
...
...
src/backend/libpq/pqpacket.c
View file @
c17fa36d
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.
8 1997/09/08 21:43:52
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.
9 1997/11/07 20:51:36
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -85,7 +85,7 @@ PacketReceive(Port *port, /* receive port */
...
@@ -85,7 +85,7 @@ PacketReceive(Port *port, /* receive port */
/*
/*
* Assume port->nBytes is zero unless we were interrupted during
* Assume port->nBytes is zero unless we were interrupted during
* non-blocking I/O. This first recv
from
() is to get the hdr
* non-blocking I/O. This first recv() is to get the hdr
* information so we know how many bytes to read. Life would be very
* information so we know how many bytes to read. Life would be very
* complicated if we read too much data (buffering).
* complicated if we read too much data (buffering).
*/
*/
...
@@ -98,8 +98,7 @@ PacketReceive(Port *port, /* receive port */
...
@@ -98,8 +98,7 @@ PacketReceive(Port *port, /* receive port */
else
else
{
{
/* peeking into the incoming message */
/* peeking into the incoming message */
cc
=
recvfrom
(
port
->
sock
,
(
char
*
)
&
(
buf
->
len
),
hdrLen
,
flag
,
cc
=
recv
(
port
->
sock
,
(
char
*
)
&
(
buf
->
len
),
hdrLen
,
flag
);
(
struct
sockaddr
*
)
&
(
port
->
raddr
),
&
addrLen
);
if
(
cc
<
hdrLen
)
if
(
cc
<
hdrLen
)
{
{
/* if cc is negative, the system call failed */
/* if cc is negative, the system call failed */
...
@@ -179,8 +178,7 @@ PacketReceive(Port *port, /* receive port */
...
@@ -179,8 +178,7 @@ PacketReceive(Port *port, /* receive port */
*/
*/
while
(
packetLen
)
while
(
packetLen
)
{
{
cc
=
recvfrom
(
port
->
sock
,
tmp
,
packetLen
,
0
,
cc
=
read
(
port
->
sock
,
tmp
,
packetLen
);
(
struct
sockaddr
*
)
&
(
port
->
raddr
),
&
addrLen
);
if
(
cc
<
0
)
if
(
cc
<
0
)
return
(
STATUS_ERROR
);
return
(
STATUS_ERROR
);
...
@@ -224,18 +222,13 @@ PacketSend(Port *port,
...
@@ -224,18 +222,13 @@ PacketSend(Port *port,
PacketLen
len
,
PacketLen
len
,
bool
nonBlocking
)
bool
nonBlocking
)
{
{
PacketLen
totalLen
;
PacketLen
doneLen
;
int
addrLen
=
sizeof
(
struct
sockaddr_in
);
Assert
(
!
nonBlocking
);
Assert
(
!
nonBlocking
);
Assert
(
buf
);
Assert
(
buf
);
totalLen
=
len
;
doneLen
=
write
(
port
->
sock
,
buf
,
len
);
if
(
doneLen
<
len
)
len
=
sendto
(
port
->
sock
,
(
Addr
)
buf
,
totalLen
,
/* flags */
0
,
(
struct
sockaddr
*
)
&
(
port
->
raddr
),
addrLen
);
if
(
len
<
totalLen
)
{
{
sprintf
(
PQerrormsg
,
sprintf
(
PQerrormsg
,
"FATAL: PacketSend: couldn't send complete packet: errno=%d
\n
"
,
"FATAL: PacketSend: couldn't send complete packet: errno=%d
\n
"
,
...
...
src/backend/postmaster/postmaster.c
View file @
c17fa36d
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.
59 1997/10/25 01:09:55
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.
60 1997/11/07 20:51:47
momjian Exp $
*
*
* NOTES
* NOTES
*
*
...
@@ -131,7 +131,8 @@ static char *progname = (char *) NULL;
...
@@ -131,7 +131,8 @@ static char *progname = (char *) NULL;
*/
*/
static
char
Execfile
[
MAXPATHLEN
]
=
""
;
static
char
Execfile
[
MAXPATHLEN
]
=
""
;
static
int
ServerSock
=
INVALID_SOCK
;
/* stream socket server */
static
int
ServerSock_INET
=
INVALID_SOCK
;
/* stream socket server */
static
int
ServerSock_UNIX
=
INVALID_SOCK
;
/* stream socket server */
/*
/*
* Set by the -o option
* Set by the -o option
...
@@ -148,6 +149,8 @@ static char ExtraOptions[ARGV_SIZE] = "";
...
@@ -148,6 +149,8 @@ static char ExtraOptions[ARGV_SIZE] = "";
static
int
Reinit
=
1
;
static
int
Reinit
=
1
;
static
int
SendStop
=
0
;
static
int
SendStop
=
0
;
static
int
NetServer
=
0
;
/* if not zero, postmaster listen for
non-local connections */
static
int
MultiplexedBackends
=
0
;
static
int
MultiplexedBackends
=
0
;
static
int
MultiplexedBackendPort
;
static
int
MultiplexedBackendPort
;
...
@@ -244,8 +247,8 @@ PostmasterMain(int argc, char *argv[])
...
@@ -244,8 +247,8 @@ PostmasterMain(int argc, char *argv[])
char
*
hostName
;
char
*
hostName
;
int
status
;
int
status
;
int
silentflag
=
0
;
int
silentflag
=
0
;
char
hostbuf
[
MAXHOSTNAMELEN
];
bool
DataDirOK
;
/* We have a usable PGDATA value */
bool
DataDirOK
;
/* We have a usable PGDATA value */
char
hostbuf
[
MAXHOSTNAMELEN
];
progname
=
argv
[
0
];
progname
=
argv
[
0
];
...
@@ -267,7 +270,7 @@ PostmasterMain(int argc, char *argv[])
...
@@ -267,7 +270,7 @@ PostmasterMain(int argc, char *argv[])
DataDir
=
getenv
(
"PGDATA"
);
/* default value */
DataDir
=
getenv
(
"PGDATA"
);
/* default value */
opterr
=
0
;
opterr
=
0
;
while
((
opt
=
getopt
(
argc
,
argv
,
"a:B:b:D:dm:Mno:p:Ss"
))
!=
EOF
)
while
((
opt
=
getopt
(
argc
,
argv
,
"a:B:b:D:d
i
m:Mno:p:Ss"
))
!=
EOF
)
{
{
switch
(
opt
)
switch
(
opt
)
{
{
...
@@ -315,6 +318,9 @@ PostmasterMain(int argc, char *argv[])
...
@@ -315,6 +318,9 @@ PostmasterMain(int argc, char *argv[])
else
else
DebugLvl
=
1
;
DebugLvl
=
1
;
break
;
break
;
case
'i'
:
NetServer
=
1
;
break
;
case
'm'
:
case
'm'
:
MultiplexedBackends
=
1
;
MultiplexedBackends
=
1
;
MultiplexedBackendPort
=
atoi
(
optarg
);
MultiplexedBackendPort
=
atoi
(
optarg
);
...
@@ -387,11 +393,20 @@ PostmasterMain(int argc, char *argv[])
...
@@ -387,11 +393,20 @@ PostmasterMain(int argc, char *argv[])
exit
(
1
);
exit
(
1
);
}
}
if
(
NetServer
)
status
=
StreamServerPort
(
hostName
,
PostPortName
,
&
ServerSock
);
{
status
=
StreamServerPort
(
hostName
,
PostPortName
,
&
ServerSock_INET
);
if
(
status
!=
STATUS_OK
)
{
fprintf
(
stderr
,
"%s: cannot create INET stream port
\n
"
,
progname
);
exit
(
1
);
}
}
status
=
StreamServerPort
(
NULL
,
PostPortName
,
&
ServerSock_UNIX
);
if
(
status
!=
STATUS_OK
)
if
(
status
!=
STATUS_OK
)
{
{
fprintf
(
stderr
,
"%s: cannot create stream port
\n
"
,
fprintf
(
stderr
,
"%s: cannot create
UNIX
stream port
\n
"
,
progname
);
progname
);
exit
(
1
);
exit
(
1
);
}
}
...
@@ -459,6 +474,7 @@ usage(const char *progname)
...
@@ -459,6 +474,7 @@ usage(const char *progname)
fprintf
(
stderr
,
"
\t
-b backend
\t
use a specific backend server executable
\n
"
);
fprintf
(
stderr
,
"
\t
-b backend
\t
use a specific backend server executable
\n
"
);
fprintf
(
stderr
,
"
\t
-d [1|2|3]
\t
set debugging level
\n
"
);
fprintf
(
stderr
,
"
\t
-d [1|2|3]
\t
set debugging level
\n
"
);
fprintf
(
stderr
,
"
\t
-D datadir
\t
set data directory
\n
"
);
fprintf
(
stderr
,
"
\t
-D datadir
\t
set data directory
\n
"
);
fprintf
(
stderr
,
"
\t
-i
\t
listen on TCP/IP sockets as well as Unix domain socket
\n
"
);
fprintf
(
stderr
,
"
\t
-m
\t
start up multiplexing backends
\n
"
);
fprintf
(
stderr
,
"
\t
-m
\t
start up multiplexing backends
\n
"
);
fprintf
(
stderr
,
"
\t
-n
\t\t
don't reinitialize shared memory after abnormal exit
\n
"
);
fprintf
(
stderr
,
"
\t
-n
\t\t
don't reinitialize shared memory after abnormal exit
\n
"
);
fprintf
(
stderr
,
"
\t
-o option
\t
pass 'option' to each backend servers
\n
"
);
fprintf
(
stderr
,
"
\t
-o option
\t
pass 'option' to each backend servers
\n
"
);
...
@@ -471,13 +487,11 @@ usage(const char *progname)
...
@@ -471,13 +487,11 @@ usage(const char *progname)
static
int
static
int
ServerLoop
(
void
)
ServerLoop
(
void
)
{
{
int
serverFd
=
ServerSock
;
fd_set
rmask
,
basemask
;
fd_set
rmask
,
basemask
;
int
nSockets
,
int
nSockets
,
nSelected
,
nSelected
,
status
,
status
,
newFd
;
oldFd
,
newFd
;
Dlelem
*
next
,
Dlelem
*
next
,
*
curr
;
*
curr
;
...
@@ -493,10 +507,16 @@ ServerLoop(void)
...
@@ -493,10 +507,16 @@ ServerLoop(void)
int
orgsigmask
=
sigblock
(
0
);
int
orgsigmask
=
sigblock
(
0
);
#endif
#endif
nSockets
=
ServerSock
+
1
;
FD_ZERO
(
&
basemask
);
FD_ZERO
(
&
basemask
);
FD_SET
(
ServerSock
,
&
basemask
);
FD_SET
(
ServerSock_UNIX
,
&
basemask
);
nSockets
=
ServerSock_UNIX
;
if
(
ServerSock_INET
!=
INVALID_SOCK
)
{
FD_SET
(
ServerSock_INET
,
&
basemask
);
if
(
ServerSock_INET
>
ServerSock_UNIX
)
nSockets
=
ServerSock_INET
;
}
nSockets
++
;
#ifdef HAVE_SIGPROCMASK
#ifdef HAVE_SIGPROCMASK
sigprocmask
(
0
,
0
,
&
oldsigmask
);
sigprocmask
(
0
,
0
,
&
oldsigmask
);
...
@@ -542,7 +562,13 @@ ServerLoop(void)
...
@@ -542,7 +562,13 @@ ServerLoop(void)
}
}
/* new connection pending on our well-known port's socket */
/* new connection pending on our well-known port's socket */
if
(
FD_ISSET
(
ServerSock
,
&
rmask
))
oldFd
=
-
1
;
if
(
FD_ISSET
(
ServerSock_UNIX
,
&
rmask
))
oldFd
=
ServerSock_UNIX
;
else
if
(
ServerSock_INET
!=
INVALID_SOCK
&&
FD_ISSET
(
ServerSock_INET
,
&
rmask
))
oldFd
=
ServerSock_INET
;
if
(
oldFd
>=
0
)
{
{
/*
/*
...
@@ -550,7 +576,7 @@ ServerLoop(void)
...
@@ -550,7 +576,7 @@ ServerLoop(void)
* connection dies and we notice it, just forget about the
* connection dies and we notice it, just forget about the
* whole thing.
* whole thing.
*/
*/
if
(
ConnCreate
(
server
Fd
,
&
newFd
)
==
STATUS_OK
)
if
(
ConnCreate
(
old
Fd
,
&
newFd
)
==
STATUS_OK
)
{
{
if
(
newFd
>=
nSockets
)
if
(
newFd
>=
nSockets
)
nSockets
=
newFd
+
1
;
nSockets
=
newFd
+
1
;
...
@@ -560,8 +586,12 @@ ServerLoop(void)
...
@@ -560,8 +586,12 @@ ServerLoop(void)
fprintf
(
stderr
,
"%s: ServerLoop: connect on %d
\n
"
,
fprintf
(
stderr
,
"%s: ServerLoop: connect on %d
\n
"
,
progname
,
newFd
);
progname
,
newFd
);
}
}
else
if
(
DebugLvl
)
fprintf
(
stderr
,
"%s: ServerLoop: connect failed: (%d) %s
\n
"
,
progname
,
errno
,
strerror
(
errno
));
--
nSelected
;
--
nSelected
;
FD_CLR
(
ServerSock
,
&
rmask
);
FD_CLR
(
oldFd
,
&
rmask
);
}
}
if
(
DebugLvl
>
1
)
if
(
DebugLvl
>
1
)
...
@@ -793,7 +823,7 @@ ConnStartup(Port *port, int *status,
...
@@ -793,7 +823,7 @@ ConnStartup(Port *port, int *status,
static
void
static
void
send_error_reply
(
Port
*
port
,
const
char
*
errormsg
)
send_error_reply
(
Port
*
port
,
const
char
*
errormsg
)
{
{
int
rc
;
/* return code from sendto
*/
int
rc
;
/* return code from write
*/
char
*
reply
;
char
*
reply
;
/*
/*
...
@@ -812,7 +842,7 @@ send_error_reply(Port *port, const char *errormsg)
...
@@ -812,7 +842,7 @@ send_error_reply(Port *port, const char *errormsg)
sprintf
(
reply
,
"E%s"
,
errormsg
);
sprintf
(
reply
,
"E%s"
,
errormsg
);
rc
=
send
(
port
->
sock
,
(
Addr
)
reply
,
strlen
(
reply
)
+
1
,
/* flags */
0
);
rc
=
write
(
port
->
sock
,
(
Addr
)
reply
,
strlen
(
reply
)
+
1
);
if
(
rc
<
0
)
if
(
rc
<
0
)
fprintf
(
stderr
,
fprintf
(
stderr
,
"%s: ServerLoop:
\t\t
"
"%s: ServerLoop:
\t\t
"
...
@@ -1269,8 +1299,8 @@ ExitPostmaster(int status)
...
@@ -1269,8 +1299,8 @@ ExitPostmaster(int status)
* Not sure of the semantics here. When the Postmaster dies, should
* Not sure of the semantics here. When the Postmaster dies, should
* the backends all be killed? probably not.
* the backends all be killed? probably not.
*/
*/
if
(
ServerSock
!=
INVALID_SOCK
)
if
(
ServerSock
_INET
!=
INVALID_SOCK
)
close
(
ServerSock_INET
);
close
(
ServerSock
);
if
(
ServerSock_UNIX
!=
INVALID_SOCK
)
close
(
ServerSock_UNIX
);
exitpg
(
status
);
exitpg
(
status
);
}
}
...
@@ -1286,8 +1316,9 @@ dumpstatus(SIGNAL_ARGS)
...
@@ -1286,8 +1316,9 @@ dumpstatus(SIGNAL_ARGS)
fprintf
(
stderr
,
"%s: dumpstatus:
\n
"
,
progname
);
fprintf
(
stderr
,
"%s: dumpstatus:
\n
"
,
progname
);
fprintf
(
stderr
,
"
\t
sock %d: nBytes=%d, laddr=0x%lx, raddr=0x%lx
\n
"
,
fprintf
(
stderr
,
"
\t
sock %d: nBytes=%d, laddr=0x%lx, raddr=0x%lx
\n
"
,
port
->
sock
,
port
->
nBytes
,
port
->
sock
,
port
->
nBytes
,
(
long
int
)
port
->
laddr
.
sin_addr
.
s_addr
,
(
long
int
)
port
->
laddr
.
in
.
sin_addr
.
s_addr
,
(
long
int
)
port
->
raddr
.
sin_addr
.
s_addr
);
(
long
int
)
port
->
raddr
.
in
.
sin_addr
.
s_addr
);
curr
=
DLGetSucc
(
curr
);
curr
=
DLGetSucc
(
curr
);
}
}
}
}
src/backend/tcop/postgres.c
View file @
c17fa36d
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.5
1 1997/11/02 15:25:45 vadim
Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.5
2 1997/11/07 20:51:54 momjian
Exp $
*
*
* NOTES
* NOTES
* this is the "main" module of the postgres backend and
* this is the "main" module of the postgres backend and
...
@@ -832,7 +832,6 @@ PostgresMain(int argc, char *argv[])
...
@@ -832,7 +832,6 @@ PostgresMain(int argc, char *argv[])
bool
multiplexedBackend
;
bool
multiplexedBackend
;
char
*
hostName
;
/* the host name of the backend server */
char
*
hostName
;
/* the host name of the backend server */
char
hostbuf
[
MAXHOSTNAMELEN
];
int
serverSock
;
int
serverSock
;
int
serverPortnum
=
0
;
int
serverPortnum
=
0
;
int
nSelected
;
/* number of descriptors ready from
int
nSelected
;
/* number of descriptors ready from
...
@@ -884,15 +883,10 @@ PostgresMain(int argc, char *argv[])
...
@@ -884,15 +883,10 @@ PostgresMain(int argc, char *argv[])
#endif
#endif
/*
/*
* get hostname is either the environment variable PGHOST or
* get hostname is either the environment variable PGHOST or
NULL
*
'localhost'
*
NULL means Unix-socket only
*/
*/
if
(
!
(
hostName
=
getenv
(
"PGHOST"
)))
hostName
=
getenv
(
"PGHOST"
);
{
if
(
gethostname
(
hostbuf
,
MAXHOSTNAMELEN
)
<
0
)
strcpy
(
hostbuf
,
"localhost"
);
hostName
=
hostbuf
;
}
DataDir
=
getenv
(
"PGDATA"
);
/* default */
DataDir
=
getenv
(
"PGDATA"
);
/* default */
multiplexedBackend
=
false
;
/* default */
multiplexedBackend
=
false
;
/* default */
...
@@ -1343,7 +1337,7 @@ PostgresMain(int argc, char *argv[])
...
@@ -1343,7 +1337,7 @@ PostgresMain(int argc, char *argv[])
if
(
IsUnderPostmaster
==
false
)
if
(
IsUnderPostmaster
==
false
)
{
{
puts
(
"
\n
POSTGRES backend interactive interface"
);
puts
(
"
\n
POSTGRES backend interactive interface"
);
puts
(
"$Revision: 1.5
1 $ $Date: 1997/11/02 15:25:45
$"
);
puts
(
"$Revision: 1.5
2 $ $Date: 1997/11/07 20:51:54
$"
);
}
}
/* ----------------
/* ----------------
...
...
src/backend/utils/init/postinit.c
View file @
c17fa36d
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.1
5 1997/11/07 06:38:46 thomas
Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.1
6 1997/11/07 20:51:58 momjian
Exp $
*
*
* NOTES
* NOTES
* InitPostgres() is the function called from PostgresMain
* InitPostgres() is the function called from PostgresMain
...
@@ -310,9 +310,6 @@ InitCommunication()
...
@@ -310,9 +310,6 @@ InitCommunication()
{
{
SystemPortAddress
address
=
atoi
(
postport
);
SystemPortAddress
address
=
atoi
(
postport
);
if
(
address
==
0
)
elog
(
FATAL
,
"InitCommunication: invalid POSTPORT"
);
if
(
MyBackendTag
==
-
1
)
if
(
MyBackendTag
==
-
1
)
elog
(
FATAL
,
"InitCommunication: missing POSTID"
);
elog
(
FATAL
,
"InitCommunication: missing POSTID"
);
...
...
src/include/libpq/pqcomm.h
View file @
c17fa36d
...
@@ -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: pqcomm.h,v 1.1
5 1997/09/12 22:26:13
momjian Exp $
* $Id: pqcomm.h,v 1.1
6 1997/11/07 20:52:06
momjian Exp $
*
*
* NOTES
* NOTES
* Some of this should move to libpq.h
* Some of this should move to libpq.h
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include <stdio.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <sys/un.h>
/*
/*
...
@@ -27,6 +28,10 @@
...
@@ -27,6 +28,10 @@
#define PATH_SIZE 64
#define PATH_SIZE 64
#define ARGV_SIZE 64
#define ARGV_SIZE 64
#define UNIXSOCK_PATH(sun,port) \
sprintf(sun.sun_path,"/tmp/.s.PGSQL.%d",port) + sizeof(sun.sun_family) + 1;
/* The various kinds of startup messages are for the various kinds of
/* The various kinds of startup messages are for the various kinds of
user authentication systems. In the beginning, there was only
user authentication systems. In the beginning, there was only
STARTUP_MSG and all connections were unauthenticated. Now, there are
STARTUP_MSG and all connections were unauthenticated. Now, there are
...
@@ -106,9 +111,10 @@ typedef struct Port
...
@@ -106,9 +111,10 @@ typedef struct Port
int
sock
;
/* file descriptor */
int
sock
;
/* file descriptor */
int
mask
;
/* select mask */
int
mask
;
/* select mask */
int
nBytes
;
/* nBytes read in so far */
int
nBytes
;
/* nBytes read in so far */
struct
sockaddr_in
laddr
;
/* local addr (us) */
/* local addr (us) */
struct
sockaddr_in
raddr
;
/* remote addr (them) */
union
{
struct
sockaddr_in
in
;
struct
sockaddr_un
un
;
}
laddr
;
/* remote addr (them) */
union
{
struct
sockaddr_in
in
;
struct
sockaddr_un
un
;
}
raddr
;
/*
/*
* PacketBufId id;
* PacketBufId id;
*//* id of packet buf currently in use */
*//* id of packet buf currently in use */
...
...
src/interfaces/libpq/fe-connect.c
View file @
c17fa36d
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.4
2 1997/09/18 20:22:46
momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.4
3 1997/11/07 20:52:15
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -86,7 +86,7 @@ static PQconninfoOption PQconninfoOptions[] = {
...
@@ -86,7 +86,7 @@ static PQconninfoOption PQconninfoOptions[] = {
{
"dbname"
,
"PGDATABASE"
,
NULL
,
NULL
,
{
"dbname"
,
"PGDATABASE"
,
NULL
,
NULL
,
"Database-Name"
,
""
,
20
},
"Database-Name"
,
""
,
20
},
{
"host"
,
"PGHOST"
,
DefaultHost
,
NULL
,
{
"host"
,
"PGHOST"
,
NULL
,
NULL
,
"Database-Host"
,
""
,
40
},
"Database-Host"
,
""
,
40
},
{
"port"
,
"PGPORT"
,
DEF_PGPORT
,
NULL
,
{
"port"
,
"PGPORT"
,
DEF_PGPORT
,
NULL
,
...
@@ -340,11 +340,8 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha
...
@@ -340,11 +340,8 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha
if
(
!
pghost
||
pghost
[
0
]
==
'\0'
)
if
(
!
pghost
||
pghost
[
0
]
==
'\0'
)
{
{
if
(
!
(
tmp
=
getenv
(
"PGHOST"
)))
conn
->
pghost
=
NULL
;
{
if
(
tmp
=
getenv
(
"PGHOST"
))
conn
->
pghost
=
strdup
(
tmp
);
tmp
=
DefaultHost
;
}
conn
->
pghost
=
strdup
(
tmp
);
}
}
else
else
conn
->
pghost
=
strdup
(
pghost
);
conn
->
pghost
=
strdup
(
pghost
);
...
@@ -473,7 +470,7 @@ connectDB(PGconn *conn)
...
@@ -473,7 +470,7 @@ connectDB(PGconn *conn)
MsgType
msgtype
;
MsgType
msgtype
;
int
laddrlen
=
sizeof
(
struct
sockaddr
);
int
laddrlen
=
sizeof
(
struct
sockaddr
);
Port
*
port
=
conn
->
port
;
Port
*
port
=
conn
->
port
;
int
portno
;
int
portno
,
family
,
len
;
/*
/*
* Initialize the startup packet.
* Initialize the startup packet.
...
@@ -501,7 +498,8 @@ connectDB(PGconn *conn)
...
@@ -501,7 +498,8 @@ connectDB(PGconn *conn)
port
=
(
Port
*
)
malloc
(
sizeof
(
Port
));
port
=
(
Port
*
)
malloc
(
sizeof
(
Port
));
MemSet
((
char
*
)
port
,
0
,
sizeof
(
Port
));
MemSet
((
char
*
)
port
,
0
,
sizeof
(
Port
));
if
(
!
(
hp
=
gethostbyname
(
conn
->
pghost
))
||
hp
->
h_addrtype
!=
AF_INET
)
if
(
conn
->
pghost
&&
(
!
(
hp
=
gethostbyname
(
conn
->
pghost
))
||
hp
->
h_addrtype
!=
AF_INET
))
{
{
(
void
)
sprintf
(
conn
->
errorMessage
,
(
void
)
sprintf
(
conn
->
errorMessage
,
"connectDB() -- unknown hostname: %s
\n
"
,
"connectDB() -- unknown hostname: %s
\n
"
,
...
@@ -509,29 +507,37 @@ connectDB(PGconn *conn)
...
@@ -509,29 +507,37 @@ connectDB(PGconn *conn)
goto
connect_errReturn
;
goto
connect_errReturn
;
}
}
MemSet
((
char
*
)
&
port
->
raddr
,
0
,
sizeof
(
port
->
raddr
));
MemSet
((
char
*
)
&
port
->
raddr
,
0
,
sizeof
(
port
->
raddr
));
memmove
((
char
*
)
&
(
port
->
raddr
.
sin_addr
),
portno
=
atoi
(
conn
->
pgport
);
port
->
raddr
.
in
.
sin_family
=
family
=
conn
->
pghost
?
AF_INET
:
AF_UNIX
;
if
(
family
==
AF_INET
)
{
memmove
((
char
*
)
&
(
port
->
raddr
.
in
.
sin_addr
),
(
char
*
)
hp
->
h_addr
,
(
char
*
)
hp
->
h_addr
,
hp
->
h_length
);
hp
->
h_length
);
port
->
raddr
.
sin_family
=
AF_INET
;
port
->
raddr
.
in
.
sin_port
=
htons
((
unsigned
short
)
(
portno
));
portno
=
atoi
(
conn
->
pgport
);
len
=
sizeof
(
struct
sockaddr_in
);
port
->
raddr
.
sin_port
=
htons
((
unsigned
short
)
(
portno
));
}
else
{
len
=
UNIXSOCK_PATH
(
port
->
raddr
.
un
,
portno
);
}
/* connect to the server */
/* connect to the server */
if
((
port
->
sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
if
((
port
->
sock
=
socket
(
family
,
SOCK_STREAM
,
0
))
<
0
)
{
{
(
void
)
sprintf
(
conn
->
errorMessage
,
(
void
)
sprintf
(
conn
->
errorMessage
,
"connectDB() -- socket() failed: errno=%d
\n
%s
\n
"
,
"connectDB() -- socket() failed: errno=%d
\n
%s
\n
"
,
errno
,
strerror
(
errno
));
errno
,
strerror
(
errno
));
goto
connect_errReturn
;
goto
connect_errReturn
;
}
}
if
(
connect
(
port
->
sock
,
(
struct
sockaddr
*
)
&
port
->
raddr
,
if
(
connect
(
port
->
sock
,
(
struct
sockaddr
*
)
&
port
->
raddr
,
len
)
<
0
)
sizeof
(
port
->
raddr
))
<
0
)
{
{
(
void
)
sprintf
(
conn
->
errorMessage
,
(
void
)
sprintf
(
conn
->
errorMessage
,
"connectDB() failed: Is the postmaster running at '%s' on port '%s'?
\n
"
,
"connectDB() failed: Is the postmaster running at '%s' on port '%s'?
\n
"
,
conn
->
pghost
,
conn
->
pgport
);
conn
->
pghost
?
conn
->
pghost
:
"UNIX Socket"
,
conn
->
pgport
);
goto
connect_errReturn
;
goto
connect_errReturn
;
}
}
if
(
family
==
AF_INET
)
{
{
struct
protoent
*
pe
;
struct
protoent
*
pe
;
int
on
=
1
;
int
on
=
1
;
...
@@ -773,19 +779,11 @@ packetSend(Port *port,
...
@@ -773,19 +779,11 @@ packetSend(Port *port,
PacketLen
len
,
PacketLen
len
,
bool
nonBlocking
)
bool
nonBlocking
)
{
{
PacketLen
totalLen
;
PacketLen
doneLen
=
write
(
port
->
sock
,
buf
,
len
);
int
addrLen
=
sizeof
(
struct
sockaddr_in
);
if
(
doneLen
<
len
)
totalLen
=
len
;
len
=
sendto
(
port
->
sock
,
(
Addr
)
buf
,
totalLen
,
/* flags */
0
,
(
struct
sockaddr
*
)
&
(
port
->
raddr
),
addrLen
);
if
(
len
<
totalLen
)
{
{
return
(
STATUS_ERROR
);
return
(
STATUS_ERROR
);
}
}
return
(
STATUS_OK
);
return
(
STATUS_OK
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment