Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
567bf445
Commit
567bf445
authored
Aug 15, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unix/Daemon: move code to ReadPidFile()
parent
28a0c46c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
12 deletions
+18
-12
Daemon.cxx
src/unix/Daemon.cxx
+2
-12
PidFile.hxx
src/unix/PidFile.hxx
+16
-0
No files found.
src/unix/Daemon.cxx
View file @
567bf445
...
@@ -65,25 +65,15 @@ static int detach_fd = -1;
...
@@ -65,25 +65,15 @@ static int detach_fd = -1;
void
void
daemonize_kill
(
void
)
daemonize_kill
(
void
)
{
{
FILE
*
fp
;
int
pid
;
if
(
pidfile
.
IsNull
())
if
(
pidfile
.
IsNull
())
FatalError
(
"no pid_file specified in the config file"
);
FatalError
(
"no pid_file specified in the config file"
);
fp
=
FOpen
(
pidfile
,
PATH_LITERAL
(
"r"
));
const
pid_t
pid
=
ReadPidFile
(
pidfile
);
if
(
fp
==
nullptr
)
{
if
(
pid
<
0
)
{
const
std
::
string
utf8
=
pidfile
.
ToUTF8
();
FormatFatalSystemError
(
"Unable to open pid file
\"
%s
\"
"
,
utf8
.
c_str
());
}
if
(
fscanf
(
fp
,
"%i"
,
&
pid
)
!=
1
)
{
const
std
::
string
utf8
=
pidfile
.
ToUTF8
();
const
std
::
string
utf8
=
pidfile
.
ToUTF8
();
FormatFatalError
(
"unable to read the pid from file
\"
%s
\"
"
,
FormatFatalError
(
"unable to read the pid from file
\"
%s
\"
"
,
utf8
.
c_str
());
utf8
.
c_str
());
}
}
fclose
(
fp
);
if
(
kill
(
pid
,
SIGTERM
)
<
0
)
if
(
kill
(
pid
,
SIGTERM
)
<
0
)
FormatFatalSystemError
(
"unable to kill process %i"
,
FormatFatalSystemError
(
"unable to kill process %i"
,
...
...
src/unix/PidFile.hxx
View file @
567bf445
...
@@ -82,4 +82,20 @@ public:
...
@@ -82,4 +82,20 @@ public:
}
}
};
};
gcc_pure
static
inline
pid_t
ReadPidFile
(
Path
path
)
{
FILE
*
fp
=
FOpen
(
path
,
PATH_LITERAL
(
"r"
));
if
(
fp
==
nullptr
)
return
-
1
;
int
pid
;
if
(
fscanf
(
fp
,
"%i"
,
&
pid
)
!=
1
)
pid
=
-
1
;
fclose
(
fp
);
return
pid
;
}
#endif
#endif
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