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
abfb4175
Commit
abfb4175
authored
Nov 04, 2000
by
Peter Eisentraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the backend grok relative paths for the data directory by converting
it to an absolute path.
parent
7bea44f4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
42 deletions
+111
-42
src/backend/bootstrap/bootstrap.c
src/backend/bootstrap/bootstrap.c
+18
-11
src/backend/postmaster/postmaster.c
src/backend/postmaster/postmaster.c
+14
-14
src/backend/tcop/postgres.c
src/backend/tcop/postgres.c
+19
-15
src/backend/utils/init/miscinit.c
src/backend/utils/init/miscinit.c
+57
-1
src/include/miscadmin.h
src/include/miscadmin.h
+3
-1
No files found.
src/backend/bootstrap/bootstrap.c
View file @
abfb4175
...
@@ -8,10 +8,12 @@
...
@@ -8,10 +8,12 @@
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.9
5 2000/10/24 09:56:09 vadim
Exp $
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.9
6 2000/11/04 12:43:23 petere
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
#include "postgres.h"
#include <unistd.h>
#include <unistd.h>
#include <time.h>
#include <time.h>
#include <signal.h>
#include <signal.h>
...
@@ -19,7 +21,6 @@
...
@@ -19,7 +21,6 @@
#define BOOTSTRAP_INCLUDE
/* mask out stuff in tcop/tcopprot.h */
#define BOOTSTRAP_INCLUDE
/* mask out stuff in tcop/tcopprot.h */
#include "postgres.h"
#ifdef HAVE_GETOPT_H
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#include <getopt.h>
#endif
#endif
...
@@ -220,6 +221,7 @@ BootstrapMain(int argc, char *argv[])
...
@@ -220,6 +221,7 @@ BootstrapMain(int argc, char *argv[])
char
*
dbName
;
char
*
dbName
;
int
flag
;
int
flag
;
bool
xloginit
=
false
;
bool
xloginit
=
false
;
char
*
potential_DataDir
=
NULL
;
extern
int
optind
;
extern
int
optind
;
extern
char
*
optarg
;
extern
char
*
optarg
;
...
@@ -255,7 +257,7 @@ BootstrapMain(int argc, char *argv[])
...
@@ -255,7 +257,7 @@ BootstrapMain(int argc, char *argv[])
if
(
!
IsUnderPostmaster
)
if
(
!
IsUnderPostmaster
)
{
{
ResetAllOptions
();
ResetAllOptions
();
DataDir
=
getenv
(
"PGDATA"
);
/* Null if no PGDATA variable */
potential_
DataDir
=
getenv
(
"PGDATA"
);
/* Null if no PGDATA variable */
}
}
while
((
flag
=
getopt
(
argc
,
argv
,
"D:dCQxpB:F"
))
!=
EOF
)
while
((
flag
=
getopt
(
argc
,
argv
,
"D:dCQxpB:F"
))
!=
EOF
)
...
@@ -263,7 +265,7 @@ BootstrapMain(int argc, char *argv[])
...
@@ -263,7 +265,7 @@ BootstrapMain(int argc, char *argv[])
switch
(
flag
)
switch
(
flag
)
{
{
case
'D'
:
case
'D'
:
DataDir
=
optarg
;
potential_
DataDir
=
optarg
;
break
;
break
;
case
'd'
:
case
'd'
:
DebugMode
=
true
;
/* print out debugging info while
DebugMode
=
true
;
/* print out debugging info while
...
@@ -301,7 +303,9 @@ BootstrapMain(int argc, char *argv[])
...
@@ -301,7 +303,9 @@ BootstrapMain(int argc, char *argv[])
SetProcessingMode
(
BootstrapProcessing
);
SetProcessingMode
(
BootstrapProcessing
);
IgnoreSystemIndexes
(
true
);
IgnoreSystemIndexes
(
true
);
if
(
!
DataDir
)
if
(
!
IsUnderPostmaster
)
{
if
(
!
potential_DataDir
)
{
{
fprintf
(
stderr
,
"%s does not know where to find the database system "
fprintf
(
stderr
,
"%s does not know where to find the database system "
"data. You must specify the directory that contains the "
"data. You must specify the directory that contains the "
...
@@ -310,6 +314,9 @@ BootstrapMain(int argc, char *argv[])
...
@@ -310,6 +314,9 @@ BootstrapMain(int argc, char *argv[])
argv
[
0
]);
argv
[
0
]);
proc_exit
(
1
);
proc_exit
(
1
);
}
}
SetDataDir
(
potential_DataDir
);
}
Assert
(
DataDir
);
if
(
dbName
==
NULL
)
if
(
dbName
==
NULL
)
{
{
...
...
src/backend/postmaster/postmaster.c
View file @
abfb4175
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.17
7 2000/11/01 21:14:02
petere Exp $
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.17
8 2000/11/04 12:43:23
petere Exp $
*
*
* NOTES
* NOTES
*
*
...
@@ -268,12 +268,12 @@ extern void GetCharSetByHost(char *, int, char *);
...
@@ -268,12 +268,12 @@ extern void GetCharSetByHost(char *, int, char *);
static
void
static
void
checkDataDir
(
const
char
*
DataD
ir
)
checkDataDir
(
const
char
*
checkd
ir
)
{
{
char
path
[
MAXPGPATH
];
char
path
[
MAXPGPATH
];
FILE
*
fp
;
FILE
*
fp
;
if
(
DataD
ir
==
NULL
)
if
(
checkd
ir
==
NULL
)
{
{
fprintf
(
stderr
,
"%s does not know where to find the database system "
fprintf
(
stderr
,
"%s does not know where to find the database system "
"data. You must specify the directory that contains the "
"data. You must specify the directory that contains the "
...
@@ -285,10 +285,10 @@ checkDataDir(const char *DataDir)
...
@@ -285,10 +285,10 @@ checkDataDir(const char *DataDir)
#ifdef OLD_FILE_NAMING
#ifdef OLD_FILE_NAMING
snprintf
(
path
,
sizeof
(
path
),
"%s%cbase%ctemplate1%cpg_class"
,
snprintf
(
path
,
sizeof
(
path
),
"%s%cbase%ctemplate1%cpg_class"
,
DataD
ir
,
SEP_CHAR
,
SEP_CHAR
,
SEP_CHAR
);
checkd
ir
,
SEP_CHAR
,
SEP_CHAR
,
SEP_CHAR
);
#else
#else
snprintf
(
path
,
sizeof
(
path
),
"%s%cbase%c%u%c%u"
,
snprintf
(
path
,
sizeof
(
path
),
"%s%cbase%c%u%c%u"
,
DataD
ir
,
SEP_CHAR
,
SEP_CHAR
,
checkd
ir
,
SEP_CHAR
,
SEP_CHAR
,
TemplateDbOid
,
SEP_CHAR
,
RelOid_pg_class
);
TemplateDbOid
,
SEP_CHAR
,
RelOid_pg_class
);
#endif
#endif
...
@@ -298,13 +298,13 @@ checkDataDir(const char *DataDir)
...
@@ -298,13 +298,13 @@ checkDataDir(const char *DataDir)
fprintf
(
stderr
,
"%s does not find the database system."
fprintf
(
stderr
,
"%s does not find the database system."
"
\n\t
Expected to find it in the PGDATA directory
\"
%s
\"
,"
"
\n\t
Expected to find it in the PGDATA directory
\"
%s
\"
,"
"
\n\t
but unable to open file
\"
%s
\"
: %s
\n\n
"
,
"
\n\t
but unable to open file
\"
%s
\"
: %s
\n\n
"
,
progname
,
DataD
ir
,
path
,
strerror
(
errno
));
progname
,
checkd
ir
,
path
,
strerror
(
errno
));
exit
(
2
);
exit
(
2
);
}
}
FreeFile
(
fp
);
FreeFile
(
fp
);
ValidatePgVersion
(
DataD
ir
);
ValidatePgVersion
(
checkd
ir
);
}
}
...
@@ -314,6 +314,7 @@ PostmasterMain(int argc, char *argv[])
...
@@ -314,6 +314,7 @@ PostmasterMain(int argc, char *argv[])
int
opt
;
int
opt
;
int
status
;
int
status
;
char
original_extraoptions
[
MAXPGPATH
];
char
original_extraoptions
[
MAXPGPATH
];
char
*
potential_DataDir
=
NULL
;
IsUnderPostmaster
=
true
;
/* so that backends know this */
IsUnderPostmaster
=
true
;
/* so that backends know this */
...
@@ -353,8 +354,7 @@ PostmasterMain(int argc, char *argv[])
...
@@ -353,8 +354,7 @@ PostmasterMain(int argc, char *argv[])
/*
/*
* Options setup
* Options setup
*/
*/
if
(
getenv
(
"PGDATA"
))
potential_DataDir
=
getenv
(
"PGDATA"
);
/* default value */
DataDir
=
strdup
(
getenv
(
"PGDATA"
));
/* default value */
ResetAllOptions
();
ResetAllOptions
();
...
@@ -377,9 +377,7 @@ PostmasterMain(int argc, char *argv[])
...
@@ -377,9 +377,7 @@ PostmasterMain(int argc, char *argv[])
switch
(
opt
)
switch
(
opt
)
{
{
case
'D'
:
case
'D'
:
if
(
DataDir
)
potential_DataDir
=
optarg
;
free
(
DataDir
);
DataDir
=
strdup
(
optarg
);
break
;
break
;
case
'-'
:
case
'-'
:
...
@@ -415,12 +413,14 @@ PostmasterMain(int argc, char *argv[])
...
@@ -415,12 +413,14 @@ PostmasterMain(int argc, char *argv[])
}
}
}
}
optind
=
1
;
/* start over
*/
checkDataDir
(
potential_DataDir
);
/* issues error messages
*/
checkDataDir
(
DataDir
);
/* issues error messages */
SetDataDir
(
potential_DataDir
);
ProcessConfigFile
(
PGC_POSTMASTER
);
ProcessConfigFile
(
PGC_POSTMASTER
);
IgnoreSystemIndexes
(
false
);
IgnoreSystemIndexes
(
false
);
optind
=
1
;
/* start over */
while
((
opt
=
getopt
(
argc
,
argv
,
"A:a:B:b:D:d:Film:MN:no:p:Ss-:?"
))
!=
EOF
)
while
((
opt
=
getopt
(
argc
,
argv
,
"A:a:B:b:D:d:Film:MN:no:p:Ss-:?"
))
!=
EOF
)
{
{
switch
(
opt
)
switch
(
opt
)
...
...
src/backend/tcop/postgres.c
View file @
abfb4175
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.18
4 2000/10/28 18:27:56 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.18
5 2000/11/04 12:43:24 petere
Exp $
*
*
* NOTES
* NOTES
* this is the "main" module of the postgres backend and
* this is the "main" module of the postgres backend and
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
#include <errno.h>
#include <errno.h>
#if HAVE_SYS_SELECT_H
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
#include <sys/select.h>
#endif
/* aix */
#endif
#include <netinet/in.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netdb.h>
...
@@ -1058,6 +1058,8 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
...
@@ -1058,6 +1058,8 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
char
*
remote_host
;
char
*
remote_host
;
unsigned
short
remote_port
;
unsigned
short
remote_port
;
char
*
potential_DataDir
=
NULL
;
extern
int
optind
;
extern
int
optind
;
extern
char
*
optarg
;
extern
char
*
optarg
;
extern
int
DebugLvl
;
extern
int
DebugLvl
;
...
@@ -1082,8 +1084,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
...
@@ -1082,8 +1084,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
if
(
!
IsUnderPostmaster
)
if
(
!
IsUnderPostmaster
)
{
{
ResetAllOptions
();
ResetAllOptions
();
if
(
getenv
(
"PGDATA"
))
potential_DataDir
=
getenv
(
"PGDATA"
);
DataDir
=
strdup
(
getenv
(
"PGDATA"
));
}
}
StatFp
=
stderr
;
StatFp
=
stderr
;
...
@@ -1142,9 +1143,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
...
@@ -1142,9 +1143,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
case
'D'
:
/* PGDATA directory */
case
'D'
:
/* PGDATA directory */
if
(
secure
)
if
(
secure
)
{
{
if
(
DataDir
)
potential_DataDir
=
optarg
;
free
(
DataDir
);
DataDir
=
strdup
(
optarg
);
}
}
break
;
break
;
...
@@ -1429,7 +1428,9 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
...
@@ -1429,7 +1428,9 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
Show_query_stats
=
false
;
Show_query_stats
=
false
;
}
}
if
(
!
DataDir
)
if
(
!
IsUnderPostmaster
)
{
if
(
!
potential_DataDir
)
{
{
fprintf
(
stderr
,
"%s does not know where to find the database system "
fprintf
(
stderr
,
"%s does not know where to find the database system "
"data. You must specify the directory that contains the "
"data. You must specify the directory that contains the "
...
@@ -1438,6 +1439,9 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
...
@@ -1438,6 +1439,9 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
argv
[
0
]);
argv
[
0
]);
proc_exit
(
1
);
proc_exit
(
1
);
}
}
SetDataDir
(
potential_DataDir
);
}
Assert
(
DataDir
);
/*
/*
* 1. Set BlockSig and UnBlockSig masks. 2. Set up signal handlers. 3.
* 1. Set BlockSig and UnBlockSig masks. 2. Set up signal handlers. 3.
...
@@ -1631,7 +1635,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
...
@@ -1631,7 +1635,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
if
(
!
IsUnderPostmaster
)
if
(
!
IsUnderPostmaster
)
{
{
puts
(
"
\n
POSTGRES backend interactive interface "
);
puts
(
"
\n
POSTGRES backend interactive interface "
);
puts
(
"$Revision: 1.18
4 $ $Date: 2000/10/28 18:27:56
$
\n
"
);
puts
(
"$Revision: 1.18
5 $ $Date: 2000/11/04 12:43:24
$
\n
"
);
}
}
/*
/*
...
...
src/backend/utils/init/miscinit.c
View file @
abfb4175
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.5
5 2000/09/19 18:17:57
petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.5
6 2000/11/04 12:43:24
petere Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -366,6 +366,62 @@ GetUserName(Oid userid)
...
@@ -366,6 +366,62 @@ GetUserName(Oid userid)
/*-------------------------------------------------------------------------
* Set data directory, but make sure it's an absolute path. Use this,
* never set DataDir directly.
*-------------------------------------------------------------------------
*/
void
SetDataDir
(
const
char
*
dir
)
{
char
*
new
;
AssertArg
(
dir
);
if
(
DataDir
)
free
(
DataDir
);
if
(
dir
[
0
]
!=
'/'
)
{
char
*
buf
;
size_t
buflen
;
buflen
=
MAXPGPATH
;
for
(;;)
{
buf
=
malloc
(
buflen
);
if
(
!
buf
)
elog
(
FATAL
,
"out of memory"
);
if
(
getcwd
(
buf
,
buflen
))
break
;
else
if
(
errno
==
ERANGE
)
{
free
(
buf
);
buflen
*=
2
;
continue
;
}
else
{
free
(
buf
);
elog
(
FATAL
,
"cannot get current working directory: %m"
);
}
}
new
=
malloc
(
strlen
(
buf
)
+
1
+
strlen
(
dir
)
+
1
);
sprintf
(
new
,
"%s/%s"
,
buf
,
dir
);
}
else
{
new
=
strdup
(
dir
);
}
if
(
!
new
)
elog
(
FATAL
,
"out of memory"
);
DataDir
=
new
;
}
/*-------------------------------------------------------------------------
/*-------------------------------------------------------------------------
*
*
* postmaster pid file stuffs. $DATADIR/postmaster.pid is created when:
* postmaster pid file stuffs. $DATADIR/postmaster.pid is created when:
...
...
src/include/miscadmin.h
View file @
abfb4175
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: miscadmin.h,v 1.6
8 2000/10/08 09:25:38 ishii
Exp $
* $Id: miscadmin.h,v 1.6
9 2000/11/04 12:43:24 petere
Exp $
*
*
* NOTES
* NOTES
* some of the information in this file will be moved to
* some of the information in this file will be moved to
...
@@ -137,6 +137,8 @@ extern Oid GetSessionUserId(void);
...
@@ -137,6 +137,8 @@ extern Oid GetSessionUserId(void);
extern
void
SetSessionUserId
(
Oid
userid
);
extern
void
SetSessionUserId
(
Oid
userid
);
extern
void
SetSessionUserIdFromUserName
(
const
char
*
username
);
extern
void
SetSessionUserIdFromUserName
(
const
char
*
username
);
extern
void
SetDataDir
(
const
char
*
dir
);
extern
int
FindExec
(
char
*
full_path
,
const
char
*
argv0
,
const
char
*
binary_name
);
extern
int
FindExec
(
char
*
full_path
,
const
char
*
argv0
,
const
char
*
binary_name
);
extern
int
CheckPathAccess
(
char
*
path
,
char
*
name
,
int
open_mode
);
extern
int
CheckPathAccess
(
char
*
path
,
char
*
name
,
int
open_mode
);
...
...
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