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

Commit9aca512

Browse files
committed
Make sure -D is an absolute path when starting server on Windows.
This is needed because Windows services may get started with a differentcurrent directory than where pg_ctl is executed. We want relative -Dpaths to be interpreted relative to pg_ctl's CWD, similarly to whathappens on other platforms.In support of this, move the backend's make_absolute_path() functioninto src/port/path.c (where it probably should have been long since)and get rid of the rather inferior version in pg_regress.Kumar Rajeev Rastogi, reviewed by MauMau
1 parent8120c74 commit9aca512

File tree

6 files changed

+124
-101
lines changed

6 files changed

+124
-101
lines changed

‎src/backend/utils/init/miscinit.c

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -117,77 +117,6 @@ ChangeToDataDir(void)
117117
DataDir)));
118118
}
119119

120-
/*
121-
* If the given pathname isn't already absolute, make it so, interpreting
122-
* it relative to the current working directory.
123-
*
124-
* Also canonicalizes the path. The result is always a malloc'd copy.
125-
*
126-
* Note: interpretation of relative-path arguments during postmaster startup
127-
* should happen before doing ChangeToDataDir(), else the user will probably
128-
* not like the results.
129-
*/
130-
char*
131-
make_absolute_path(constchar*path)
132-
{
133-
char*new;
134-
135-
/* Returning null for null input is convenient for some callers */
136-
if (path==NULL)
137-
returnNULL;
138-
139-
if (!is_absolute_path(path))
140-
{
141-
char*buf;
142-
size_tbuflen;
143-
144-
buflen=MAXPGPATH;
145-
for (;;)
146-
{
147-
buf=malloc(buflen);
148-
if (!buf)
149-
ereport(FATAL,
150-
(errcode(ERRCODE_OUT_OF_MEMORY),
151-
errmsg("out of memory")));
152-
153-
if (getcwd(buf,buflen))
154-
break;
155-
elseif (errno==ERANGE)
156-
{
157-
free(buf);
158-
buflen *=2;
159-
continue;
160-
}
161-
else
162-
{
163-
free(buf);
164-
elog(FATAL,"could not get current working directory: %m");
165-
}
166-
}
167-
168-
new=malloc(strlen(buf)+strlen(path)+2);
169-
if (!new)
170-
ereport(FATAL,
171-
(errcode(ERRCODE_OUT_OF_MEMORY),
172-
errmsg("out of memory")));
173-
sprintf(new,"%s/%s",buf,path);
174-
free(buf);
175-
}
176-
else
177-
{
178-
new=strdup(path);
179-
if (!new)
180-
ereport(FATAL,
181-
(errcode(ERRCODE_OUT_OF_MEMORY),
182-
errmsg("out of memory")));
183-
}
184-
185-
/* Make sure punctuation is canonical, too */
186-
canonicalize_path(new);
187-
188-
returnnew;
189-
}
190-
191120

192121
/* ----------------------------------------------------------------
193122
*User ID state

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,19 @@ pgwin32_CommandLine(bool registration)
13871387
register_servicename);
13881388

13891389
if (pg_config)
1390-
appendPQExpBuffer(cmdLine," -D \"%s\"",pg_config);
1390+
{
1391+
/* We need the -D path to be absolute */
1392+
char*dataDir;
1393+
1394+
if ((dataDir=make_absolute_path(pg_config))==NULL)
1395+
{
1396+
/* make_absolute_path already reported the error */
1397+
exit(1);
1398+
}
1399+
make_native_path(dataDir);
1400+
appendPQExpBuffer(cmdLine," -D \"%s\"",dataDir);
1401+
free(dataDir);
1402+
}
13911403

13921404
if (registration&&do_wait)
13931405
appendPQExpBuffer(cmdLine," -w");

‎src/include/miscadmin.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ extern void SetCurrentRoleId(Oid roleid, bool is_superuser);
296296

297297
externvoidSetDataDir(constchar*dir);
298298
externvoidChangeToDataDir(void);
299-
externchar*make_absolute_path(constchar*path);
300299

301300
/* in utils/misc/superuser.c */
302301
externboolsuperuser(void);/* current user is superuser */

‎src/include/port.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern void make_native_path(char *path);
4545
externboolpath_contains_parent_reference(constchar*path);
4646
externboolpath_is_relative_and_below_cwd(constchar*path);
4747
externboolpath_is_prefix_of_path(constchar*path1,constchar*path2);
48+
externchar*make_absolute_path(constchar*path);
4849
externconstchar*get_progname(constchar*argv0);
4950
externvoidget_share_path(constchar*my_exec_path,char*ret_path);
5051
externvoidget_etc_path(constchar*my_exec_path,char*ret_path);

‎src/port/path.c

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
*-------------------------------------------------------------------------
1414
*/
1515

16-
#include"c.h"
16+
#ifndefFRONTEND
17+
#include"postgres.h"
18+
#else
19+
#include"postgres_fe.h"
20+
#endif
1721

1822
#include<ctype.h>
1923
#include<sys/stat.h>
@@ -549,6 +553,111 @@ make_relative_path(char *ret_path, const char *target_path,
549553
}
550554

551555

556+
/*
557+
* make_absolute_path
558+
*
559+
* If the given pathname isn't already absolute, make it so, interpreting
560+
* it relative to the current working directory.
561+
*
562+
* Also canonicalizes the path. The result is always a malloc'd copy.
563+
*
564+
* In backend, failure cases result in ereport(ERROR); in frontend,
565+
* we write a complaint on stderr and return NULL.
566+
*
567+
* Note: interpretation of relative-path arguments during postmaster startup
568+
* should happen before doing ChangeToDataDir(), else the user will probably
569+
* not like the results.
570+
*/
571+
char*
572+
make_absolute_path(constchar*path)
573+
{
574+
char*new;
575+
576+
/* Returning null for null input is convenient for some callers */
577+
if (path==NULL)
578+
returnNULL;
579+
580+
if (!is_absolute_path(path))
581+
{
582+
char*buf;
583+
size_tbuflen;
584+
585+
buflen=MAXPGPATH;
586+
for (;;)
587+
{
588+
buf=malloc(buflen);
589+
if (!buf)
590+
{
591+
#ifndefFRONTEND
592+
ereport(ERROR,
593+
(errcode(ERRCODE_OUT_OF_MEMORY),
594+
errmsg("out of memory")));
595+
#else
596+
fprintf(stderr,_("out of memory\n"));
597+
returnNULL;
598+
#endif
599+
}
600+
601+
if (getcwd(buf,buflen))
602+
break;
603+
elseif (errno==ERANGE)
604+
{
605+
free(buf);
606+
buflen *=2;
607+
continue;
608+
}
609+
else
610+
{
611+
free(buf);
612+
#ifndefFRONTEND
613+
elog(ERROR,"could not get current working directory: %m");
614+
#else
615+
fprintf(stderr,_("could not get current working directory: %s\n"),
616+
strerror(errno));
617+
returnNULL;
618+
#endif
619+
}
620+
}
621+
622+
new=malloc(strlen(buf)+strlen(path)+2);
623+
if (!new)
624+
{
625+
free(buf);
626+
#ifndefFRONTEND
627+
ereport(ERROR,
628+
(errcode(ERRCODE_OUT_OF_MEMORY),
629+
errmsg("out of memory")));
630+
#else
631+
fprintf(stderr,_("out of memory\n"));
632+
returnNULL;
633+
#endif
634+
}
635+
sprintf(new,"%s/%s",buf,path);
636+
free(buf);
637+
}
638+
else
639+
{
640+
new=strdup(path);
641+
if (!new)
642+
{
643+
#ifndefFRONTEND
644+
ereport(ERROR,
645+
(errcode(ERRCODE_OUT_OF_MEMORY),
646+
errmsg("out of memory")));
647+
#else
648+
fprintf(stderr,_("out of memory\n"));
649+
returnNULL;
650+
#endif
651+
}
652+
}
653+
654+
/* Make sure punctuation is canonical, too */
655+
canonicalize_path(new);
656+
657+
returnnew;
658+
}
659+
660+
552661
/*
553662
*get_share_path
554663
*/

‎src/test/regress/pg_regress.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,33 +1855,6 @@ create_role(const char *rolename, const _stringlist * granted_dbs)
18551855
}
18561856
}
18571857

1858-
staticchar*
1859-
make_absolute_path(constchar*in)
1860-
{
1861-
char*result;
1862-
1863-
if (is_absolute_path(in))
1864-
result=strdup(in);
1865-
else
1866-
{
1867-
staticcharcwdbuf[MAXPGPATH];
1868-
1869-
if (!cwdbuf[0])
1870-
{
1871-
if (!getcwd(cwdbuf,sizeof(cwdbuf)))
1872-
{
1873-
fprintf(stderr,_("could not get current working directory: %s\n"),strerror(errno));
1874-
exit(2);
1875-
}
1876-
}
1877-
1878-
result=psprintf("%s/%s",cwdbuf,in);
1879-
}
1880-
1881-
canonicalize_path(result);
1882-
returnresult;
1883-
}
1884-
18851858
staticvoid
18861859
help(void)
18871860
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp