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
d9f61cfa
Commit
d9f61cfa
authored
Dec 04, 1999
by
Tatsuo Ishii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unlink the pid file if it's bogus (no associated process exists)
parent
e958a305
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
113 additions
and
22 deletions
+113
-22
src/backend/postmaster/postmaster.c
src/backend/postmaster/postmaster.c
+113
-22
No files found.
src/backend/postmaster/postmaster.c
View file @
d9f61cfa
...
...
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.12
8 1999/12/03 06:26:34
ishii Exp $
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.12
9 1999/12/04 08:23:43
ishii Exp $
*
* NOTES
*
...
...
@@ -257,7 +257,7 @@ extern int optind,
/*
* postmaster.c - function prototypes
*/
static
void
pmdaemonize
(
void
);
static
void
pmdaemonize
(
char
*
extraoptions
);
static
Port
*
ConnCreate
(
int
serverFd
);
static
void
ConnFree
(
Port
*
port
);
static
void
reset_shared
(
unsigned
short
port
);
...
...
@@ -645,13 +645,13 @@ PostmasterMain(int argc, char *argv[])
BackendList
=
DLNewList
();
PortList
=
DLNewList
();
if
(
silentflag
)
pmdaemonize
();
/*
* create pid file. if the file has already existed, exits.
*/
if
(
SetPidFile
(
if
(
silentflag
)
{
pmdaemonize
(
original_extraoptions
);
}
else
{
/*
* create pid file. if the file has already existed, exits.
*/
if
(
SetPidFile
(
getpid
(),
/* postmaster process id */
progname
,
/* postmaster executable file */
PostPortName
,
/* port number */
...
...
@@ -670,9 +670,10 @@ PostmasterMain(int argc, char *argv[])
SendStop
,
/* -s: send SIGSTOP */
original_extraoptions
/* options for backend */
)
)
{
ExitPostmaster
(
1
);
return
0
;
)
{
ExitPostmaster
(
1
);
return
0
;
/* not reached */
}
}
/*
...
...
@@ -703,12 +704,50 @@ PostmasterMain(int argc, char *argv[])
}
static
void
pmdaemonize
(
void
)
pmdaemonize
(
char
*
extraoptions
)
{
int
i
;
pid_t
pid
;
if
(
fork
())
pid
=
fork
();
if
(
pid
==
-
1
)
{
perror
(
"Failed to fork postmaster"
);
ExitPostmaster
(
1
);
return
;
/* not reached */
}
else
if
(
pid
)
{
/* parent */
/*
* create pid file. if the file has already existed, exits.
*/
if
(
SetPidFile
(
pid
,
/* postmaster process id */
progname
,
/* postmaster executable file */
PostPortName
,
/* port number */
DataDir
,
/* PGDATA */
assert_enabled
,
/* whether -A is specified or not */
NBuffers
,
/* -B: number of shared buffers */
Execfile
,
/* -b: postgres executable file */
DebugLvl
,
/* -d: debug level */
NetServer
,
/* -i: accept connection from INET */
#ifdef USE_SSL
SecureNetServer
,
/* -l: use SSL */
#endif
MaxBackends
,
/* -N: max number of backends */
Reinit
,
/* -n: reinit shared mem after failure */
1
,
/* -S: detach tty */
SendStop
,
/* -s: send SIGSTOP */
extraoptions
/* options for backend */
)
)
{
/*
* Failed to create pid file. kill the child and
* exit now.
*/
kill
(
pid
,
SIGTERM
);
ExitPostmaster
(
1
);
return
;
/* not reached */
}
_exit
(
0
);
}
/* GH: If there's no setsid(), we hopefully don't need silent mode.
* Until there's a better solution.
*/
...
...
@@ -2145,22 +2184,74 @@ static int SetPidFile(pid_t pid, char *progname, int port, char *datadir,
int
fd
;
char
optsfile
[
MAXPGPATH
];
char
pidstr
[
32
];
int
len
;
pid_t
post_pid
;
char
opts
[
1024
];
char
buf
[
1024
];
/*
* Creating pid file
*/
s
printf
(
PidFile
,
"%s/%s"
,
datadir
,
PIDFNAME
);
s
nprintf
(
PidFile
,
sizeof
(
PidFile
),
"%s/%s"
,
datadir
,
PIDFNAME
);
fd
=
open
(
PidFile
,
O_RDWR
|
O_CREAT
|
O_EXCL
,
0600
);
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"Can't create pidfile: %s
\n
"
,
PidFile
);
fprintf
(
stderr
,
"Is another postmaser running?
\n
"
);
return
(
-
1
);
/*
* Couldn't create the pid file. Probably
* it already exists. Read the file to see if the process
* actually exists
*/
fd
=
open
(
PidFile
,
O_RDONLY
,
0600
);
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"Can't create/read pid file: %s
\n
"
,
PidFile
);
fprintf
(
stderr
,
"Please check the permission and try again.
\n
"
);
return
(
-
1
);
}
if
((
len
=
read
(
fd
,
pidstr
,
sizeof
(
pidstr
)
-
1
))
<
0
)
{
fprintf
(
stderr
,
"Can't create/read pid file: %s
\n
"
,
PidFile
);
fprintf
(
stderr
,
"Please check the permission and try again.
\n
"
);
close
(
fd
);
return
(
-
1
);
}
close
(
fd
);
/*
* Check to see if the process actually exists
*/
pidstr
[
len
]
=
'\0'
;
post_pid
=
(
pid_t
)
atoi
(
pidstr
);
if
(
post_pid
==
0
||
(
post_pid
>
0
&&
kill
(
post_pid
,
0
)
<
0
))
{
/*
* No, the process did not exist. Unlink
* the file and try to create it
*/
if
(
unlink
(
PidFile
)
<
0
)
{
fprintf
(
stderr
,
"Can't remove pidfile: %s
\n
"
,
PidFile
);
fprintf
(
stderr
,
"The file seems accidently left, but I couldn't remove it.
\n
"
);
fprintf
(
stderr
,
"Please remove the file by hand and try again.
\n
"
);
return
(
-
1
);
}
fd
=
open
(
PidFile
,
O_RDWR
|
O_CREAT
|
O_EXCL
,
0600
);
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"Can't create pidfile: %s
\n
"
,
PidFile
);
fprintf
(
stderr
,
"Please check the permission and try again.
\n
"
);
return
(
-
1
);
}
}
else
{
/*
* Another postmaster is running
*/
fprintf
(
stderr
,
"Can't create pidfile: %s
\n
"
,
PidFile
);
fprintf
(
stderr
,
"Is another postmaser (pid: %s) running?
\n
"
,
pidstr
);
return
(
-
1
);
}
}
sprintf
(
pidstr
,
"%d"
,
pid
);
if
(
write
(
fd
,
pidstr
,
strlen
(
pidstr
))
!=
strlen
(
pidstr
))
{
fprintf
(
stderr
,
"Write to pid file failed
\n
"
);
fprintf
(
stderr
,
"Please check the permission and try again.
\n
"
);
close
(
fd
);
unlink
(
PidFile
);
return
(
-
1
);
...
...
@@ -2170,20 +2261,20 @@ static int SetPidFile(pid_t pid, char *progname, int port, char *datadir,
/*
* Creating opts file
*/
s
printf
(
optsfile
,
"%s/%s"
,
datadir
,
OPTSFNAME
);
s
nprintf
(
optsfile
,
sizeof
(
optsfile
),
"%s/%s"
,
datadir
,
OPTSFNAME
);
fd
=
open
(
optsfile
,
O_RDWR
|
O_TRUNC
|
O_CREAT
,
0600
);
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"Can't create optsfile:%s"
,
optsfile
);
unlink
(
PidFile
);
return
(
-
1
);
}
s
printf
(
opts
,
"%s
\n
-p %d
\n
-D %s
\n
"
,
progname
,
port
,
datadir
);
s
nprintf
(
opts
,
sizeof
(
opts
)
,
"%s
\n
-p %d
\n
-D %s
\n
"
,
progname
,
port
,
datadir
);
if
(
assert
)
{
sprintf
(
buf
,
"-A %d
\n
"
,
assert
);
strcat
(
opts
,
buf
);
}
s
printf
(
buf
,
"-B %d
\n
-b %s
\n
"
,
nbuf
,
execfile
);
s
nprintf
(
buf
,
sizeof
(
buf
)
,
"-B %d
\n
-b %s
\n
"
,
nbuf
,
execfile
);
strcat
(
opts
,
buf
);
if
(
debuglvl
)
{
...
...
@@ -2201,7 +2292,7 @@ static int SetPidFile(pid_t pid, char *progname, int port, char *datadir,
}
#endif
s
printf
(
buf
,
"-N %d
\n
"
,
maxbackends
);
s
nprintf
(
buf
,
sizeof
(
buf
)
,
"-N %d
\n
"
,
maxbackends
);
strcat
(
opts
,
buf
);
if
(
!
reinit
)
{
...
...
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