Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitec136d1

Browse files
committed
Move code shared between libpq and backend from backend/libpq/ to common/.
When building libpq, ip.c and md5.c were symlinked or copied fromsrc/backend/libpq into src/interfaces/libpq, but now that we have adirectory specifically for routines that are shared between the server andclient binaries, src/common/, move them there.Some routines in ip.c were only used in the backend. Keep those insrc/backend/libpq, but rename to ifaddr.c to avoid confusion with the filethat's now in common.Fix the comment in src/common/Makefile to reflect how libpq actually linksthose files.There are two more files that libpq symlinks directly from src/backend:encnames.c and wchar.c. I don't feel compelled to move those right now,though.Patch by Michael Paquier, with some changes by me.Discussion: <69938195-9c76-8523-0af8-eb718ea5b36e@iki.fi>
1 parent9cca11c commitec136d1

File tree

25 files changed

+337
-275
lines changed

25 files changed

+337
-275
lines changed

‎contrib/passwordcheck/passwordcheck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#endif
2222

2323
#include"commands/user.h"
24+
#include"common/md5.h"
2425
#include"fmgr.h"
25-
#include"libpq/md5.h"
2626

2727
PG_MODULE_MAGIC;
2828

‎src/backend/commands/user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include"commands/dbcommands.h"
3030
#include"commands/seclabel.h"
3131
#include"commands/user.h"
32-
#include"libpq/md5.h"
32+
#include"common/md5.h"
3333
#include"miscadmin.h"
3434
#include"storage/lmgr.h"
3535
#include"utils/acl.h"

‎src/backend/libpq/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ include $(top_builddir)/src/Makefile.global
1414

1515
# be-fsstubs is here for historical reasons, probably belongs elsewhere
1616

17-
OBJS = be-fsstubs.o be-secure.o auth.o crypt.o hba.oip.o md5.o pqcomm.o\
17+
OBJS = be-fsstubs.o be-secure.o auth.o crypt.o hba.oifaddr.o pqcomm.o\
1818
pqformat.o pqmq.o pqsignal.o
1919

2020
ifeq ($(with_openssl),yes)

‎src/backend/libpq/auth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
#include<arpa/inet.h>
2222
#include<unistd.h>
2323

24+
#include"common/ip.h"
25+
#include"common/md5.h"
2426
#include"libpq/auth.h"
2527
#include"libpq/crypt.h"
26-
#include"libpq/ip.h"
2728
#include"libpq/libpq.h"
2829
#include"libpq/pqformat.h"
29-
#include"libpq/md5.h"
3030
#include"miscadmin.h"
3131
#include"replication/walsender.h"
3232
#include"storage/ipc.h"

‎src/backend/libpq/crypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#endif
2222

2323
#include"catalog/pg_authid.h"
24+
#include"common/md5.h"
2425
#include"libpq/crypt.h"
25-
#include"libpq/md5.h"
2626
#include"miscadmin.h"
2727
#include"utils/builtins.h"
2828
#include"utils/syscache.h"

‎src/backend/libpq/hba.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
#include<unistd.h>
2727

2828
#include"catalog/pg_collation.h"
29-
#include"libpq/ip.h"
29+
#include"common/ip.h"
30+
#include"libpq/ifaddr.h"
3031
#include"libpq/libpq.h"
3132
#include"postmaster/postmaster.h"
3233
#include"regex/regex.h"

‎src/backend/libpq/ip.crenamed to‎src/backend/libpq/ifaddr.c

Lines changed: 5 additions & 227 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*-------------------------------------------------------------------------
22
*
3-
*ip.c
4-
*IPv6-awarenetworkaccess.
3+
*ifaddr.c
4+
*IP netmask calculations, and enumeratingnetworkinterfaces.
55
*
66
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
*
1010
* IDENTIFICATION
11-
* src/backend/libpq/ip.c
11+
* src/backend/libpq/ifaddr.c
1212
*
1313
* This file and the IPV6 implementation were initially provided by
1414
* Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
@@ -17,8 +17,7 @@
1717
*-------------------------------------------------------------------------
1818
*/
1919

20-
/* This is intended to be used in both frontend and backend, so use c.h */
21-
#include"c.h"
20+
#include"postgres.h"
2221

2322
#include<unistd.h>
2423
#include<sys/types.h>
@@ -32,8 +31,7 @@
3231
#include<arpa/inet.h>
3332
#include<sys/file.h>
3433

35-
#include"libpq/ip.h"
36-
34+
#include"libpq/ifaddr.h"
3735

3836
staticintrange_sockaddr_AF_INET(conststructsockaddr_in*addr,
3937
conststructsockaddr_in*netaddr,
@@ -45,226 +43,6 @@ static int range_sockaddr_AF_INET6(const struct sockaddr_in6 * addr,
4543
conststructsockaddr_in6*netmask);
4644
#endif
4745

48-
#ifdefHAVE_UNIX_SOCKETS
49-
staticintgetaddrinfo_unix(constchar*path,
50-
conststructaddrinfo*hintsp,
51-
structaddrinfo**result);
52-
53-
staticintgetnameinfo_unix(conststructsockaddr_un*sa,intsalen,
54-
char*node,intnodelen,
55-
char*service,intservicelen,
56-
intflags);
57-
#endif
58-
59-
60-
/*
61-
*pg_getaddrinfo_all - get address info for Unix, IPv4 and IPv6 sockets
62-
*/
63-
int
64-
pg_getaddrinfo_all(constchar*hostname,constchar*servname,
65-
conststructaddrinfo*hintp,structaddrinfo**result)
66-
{
67-
intrc;
68-
69-
/* not all versions of getaddrinfo() zero *result on failure */
70-
*result=NULL;
71-
72-
#ifdefHAVE_UNIX_SOCKETS
73-
if (hintp->ai_family==AF_UNIX)
74-
returngetaddrinfo_unix(servname,hintp,result);
75-
#endif
76-
77-
/* NULL has special meaning to getaddrinfo(). */
78-
rc=getaddrinfo((!hostname||hostname[0]=='\0') ?NULL :hostname,
79-
servname,hintp,result);
80-
81-
returnrc;
82-
}
83-
84-
85-
/*
86-
*pg_freeaddrinfo_all - free addrinfo structures for IPv4, IPv6, or Unix
87-
*
88-
* Note: the ai_family field of the original hint structure must be passed
89-
* so that we can tell whether the addrinfo struct was built by the system's
90-
* getaddrinfo() routine or our own getaddrinfo_unix() routine. Some versions
91-
* of getaddrinfo() might be willing to return AF_UNIX addresses, so it's
92-
* not safe to look at ai_family in the addrinfo itself.
93-
*/
94-
void
95-
pg_freeaddrinfo_all(inthint_ai_family,structaddrinfo*ai)
96-
{
97-
#ifdefHAVE_UNIX_SOCKETS
98-
if (hint_ai_family==AF_UNIX)
99-
{
100-
/* struct was built by getaddrinfo_unix (see pg_getaddrinfo_all) */
101-
while (ai!=NULL)
102-
{
103-
structaddrinfo*p=ai;
104-
105-
ai=ai->ai_next;
106-
free(p->ai_addr);
107-
free(p);
108-
}
109-
}
110-
else
111-
#endif/* HAVE_UNIX_SOCKETS */
112-
{
113-
/* struct was built by getaddrinfo() */
114-
if (ai!=NULL)
115-
freeaddrinfo(ai);
116-
}
117-
}
118-
119-
120-
/*
121-
*pg_getnameinfo_all - get name info for Unix, IPv4 and IPv6 sockets
122-
*
123-
* The API of this routine differs from the standard getnameinfo() definition
124-
* in two ways: first, the addr parameter is declared as sockaddr_storage
125-
* rather than struct sockaddr, and second, the node and service fields are
126-
* guaranteed to be filled with something even on failure return.
127-
*/
128-
int
129-
pg_getnameinfo_all(conststructsockaddr_storage*addr,intsalen,
130-
char*node,intnodelen,
131-
char*service,intservicelen,
132-
intflags)
133-
{
134-
intrc;
135-
136-
#ifdefHAVE_UNIX_SOCKETS
137-
if (addr&&addr->ss_family==AF_UNIX)
138-
rc=getnameinfo_unix((conststructsockaddr_un*)addr,salen,
139-
node,nodelen,
140-
service,servicelen,
141-
flags);
142-
else
143-
#endif
144-
rc=getnameinfo((conststructsockaddr*)addr,salen,
145-
node,nodelen,
146-
service,servicelen,
147-
flags);
148-
149-
if (rc!=0)
150-
{
151-
if (node)
152-
strlcpy(node,"???",nodelen);
153-
if (service)
154-
strlcpy(service,"???",servicelen);
155-
}
156-
157-
returnrc;
158-
}
159-
160-
161-
#if defined(HAVE_UNIX_SOCKETS)
162-
163-
/* -------
164-
*getaddrinfo_unix - get unix socket info using IPv6-compatible API
165-
*
166-
*Bugs: only one addrinfo is set even though hintsp is NULL or
167-
* ai_socktype is 0
168-
* AI_CANONNAME is not supported.
169-
* -------
170-
*/
171-
staticint
172-
getaddrinfo_unix(constchar*path,conststructaddrinfo*hintsp,
173-
structaddrinfo**result)
174-
{
175-
structaddrinfohints;
176-
structaddrinfo*aip;
177-
structsockaddr_un*unp;
178-
179-
*result=NULL;
180-
181-
MemSet(&hints,0,sizeof(hints));
182-
183-
if (strlen(path) >=sizeof(unp->sun_path))
184-
returnEAI_FAIL;
185-
186-
if (hintsp==NULL)
187-
{
188-
hints.ai_family=AF_UNIX;
189-
hints.ai_socktype=SOCK_STREAM;
190-
}
191-
else
192-
memcpy(&hints,hintsp,sizeof(hints));
193-
194-
if (hints.ai_socktype==0)
195-
hints.ai_socktype=SOCK_STREAM;
196-
197-
if (hints.ai_family!=AF_UNIX)
198-
{
199-
/* shouldn't have been called */
200-
returnEAI_FAIL;
201-
}
202-
203-
aip=calloc(1,sizeof(structaddrinfo));
204-
if (aip==NULL)
205-
returnEAI_MEMORY;
206-
207-
unp=calloc(1,sizeof(structsockaddr_un));
208-
if (unp==NULL)
209-
{
210-
free(aip);
211-
returnEAI_MEMORY;
212-
}
213-
214-
aip->ai_family=AF_UNIX;
215-
aip->ai_socktype=hints.ai_socktype;
216-
aip->ai_protocol=hints.ai_protocol;
217-
aip->ai_next=NULL;
218-
aip->ai_canonname=NULL;
219-
*result=aip;
220-
221-
unp->sun_family=AF_UNIX;
222-
aip->ai_addr= (structsockaddr*)unp;
223-
aip->ai_addrlen=sizeof(structsockaddr_un);
224-
225-
strcpy(unp->sun_path,path);
226-
227-
#ifdefHAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
228-
unp->sun_len=sizeof(structsockaddr_un);
229-
#endif
230-
231-
return0;
232-
}
233-
234-
/*
235-
* Convert an address to a hostname.
236-
*/
237-
staticint
238-
getnameinfo_unix(conststructsockaddr_un*sa,intsalen,
239-
char*node,intnodelen,
240-
char*service,intservicelen,
241-
intflags)
242-
{
243-
intret=-1;
244-
245-
/* Invalid arguments. */
246-
if (sa==NULL||sa->sun_family!=AF_UNIX||
247-
(node==NULL&&service==NULL))
248-
returnEAI_FAIL;
249-
250-
if (node)
251-
{
252-
ret=snprintf(node,nodelen,"%s","[local]");
253-
if (ret==-1||ret>nodelen)
254-
returnEAI_MEMORY;
255-
}
256-
257-
if (service)
258-
{
259-
ret=snprintf(service,servicelen,"%s",sa->sun_path);
260-
if (ret==-1||ret>servicelen)
261-
returnEAI_MEMORY;
262-
}
263-
264-
return0;
265-
}
266-
#endif/* HAVE_UNIX_SOCKETS */
267-
26846

26947
/*
27048
* pg_range_sockaddr - is addr within the subnet specified by netaddr/netmask ?

‎src/backend/libpq/pqcomm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
#include<mstcpip.h>
9090
#endif
9191

92-
#include"libpq/ip.h"
92+
#include"common/ip.h"
9393
#include"libpq/libpq.h"
9494
#include"miscadmin.h"
9595
#include"storage/ipc.h"

‎src/backend/postmaster/pgstat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include"access/xact.h"
3939
#include"catalog/pg_database.h"
4040
#include"catalog/pg_proc.h"
41-
#include"libpq/ip.h"
41+
#include"common/ip.h"
4242
#include"libpq/libpq.h"
4343
#include"libpq/pqsignal.h"
4444
#include"mb/pg_wchar.h"

‎src/backend/postmaster/postmaster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@
9999
#include"access/xlog.h"
100100
#include"bootstrap/bootstrap.h"
101101
#include"catalog/pg_control.h"
102+
#include"common/ip.h"
102103
#include"lib/ilist.h"
103104
#include"libpq/auth.h"
104-
#include"libpq/ip.h"
105105
#include"libpq/libpq.h"
106106
#include"libpq/pqsignal.h"
107107
#include"miscadmin.h"

‎src/backend/utils/adt/network.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include"access/hash.h"
1616
#include"catalog/pg_type.h"
17-
#include"libpq/ip.h"
17+
#include"common/ip.h"
1818
#include"libpq/libpq-be.h"
1919
#include"libpq/pqformat.h"
2020
#include"miscadmin.h"

‎src/backend/utils/adt/pgstatfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#include"access/htup_details.h"
1818
#include"catalog/pg_type.h"
19+
#include"common/ip.h"
1920
#include"funcapi.h"
20-
#include"libpq/ip.h"
2121
#include"miscadmin.h"
2222
#include"pgstat.h"
2323
#include"storage/proc.h"

‎src/backend/utils/adt/varlena.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include"access/tuptoaster.h"
2222
#include"catalog/pg_collation.h"
2323
#include"catalog/pg_type.h"
24+
#include"common/md5.h"
2425
#include"lib/hyperloglog.h"
25-
#include"libpq/md5.h"
2626
#include"libpq/pqformat.h"
2727
#include"miscadmin.h"
2828
#include"parser/scansup.h"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp