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
4b00c625
Commit
4b00c625
authored
Nov 18, 2005
by
Qball Cow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DJWLindenaar's fix race condition and some memory leaks patch
git-svn-id:
https://svn.musicpd.org/mpd/trunk@3681
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
32e5f4ca
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
5 deletions
+41
-5
command.h
src/command.h
+1
-0
conf.c
src/conf.c
+5
-0
conf.h
src/conf.h
+1
-0
main.c
src/main.c
+15
-5
myfprintf.c
src/myfprintf.c
+7
-0
myfprintf.h
src/myfprintf.h
+1
-0
sig_handlers.c
src/sig_handlers.c
+11
-0
No files found.
src/command.h
View file @
4b00c625
...
...
@@ -30,6 +30,7 @@
#define COMMAND_RETURN_KILL 10
#define COMMAND_RETURN_CLOSE 20
#define COMMAND_MASTER_READY 30
extern
char
*
current_command
;
extern
int
command_listNum
;
...
...
src/conf.c
View file @
4b00c625
...
...
@@ -112,6 +112,10 @@ void registerConfigParam(char * name, int repeatable, int block) {
insertInList
(
configEntriesList
,
name
,
entry
);
}
void
finishConf
()
{
freeList
(
configEntriesList
);
}
void
initConf
()
{
configEntriesList
=
makeList
((
ListFreeDataFunc
*
)
freeConfigEntry
,
1
);
...
...
@@ -295,6 +299,7 @@ void readConf(char * file) {
freeArgArray
(
array
,
numberOfArgs
);
}
fclose
(
fp
);
}
ConfigParam
*
getNextConfigParam
(
char
*
name
,
ConfigParam
*
last
)
{
...
...
src/conf.h
View file @
4b00c625
...
...
@@ -73,6 +73,7 @@ typedef struct _ConfigParam {
}
ConfigParam
;
void
initConf
();
void
finishConf
();
void
readConf
(
char
*
file
);
...
...
src/main.c
View file @
4b00c625
...
...
@@ -42,6 +42,7 @@
#include <stdio.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
...
...
@@ -306,6 +307,7 @@ void startMainProcess() {
mainPid
=
pid
;
masterInitSigHandlers
();
kill
(
mainPid
,
SIGUSR1
);
while
(
masterHandlePendingSignals
()
!=
COMMAND_RETURN_KILL
)
waitOnSignals
();
/* we're killed */
...
...
@@ -320,6 +322,9 @@ void startMainProcess() {
finishPaths
();
kill
(
mainPid
,
SIGTERM
);
waitpid
(
mainPid
,
NULL
,
0
);
finishConf
();
myfprintfCloseLogFile
();
exit
(
EXIT_SUCCESS
);
}
else
if
(
pid
<
0
)
{
...
...
@@ -483,8 +488,8 @@ void killFromPidFile(char * cmd, int killOption) {
}
int
main
(
int
argc
,
char
*
argv
[])
{
FILE
*
out
;
FILE
*
err
;
FILE
*
out
=
NULL
;
FILE
*
err
=
NULL
;
Options
options
;
closeAllFDs
();
...
...
@@ -519,8 +524,7 @@ int main(int argc, char * argv[]) {
/* This is the main process which has
* been forked from the master process.
*/
initSigHandlers
();
initPermissions
();
...
...
@@ -539,8 +543,12 @@ int main(int argc, char * argv[]) {
setupLogOutput
(
&
options
,
out
,
err
);
/* wait for the master process to get ready so we can start
* playing if readPlaylistState thinks we should*/
while
(
COMMAND_MASTER_READY
!=
handlePendingSignals
())
my_usleep
(
1
);
openVolumeDevice
();
initSigHandlers
();
readPlaylistState
();
...
...
@@ -567,6 +575,8 @@ int main(int argc, char * argv[]) {
finishCommands
();
finishInputPlugins
();
cleanUpPidFile
();
finishConf
();
myfprintfCloseLogFile
();
return
EXIT_SUCCESS
;
}
src/myfprintf.c
View file @
4b00c625
...
...
@@ -122,3 +122,10 @@ int myfprintfCloseAndOpenLogFile() {
return
0
;
}
void
myfprintfCloseLogFile
()
{
if
(
myfprintf_stdLogMode
)
{
while
(
fclose
(
myfprintf_out
)
<
0
&&
errno
==
EINTR
);
while
(
fclose
(
myfprintf_err
)
<
0
&&
errno
==
EINTR
);
}
}
src/myfprintf.h
View file @
4b00c625
...
...
@@ -29,4 +29,5 @@ void myfprintf(FILE * fp, char * format, ... );
int
myfprintfCloseAndOpenLogFile
();
void
myfprintfCloseLogFile
();
#endif
src/sig_handlers.c
View file @
4b00c625
...
...
@@ -56,6 +56,16 @@ int masterHandlePendingSignals() {
}
int
handlePendingSignals
()
{
/* this SIGUSR1 signal comes before the KILL signals, because there if the process is
* looping, waiting for this signal, it will not respond to the KILL signal. This might be
* better implemented by using bit-wise defines and or'ing of the COMMAND_FOO as return.
*/
if
(
signal_is_pending
(
SIGUSR1
))
{
signal_clear
(
SIGUSR1
);
DEBUG
(
"The master process is ready to receive signals
\n
"
);
return
COMMAND_MASTER_READY
;
}
if
(
signal_is_pending
(
SIGINT
)
||
signal_is_pending
(
SIGTERM
))
{
DEBUG
(
"main process got SIGINT or SIGTERM, exiting
\n
"
);
return
COMMAND_RETURN_KILL
;
...
...
@@ -135,6 +145,7 @@ void initSigHandlers() {
while
(
sigaction
(
SIGPIPE
,
&
sa
,
NULL
)
<
0
&&
errno
==
EINTR
);
sa
.
sa_handler
=
chldSigHandler
;
while
(
sigaction
(
SIGCHLD
,
&
sa
,
NULL
)
<
0
&&
errno
==
EINTR
);
signal_handle
(
SIGUSR2
);
signal_handle
(
SIGUSR1
);
signal_handle
(
SIGINT
);
signal_handle
(
SIGTERM
);
...
...
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