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
c7516384
Commit
c7516384
authored
Apr 06, 2011
by
Peter Eisentraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace the confusing exit_nicely() by an atexit/on_exit hook
parent
2bd78eb8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
43 deletions
+37
-43
contrib/pg_upgrade/check.c
contrib/pg_upgrade/check.c
+1
-1
contrib/pg_upgrade/option.c
contrib/pg_upgrade/option.c
+5
-5
contrib/pg_upgrade/pg_upgrade.h
contrib/pg_upgrade/pg_upgrade.h
+0
-1
contrib/pg_upgrade/server.c
contrib/pg_upgrade/server.c
+29
-5
contrib/pg_upgrade/util.c
contrib/pg_upgrade/util.c
+2
-31
No files found.
contrib/pg_upgrade/check.c
View file @
c7516384
...
@@ -131,7 +131,7 @@ report_clusters_compatible(void)
...
@@ -131,7 +131,7 @@ report_clusters_compatible(void)
pg_log
(
PG_REPORT
,
"
\n
*Clusters are compatible*
\n
"
);
pg_log
(
PG_REPORT
,
"
\n
*Clusters are compatible*
\n
"
);
/* stops new cluster */
/* stops new cluster */
stop_postmaster
(
false
,
false
);
stop_postmaster
(
false
,
false
);
exit
_nicely
(
false
);
exit
(
0
);
}
}
pg_log
(
PG_REPORT
,
"
\n
"
pg_log
(
PG_REPORT
,
"
\n
"
...
...
contrib/pg_upgrade/option.c
View file @
c7516384
...
@@ -77,12 +77,12 @@ parseCommandLine(int argc, char *argv[])
...
@@ -77,12 +77,12 @@ parseCommandLine(int argc, char *argv[])
strcmp
(
argv
[
1
],
"-?"
)
==
0
)
strcmp
(
argv
[
1
],
"-?"
)
==
0
)
{
{
usage
();
usage
();
exit
_nicely
(
false
);
exit
(
0
);
}
}
if
(
strcmp
(
argv
[
1
],
"--version"
)
==
0
||
strcmp
(
argv
[
1
],
"-V"
)
==
0
)
if
(
strcmp
(
argv
[
1
],
"--version"
)
==
0
||
strcmp
(
argv
[
1
],
"-V"
)
==
0
)
{
{
pg_log
(
PG_REPORT
,
"pg_upgrade "
PG_VERSION
"
\n
"
);
pg_log
(
PG_REPORT
,
"pg_upgrade "
PG_VERSION
"
\n
"
);
exit
_nicely
(
false
);
exit
(
0
);
}
}
}
}
...
@@ -125,7 +125,7 @@ parseCommandLine(int argc, char *argv[])
...
@@ -125,7 +125,7 @@ parseCommandLine(int argc, char *argv[])
if
((
log_opts
.
debug_fd
=
fopen
(
optarg
,
"w"
))
==
NULL
)
if
((
log_opts
.
debug_fd
=
fopen
(
optarg
,
"w"
))
==
NULL
)
{
{
pg_log
(
PG_FATAL
,
"cannot open debug file
\n
"
);
pg_log
(
PG_FATAL
,
"cannot open debug file
\n
"
);
exit
_nicely
(
false
);
exit
(
1
);
}
}
break
;
break
;
...
@@ -141,7 +141,7 @@ parseCommandLine(int argc, char *argv[])
...
@@ -141,7 +141,7 @@ parseCommandLine(int argc, char *argv[])
if
((
old_cluster
.
port
=
atoi
(
optarg
))
<=
0
)
if
((
old_cluster
.
port
=
atoi
(
optarg
))
<=
0
)
{
{
pg_log
(
PG_FATAL
,
"invalid old port number
\n
"
);
pg_log
(
PG_FATAL
,
"invalid old port number
\n
"
);
exit
_nicely
(
false
);
exit
(
1
);
}
}
break
;
break
;
...
@@ -149,7 +149,7 @@ parseCommandLine(int argc, char *argv[])
...
@@ -149,7 +149,7 @@ parseCommandLine(int argc, char *argv[])
if
((
new_cluster
.
port
=
atoi
(
optarg
))
<=
0
)
if
((
new_cluster
.
port
=
atoi
(
optarg
))
<=
0
)
{
{
pg_log
(
PG_FATAL
,
"invalid new port number
\n
"
);
pg_log
(
PG_FATAL
,
"invalid new port number
\n
"
);
exit
_nicely
(
false
);
exit
(
1
);
}
}
break
;
break
;
...
...
contrib/pg_upgrade/pg_upgrade.h
View file @
c7516384
...
@@ -363,7 +363,6 @@ void check_for_libpq_envvars(void);
...
@@ -363,7 +363,6 @@ void check_for_libpq_envvars(void);
/* util.c */
/* util.c */
void
exit_nicely
(
bool
need_cleanup
);
char
*
quote_identifier
(
const
char
*
s
);
char
*
quote_identifier
(
const
char
*
s
);
int
get_user_info
(
char
**
user_name
);
int
get_user_info
(
char
**
user_name
);
void
check_ok
(
void
);
void
check_ok
(
void
);
...
...
contrib/pg_upgrade/server.c
View file @
c7516384
...
@@ -23,7 +23,7 @@ static bool test_server_conn(ClusterInfo *cluster, int timeout);
...
@@ -23,7 +23,7 @@ static bool test_server_conn(ClusterInfo *cluster, int timeout);
*
*
* Connects to the desired database on the designated server.
* Connects to the desired database on the designated server.
* If the connection attempt fails, this function logs an error
* If the connection attempt fails, this function logs an error
* message and calls exit
_nicely
() to kill the program.
* message and calls exit() to kill the program.
*/
*/
PGconn
*
PGconn
*
connectToServer
(
ClusterInfo
*
cluster
,
const
char
*
db_name
)
connectToServer
(
ClusterInfo
*
cluster
,
const
char
*
db_name
)
...
@@ -45,7 +45,8 @@ connectToServer(ClusterInfo *cluster, const char *db_name)
...
@@ -45,7 +45,8 @@ connectToServer(ClusterInfo *cluster, const char *db_name)
if
(
conn
)
if
(
conn
)
PQfinish
(
conn
);
PQfinish
(
conn
);
exit_nicely
(
true
);
printf
(
"Failure, exiting
\n
"
);
exit
(
1
);
}
}
return
conn
;
return
conn
;
...
@@ -57,7 +58,7 @@ connectToServer(ClusterInfo *cluster, const char *db_name)
...
@@ -57,7 +58,7 @@ connectToServer(ClusterInfo *cluster, const char *db_name)
*
*
* Formats a query string from the given arguments and executes the
* Formats a query string from the given arguments and executes the
* resulting query. If the query fails, this function logs an error
* resulting query. If the query fails, this function logs an error
* message and calls exit
_nicely
() to kill the program.
* message and calls exit() to kill the program.
*/
*/
PGresult
*
PGresult
*
executeQueryOrDie
(
PGconn
*
conn
,
const
char
*
fmt
,...)
executeQueryOrDie
(
PGconn
*
conn
,
const
char
*
fmt
,...)
...
@@ -81,8 +82,8 @@ executeQueryOrDie(PGconn *conn, const char *fmt,...)
...
@@ -81,8 +82,8 @@ executeQueryOrDie(PGconn *conn, const char *fmt,...)
PQerrorMessage
(
conn
));
PQerrorMessage
(
conn
));
PQclear
(
result
);
PQclear
(
result
);
PQfinish
(
conn
);
PQfinish
(
conn
);
exit_nicely
(
true
);
printf
(
"Failure, exiting
\n
"
);
return
NULL
;
/* Never get here, but keeps compiler happy */
exit
(
1
);
}
}
else
else
return
result
;
return
result
;
...
@@ -152,6 +153,18 @@ get_major_server_version(ClusterInfo *cluster)
...
@@ -152,6 +153,18 @@ get_major_server_version(ClusterInfo *cluster)
}
}
static
void
#ifdef HAVE_ATEXIT
stop_postmaster_atexit
(
void
)
#else
stop_postmaster_on_exit
(
int
exitstatus
,
void
*
arg
)
#endif
{
stop_postmaster
(
true
,
true
);
}
void
void
start_postmaster
(
ClusterInfo
*
cluster
,
bool
quiet
)
start_postmaster
(
ClusterInfo
*
cluster
,
bool
quiet
)
{
{
...
@@ -159,11 +172,22 @@ start_postmaster(ClusterInfo *cluster, bool quiet)
...
@@ -159,11 +172,22 @@ start_postmaster(ClusterInfo *cluster, bool quiet)
const
char
*
bindir
;
const
char
*
bindir
;
const
char
*
datadir
;
const
char
*
datadir
;
unsigned
short
port
;
unsigned
short
port
;
bool
exit_hook_registered
=
false
;
bindir
=
cluster
->
bindir
;
bindir
=
cluster
->
bindir
;
datadir
=
cluster
->
pgdata
;
datadir
=
cluster
->
pgdata
;
port
=
cluster
->
port
;
port
=
cluster
->
port
;
if
(
!
exit_hook_registered
)
{
#ifdef HAVE_ATEXIT
atexit
(
stop_postmaster_atexit
);
#else
on_exit
(
stop_postmaster_on_exit
);
#endif
exit_hook_registered
=
true
;
}
/*
/*
* On Win32, we can't send both pg_upgrade output and pg_ctl output to the
* On Win32, we can't send both pg_upgrade output and pg_ctl output to the
* same file because we get the error: "The process cannot access the file
* same file because we get the error: "The process cannot access the file
...
...
contrib/pg_upgrade/util.c
View file @
c7516384
...
@@ -99,7 +99,8 @@ pg_log(eLogType type, char *fmt,...)
...
@@ -99,7 +99,8 @@ pg_log(eLogType type, char *fmt,...)
case
PG_FATAL
:
case
PG_FATAL
:
printf
(
"%s"
,
"
\n
"
);
printf
(
"%s"
,
"
\n
"
);
printf
(
"%s"
,
_
(
message
));
printf
(
"%s"
,
_
(
message
));
exit_nicely
(
true
);
printf
(
"Failure, exiting
\n
"
);
exit
(
1
);
break
;
break
;
case
PG_DEBUG
:
case
PG_DEBUG
:
...
@@ -184,36 +185,6 @@ get_user_info(char **user_name)
...
@@ -184,36 +185,6 @@ get_user_info(char **user_name)
}
}
void
exit_nicely
(
bool
need_cleanup
)
{
stop_postmaster
(
true
,
true
);
pg_free
(
log_opts
.
filename
);
if
(
log_opts
.
fd
)
fclose
(
log_opts
.
fd
);
if
(
log_opts
.
debug_fd
)
fclose
(
log_opts
.
debug_fd
);
/* terminate any running instance of postmaster */
if
(
os_info
.
postmasterPID
!=
0
)
kill
(
os_info
.
postmasterPID
,
SIGTERM
);
if
(
need_cleanup
)
{
printf
(
"Failure, exiting
\n
"
);
/*
* FIXME must delete intermediate files
*/
exit
(
1
);
}
else
exit
(
0
);
}
void
*
void
*
pg_malloc
(
int
n
)
pg_malloc
(
int
n
)
{
{
...
...
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