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
dcff29e5
Commit
dcff29e5
authored
Jan 03, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
state_file: errors are non-fatal in read_state_file()
If the state file cannot be read, for whatever reason, don't abort MPD. The state file isn't _that_ important.
parent
2064e8ac
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
28 deletions
+23
-28
NEWS
NEWS
+1
-0
playlist.c
src/playlist.c
+20
-12
state_file.c
src/state_file.c
+2
-15
state_file.h
src/state_file.h
+0
-1
No files found.
NEWS
View file @
dcff29e5
...
@@ -9,6 +9,7 @@ ver 0.15 - (200?/??/??)
...
@@ -9,6 +9,7 @@ ver 0.15 - (200?/??/??)
"log_file"
"log_file"
* support logging to syslog
* support logging to syslog
* fall back to XDG music directory if no music_directory is configured
* fall back to XDG music directory if no music_directory is configured
* failure to read the state file is non-fatal
ver 0.14 (2008/12/25)
ver 0.14 (2008/12/25)
* audio outputs:
* audio outputs:
...
...
src/playlist.c
View file @
dcff29e5
...
@@ -30,7 +30,6 @@
...
@@ -30,7 +30,6 @@
#include "log.h"
#include "log.h"
#include "mapper.h"
#include "mapper.h"
#include "path.h"
#include "path.h"
#include "state_file.h"
#include "stored_playlist.h"
#include "stored_playlist.h"
#include "ack.h"
#include "ack.h"
#include "idle.h"
#include "idle.h"
...
@@ -279,17 +278,26 @@ static void loadPlaylistFromStateFile(FILE *fp, char *buffer,
...
@@ -279,17 +278,26 @@ static void loadPlaylistFromStateFile(FILE *fp, char *buffer,
char
*
temp
;
char
*
temp
;
int
song
;
int
song
;
if
(
!
fgets
(
buffer
,
PLAYLIST_BUFFER_SIZE
,
fp
))
if
(
!
fgets
(
buffer
,
PLAYLIST_BUFFER_SIZE
,
fp
))
{
state_file_fatal
();
g_warning
(
"No playlist in state file"
);
return
;
}
while
(
!
g_str_has_prefix
(
buffer
,
PLAYLIST_STATE_FILE_PLAYLIST_END
))
{
while
(
!
g_str_has_prefix
(
buffer
,
PLAYLIST_STATE_FILE_PLAYLIST_END
))
{
g_strchomp
(
buffer
);
g_strchomp
(
buffer
);
temp
=
strtok
(
buffer
,
":"
);
temp
=
strtok
(
buffer
,
":"
);
if
(
temp
==
NULL
)
if
(
temp
==
NULL
)
{
state_file_fatal
();
g_warning
(
"Malformed playlist line in state file"
);
break
;
}
song
=
atoi
(
temp
);
song
=
atoi
(
temp
);
if
(
!
(
temp
=
strtok
(
NULL
,
""
)))
if
(
!
(
temp
=
strtok
(
NULL
,
""
)))
{
state_file_fatal
();
g_warning
(
"Malformed playlist line in state file"
);
break
;
}
if
(
addToPlaylist
(
temp
,
NULL
)
==
PLAYLIST_RESULT_SUCCESS
if
(
addToPlaylist
(
temp
,
NULL
)
==
PLAYLIST_RESULT_SUCCESS
&&
current
==
song
)
{
&&
current
==
song
)
{
if
(
state
!=
PLAYER_STATE_STOP
)
{
if
(
state
!=
PLAYER_STATE_STOP
)
{
...
@@ -304,8 +312,11 @@ static void loadPlaylistFromStateFile(FILE *fp, char *buffer,
...
@@ -304,8 +312,11 @@ static void loadPlaylistFromStateFile(FILE *fp, char *buffer,
}
}
}
}
if
(
!
fgets
(
buffer
,
PLAYLIST_BUFFER_SIZE
,
fp
))
if
(
!
fgets
(
buffer
,
PLAYLIST_BUFFER_SIZE
,
fp
))
{
state_file_fatal
();
g_warning
(
"'%s' not found in state file"
,
PLAYLIST_STATE_FILE_PLAYLIST_END
);
break
;
}
}
}
}
}
...
@@ -357,9 +368,6 @@ void readPlaylistState(FILE *fp)
...
@@ -357,9 +368,6 @@ void readPlaylistState(FILE *fp)
}
else
}
else
setPlaylistRandomStatus
(
false
);
setPlaylistRandomStatus
(
false
);
}
else
if
(
g_str_has_prefix
(
buffer
,
PLAYLIST_STATE_FILE_CURRENT
))
{
}
else
if
(
g_str_has_prefix
(
buffer
,
PLAYLIST_STATE_FILE_CURRENT
))
{
if
(
strlen
(
buffer
)
==
strlen
(
PLAYLIST_STATE_FILE_CURRENT
))
state_file_fatal
();
current
=
atoi
(
&
(
buffer
current
=
atoi
(
&
(
buffer
[
strlen
[
strlen
(
PLAYLIST_STATE_FILE_CURRENT
)]));
(
PLAYLIST_STATE_FILE_CURRENT
)]));
...
...
src/state_file.c
View file @
dcff29e5
...
@@ -26,7 +26,6 @@
...
@@ -26,7 +26,6 @@
#include <glib.h>
#include <glib.h>
#include <string.h>
#include <string.h>
#include <sys/stat.h>
#undef G_LOG_DOMAIN
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "state_file"
#define G_LOG_DOMAIN "state_file"
...
@@ -74,24 +73,18 @@ void write_state_file(void)
...
@@ -74,24 +73,18 @@ void write_state_file(void)
void
read_state_file
(
void
)
void
read_state_file
(
void
)
{
{
struct
stat
st
;
unsigned
int
i
;
unsigned
int
i
;
FILE
*
fp
;
FILE
*
fp
;
get_state_file_path
();
get_state_file_path
();
if
(
!
sfpath
)
if
(
!
sfpath
)
return
;
return
;
if
(
stat
(
sfpath
,
&
st
)
<
0
)
{
g_debug
(
"failed to stat %s: %s"
,
sfpath
,
strerror
(
errno
));
return
;
}
if
(
!
S_ISREG
(
st
.
st_mode
))
g_error
(
"
\"
%s
\"
is not a regular file"
,
sfpath
);
while
(
!
(
fp
=
fopen
(
sfpath
,
"r"
))
&&
errno
==
EINTR
);
while
(
!
(
fp
=
fopen
(
sfpath
,
"r"
))
&&
errno
==
EINTR
);
if
(
G_UNLIKELY
(
!
fp
))
{
if
(
G_UNLIKELY
(
!
fp
))
{
g_
error
(
"failed to open %s: %s"
,
g_
warning
(
"failed to open %s: %s"
,
sfpath
,
strerror
(
errno
));
sfpath
,
strerror
(
errno
));
return
;
}
}
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
sf_callbacks
);
i
++
)
{
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
sf_callbacks
);
i
++
)
{
sf_callbacks
[
i
].
reader
(
fp
);
sf_callbacks
[
i
].
reader
(
fp
);
...
@@ -100,9 +93,3 @@ void read_state_file(void)
...
@@ -100,9 +93,3 @@ void read_state_file(void)
while
(
fclose
(
fp
)
&&
errno
==
EINTR
)
/* nothing */
;
while
(
fclose
(
fp
)
&&
errno
==
EINTR
)
/* nothing */
;
}
}
void
G_GNUC_NORETURN
state_file_fatal
(
void
)
{
g_error
(
"failed to parse %s"
,
sfpath
);
}
src/state_file.h
View file @
dcff29e5
...
@@ -23,6 +23,5 @@
...
@@ -23,6 +23,5 @@
void
write_state_file
(
void
);
void
write_state_file
(
void
);
void
read_state_file
(
void
);
void
read_state_file
(
void
);
void
G_GNUC_NORETURN
state_file_fatal
(
void
);
#endif
/* STATE_FILE_H */
#endif
/* STATE_FILE_H */
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