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

Commit7b0f060

Browse files
committed
Use canonicalize_path for -D, GUC paths, and paths coming in from
environment variables.
1 parent8801110 commit7b0f060

File tree

5 files changed

+71
-39
lines changed

5 files changed

+71
-39
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.407 2004/07/1100:18:43 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.408 2004/07/1121:33:59 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -372,7 +372,8 @@ PostmasterMain(int argc, char *argv[])
372372
InitializeGUCOptions();
373373

374374
userPGDATA=getenv("PGDATA");/* default value */
375-
375+
canonicalize_path(userPGDATA);
376+
376377
opterr=1;
377378

378379
while ((opt=getopt(argc,argv,"A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:"))!=-1)

‎src/backend/utils/misc/guc.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.214 2004/07/1100:18:44 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.215 2004/07/1121:34:00 momjian Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -113,6 +113,7 @@ static const char *assign_custom_variable_classes(const char *newval, bool doit,
113113
staticboolassign_stage_log_stats(boolnewval,booldoit,GucSourcesource);
114114
staticboolassign_log_stats(boolnewval,booldoit,GucSourcesource);
115115
staticboolassign_transaction_read_only(boolnewval,booldoit,GucSourcesource);
116+
staticconstchar*assign_canonical_path(constchar*newval,booldoit,GucSourcesource);
116117

117118
staticvoidReadConfigFile(char*filename,GucContextcontext);
118119

@@ -1470,7 +1471,7 @@ static struct config_string ConfigureNamesString[] =
14701471
"the specified file.")
14711472
},
14721473
&Dynamic_library_path,
1473-
"$libdir",NULL,NULL
1474+
"$libdir",assign_canonical_path,NULL
14741475
},
14751476

14761477
{
@@ -1556,7 +1557,7 @@ static struct config_string ConfigureNamesString[] =
15561557
GUC_LIST_INPUT |GUC_LIST_QUOTE
15571558
},
15581559
&preload_libraries_string,
1559-
"",NULL,NULL
1560+
"",assign_canonical_path,NULL
15601561
},
15611562

15621563
{
@@ -1678,7 +1679,7 @@ static struct config_string ConfigureNamesString[] =
16781679
NULL
16791680
},
16801681
&UnixSocketDir,
1681-
"",NULL,NULL
1682+
"",assign_canonical_path,NULL
16821683
},
16831684

16841685
{
@@ -1712,25 +1713,25 @@ static struct config_string ConfigureNamesString[] =
17121713
{
17131714
{"pgdata",PGC_POSTMASTER,0,gettext_noop("Sets the location of the data directory"),NULL},
17141715
&guc_pgdata,
1715-
NULL,NULL,NULL
1716+
NULL,assign_canonical_path,NULL
17161717
},
17171718

17181719
{
17191720
{"hba_conf",PGC_SIGHUP,0,gettext_noop("Sets the location of the \"hba\" configuration file"),NULL},
17201721
&guc_hbafile,
1721-
NULL,NULL,NULL
1722+
NULL,assign_canonical_path,NULL
17221723
},
17231724

17241725
{
17251726
{"ident_conf",PGC_SIGHUP,0,gettext_noop("Sets the location of the \"ident\" configuration file"),NULL},
17261727
&guc_identfile,
1727-
NULL,NULL,NULL
1728+
NULL,assign_canonical_path,NULL
17281729
},
17291730

17301731
{
17311732
{"external_pidfile",PGC_POSTMASTER,0,gettext_noop("Writes the postmaster PID to the specified file"),NULL},
17321733
&external_pidfile,
1733-
NULL,NULL,NULL
1734+
NULL,assign_canonical_path,NULL
17341735
},
17351736

17361737
/* End-of-list marker */
@@ -5160,8 +5161,7 @@ assign_log_min_messages(const char *newval,
51605161
}
51615162

51625163
staticconstchar*
5163-
assign_client_min_messages(constchar*newval,
5164-
booldoit,GucSourcesource)
5164+
assign_client_min_messages(constchar*newval,booldoit,GucSourcesource)
51655165
{
51665166
return (assign_msglvl(&client_min_messages,newval,doit,source));
51675167
}
@@ -5430,4 +5430,19 @@ assign_transaction_read_only(bool newval, bool doit, GucSource source)
54305430
return true;
54315431
}
54325432

5433+
staticconstchar*
5434+
assign_canonical_path(constchar*newval,booldoit,GucSourcesource)
5435+
{
5436+
5437+
if (doit)
5438+
{
5439+
/* We have to create a new pointer to force the change */
5440+
char*canon_val=guc_strdup(FATAL,newval);
5441+
canonicalize_path(canon_val);
5442+
returncanon_val;
5443+
}
5444+
else
5445+
returnnewval;
5446+
}
5447+
54335448
#include"guc-file.c"

‎src/bin/psql/command.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.119 2004/07/1113:29:15 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.120 2004/07/1121:34:03 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -375,6 +375,7 @@ exec_command(const char *cmd,
375375
fname=psql_scan_slash_option(scan_state,
376376
OT_NORMAL,NULL, true);
377377
expand_tilde(&fname);
378+
canonicalize_path(fname);
378379
status=do_edit(fname,query_buf) ?CMD_NEWEDIT :CMD_ERROR;
379380
free(fname);
380381
}
@@ -777,8 +778,10 @@ exec_command(const char *cmd,
777778
fd=popen(&fname[1],"w");
778779
}
779780
else
781+
{
782+
canonicalize_path(fname);
780783
fd=fopen(fname,"w");
781-
784+
}
782785
if (!fd)
783786
{
784787
psql_error("%s: %s\n",fname,strerror(errno));
@@ -1122,7 +1125,6 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
11221125

11231126
if (filename_arg)
11241127
fname=filename_arg;
1125-
11261128
else
11271129
{
11281130
/* make a temp file to edit */
@@ -1262,6 +1264,7 @@ process_file(char *filename)
12621264
if (!filename)
12631265
return false;
12641266

1267+
canonicalize_path(filename);
12651268
fd=fopen(filename,PG_BINARY_R);
12661269

12671270
if (!fd)

‎src/bin/psql/copy.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.49 2004/07/1113:29:15 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.50 2004/07/1121:34:03 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"copy.h"
@@ -513,6 +513,8 @@ do_copy(const char *args)
513513
appendPQExpBuffer(&query," FORCE NOT NULL %s",options->force_notnull_list);
514514
}
515515

516+
canonicalize_path(options->file);
517+
516518
if (options->from)
517519
{
518520
if (options->file)

‎src/port/path.c

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/port/path.c,v 1.22 2004/07/1102:59:42 momjian Exp $
11+
* $PostgreSQL: pgsql/src/port/path.c,v 1.23 2004/07/1121:34:04 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -33,6 +33,7 @@
3333
#endif
3434

3535
conststaticchar*relative_path(constchar*bin_path,constchar*other_path);
36+
staticvoidmake_relative(constchar*my_exec_path,constchar*p,char*ret_path);
3637
staticvoidtrim_directory(char*path);
3738
staticvoidtrim_trailing_separator(char*path);
3839

@@ -43,15 +44,6 @@ static void trim_trailing_separator(char *path);
4344
(p)++; \
4445
}
4546

46-
/* Macro creates a relative path */
47-
#defineMAKE_RELATIVE \
48-
do { \
49-
StrNCpy(path, my_exec_path, MAXPGPATH); \
50-
trim_directory(path); \
51-
trim_directory(path); \
52-
snprintf(ret_path, MAXPGPATH, "%s/%s", path, p); \
53-
} while (0)
54-
5547
/*
5648
*first_dir_separator
5749
*/
@@ -140,13 +132,13 @@ get_progname(const char *argv0)
140132
void
141133
get_share_path(constchar*my_exec_path,char*ret_path)
142134
{
143-
charpath[MAXPGPATH];
144135
constchar*p;
145136

146137
if ((p=relative_path(PGBINDIR,PGSHAREDIR)))
147-
MAKE_RELATIVE;
138+
make_relative(my_exec_path,p,ret_path);
148139
else
149140
StrNCpy(ret_path,PGSHAREDIR,MAXPGPATH);
141+
canonicalize_path(ret_path);
150142
}
151143

152144

@@ -157,13 +149,13 @@ get_share_path(const char *my_exec_path, char *ret_path)
157149
void
158150
get_etc_path(constchar*my_exec_path,char*ret_path)
159151
{
160-
charpath[MAXPGPATH];
161152
constchar*p;
162153

163154
if ((p=relative_path(PGBINDIR,SYSCONFDIR)))
164-
MAKE_RELATIVE;
155+
make_relative(my_exec_path,p,ret_path);
165156
else
166157
StrNCpy(ret_path,SYSCONFDIR,MAXPGPATH);
158+
canonicalize_path(ret_path);
167159
}
168160

169161

@@ -174,13 +166,13 @@ get_etc_path(const char *my_exec_path, char *ret_path)
174166
void
175167
get_include_path(constchar*my_exec_path,char*ret_path)
176168
{
177-
charpath[MAXPGPATH];
178169
constchar*p;
179170

180171
if ((p=relative_path(PGBINDIR,INCLUDEDIR)))
181-
MAKE_RELATIVE;
172+
make_relative(my_exec_path,p,ret_path);
182173
else
183174
StrNCpy(ret_path,INCLUDEDIR,MAXPGPATH);
175+
canonicalize_path(ret_path);
184176
}
185177

186178

@@ -191,13 +183,13 @@ get_include_path(const char *my_exec_path, char *ret_path)
191183
void
192184
get_pkginclude_path(constchar*my_exec_path,char*ret_path)
193185
{
194-
charpath[MAXPGPATH];
195186
constchar*p;
196187

197188
if ((p=relative_path(PGBINDIR,PKGINCLUDEDIR)))
198-
MAKE_RELATIVE;
189+
make_relative(my_exec_path,p,ret_path);
199190
else
200191
StrNCpy(ret_path,PKGINCLUDEDIR,MAXPGPATH);
192+
canonicalize_path(ret_path);
201193
}
202194

203195

@@ -210,13 +202,13 @@ get_pkginclude_path(const char *my_exec_path, char *ret_path)
210202
void
211203
get_pkglib_path(constchar*my_exec_path,char*ret_path)
212204
{
213-
charpath[MAXPGPATH];
214205
constchar*p;
215206

216207
if ((p=relative_path(PGBINDIR,PKGLIBDIR)))
217-
MAKE_RELATIVE;
208+
make_relative(my_exec_path,p,ret_path);
218209
else
219210
StrNCpy(ret_path,PKGLIBDIR,MAXPGPATH);
211+
canonicalize_path(ret_path);
220212
}
221213

222214

@@ -229,13 +221,13 @@ get_pkglib_path(const char *my_exec_path, char *ret_path)
229221
void
230222
get_locale_path(constchar*my_exec_path,char*ret_path)
231223
{
232-
charpath[MAXPGPATH];
233224
constchar*p;
234225

235226
if ((p=relative_path(PGBINDIR,LOCALEDIR)))
236-
MAKE_RELATIVE;
227+
make_relative(my_exec_path,p,ret_path);
237228
else
238229
StrNCpy(ret_path,LOCALEDIR,MAXPGPATH);
230+
canonicalize_path(ret_path);
239231
}
240232

241233

@@ -270,6 +262,7 @@ set_pglocale_pgservice(const char *argv0, const char *app)
270262
{
271263
/* set for libpq to use */
272264
snprintf(env_path,sizeof(env_path),"PGLOCALEDIR=%s",path);
265+
canonicalize_path(env_path);
273266
putenv(strdup(env_path));
274267
}
275268
#endif
@@ -280,11 +273,26 @@ set_pglocale_pgservice(const char *argv0, const char *app)
280273

281274
/* set for libpq to use */
282275
snprintf(env_path,sizeof(env_path),"PGSYSCONFDIR=%s",path);
276+
canonicalize_path(env_path);
283277
putenv(strdup(env_path));
284278
}
285279
}
286280

287281

282+
/*
283+
*make_relative - adjust path to be relative to bin/
284+
*/
285+
staticvoid
286+
make_relative(constchar*my_exec_path,constchar*p,char*ret_path)
287+
{
288+
charpath[MAXPGPATH];
289+
290+
StrNCpy(path,my_exec_path,MAXPGPATH);
291+
trim_directory(path);
292+
trim_directory(path);
293+
snprintf(ret_path,MAXPGPATH,"%s/%s",path,p);
294+
}
295+
288296

289297
/*
290298
*relative_path
@@ -391,7 +399,10 @@ trim_trailing_separator(char *path)
391399
char*p=path+strlen(path);
392400

393401
#ifdefWIN32
394-
/* Skip over network and drive specifiers for win32 */
402+
/*
403+
*Skip over network and drive specifiers for win32.
404+
*Set 'path' to point to the last character to keep.
405+
*/
395406
if (strlen(path) >=2)
396407
{
397408
if (IS_DIR_SEP(path[0])&&IS_DIR_SEP(path[1]))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp