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
b42a8d23
Commit
b42a8d23
authored
Sep 09, 2011
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: parsePath() returns GError on failure
Better error messages.
parent
61fc01e7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
14 deletions
+30
-14
conf.c
src/conf.c
+4
-4
fifo_output_plugin.c
src/output/fifo_output_plugin.c
+3
-3
utils.c
src/utils.c
+21
-6
utils.h
src/utils.h
+2
-1
No files found.
src/conf.c
View file @
b42a8d23
...
@@ -513,11 +513,11 @@ config_dup_path(const char *name, GError **error_r)
...
@@ -513,11 +513,11 @@ config_dup_path(const char *name, GError **error_r)
if
(
param
==
NULL
)
if
(
param
==
NULL
)
return
NULL
;
return
NULL
;
char
*
path
=
parsePath
(
param
->
value
);
char
*
path
=
parsePath
(
param
->
value
,
error_r
);
if
(
G_UNLIKELY
(
path
==
NULL
))
if
(
G_UNLIKELY
(
path
==
NULL
))
g_
set_error
(
error_r
,
config_quark
(),
0
,
g_
prefix_error
(
error_r
,
"Invalid path in
\"
%s
\"
at line %i
"
,
"Invalid path in
\"
%s
\"
at line %i:
"
,
name
,
param
->
line
);
name
,
param
->
line
);
return
path
;
return
path
;
}
}
...
...
src/output/fifo_output_plugin.c
View file @
b42a8d23
...
@@ -190,11 +190,11 @@ fifo_output_init(G_GNUC_UNUSED const struct audio_format *audio_format,
...
@@ -190,11 +190,11 @@ fifo_output_init(G_GNUC_UNUSED const struct audio_format *audio_format,
return
NULL
;
return
NULL
;
}
}
path
=
parsePath
(
value
);
path
=
parsePath
(
value
,
error
);
g_free
(
value
);
g_free
(
value
);
if
(
!
path
)
{
if
(
!
path
)
{
g_
set_error
(
error
,
fifo_output_quark
(),
errno
,
g_
prefix_error
(
error
,
"Invalid path in line %i: "
,
"Could not parse
\"
path
\"
parameter"
);
param
->
line
);
return
NULL
;
return
NULL
;
}
}
...
...
src/utils.c
View file @
b42a8d23
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include "config.h"
#include "config.h"
#include "utils.h"
#include "utils.h"
#include "glib_compat.h"
#include "conf.h"
#include "conf.h"
#include <glib.h>
#include <glib.h>
...
@@ -41,12 +42,23 @@
...
@@ -41,12 +42,23 @@
#include <windows.h>
#include <windows.h>
#endif
#endif
G_GNUC_CONST
static
inline
GQuark
parse_path_quark
(
void
)
{
return
g_quark_from_static_string
(
"path"
);
}
char
*
char
*
parsePath
(
const
char
*
path
)
parsePath
(
const
char
*
path
,
G_GNUC_UNUSED
GError
**
error_r
)
{
{
assert
(
path
!=
NULL
);
assert
(
error_r
==
NULL
||
*
error_r
==
NULL
);
#ifndef WIN32
#ifndef WIN32
if
(
!
g_path_is_absolute
(
path
)
&&
path
[
0
]
!=
'~'
)
{
if
(
!
g_path_is_absolute
(
path
)
&&
path
[
0
]
!=
'~'
)
{
g_warning
(
"
\"
%s
\"
is not an absolute path"
,
path
);
g_set_error
(
error_r
,
parse_path_quark
(),
0
,
"not an absolute path: %s"
,
path
);
return
NULL
;
return
NULL
;
}
else
if
(
path
[
0
]
==
'~'
)
{
}
else
if
(
path
[
0
]
==
'~'
)
{
const
char
*
home
;
const
char
*
home
;
...
@@ -56,7 +68,8 @@ parsePath(const char *path)
...
@@ -56,7 +68,8 @@ parsePath(const char *path)
if
(
user
!=
NULL
)
{
if
(
user
!=
NULL
)
{
struct
passwd
*
passwd
=
getpwnam
(
user
);
struct
passwd
*
passwd
=
getpwnam
(
user
);
if
(
!
passwd
)
{
if
(
!
passwd
)
{
g_warning
(
"no such user %s"
,
user
);
g_set_error
(
error_r
,
parse_path_quark
(),
0
,
"no such user: %s"
,
user
);
return
NULL
;
return
NULL
;
}
}
...
@@ -64,8 +77,9 @@ parsePath(const char *path)
...
@@ -64,8 +77,9 @@ parsePath(const char *path)
}
else
{
}
else
{
home
=
g_get_home_dir
();
home
=
g_get_home_dir
();
if
(
home
==
NULL
)
{
if
(
home
==
NULL
)
{
g_warning
(
"problems getting home "
g_set_error_literal
(
error_r
,
parse_path_quark
(),
0
,
"for current user"
);
"problems getting home "
"for current user"
);
return
NULL
;
return
NULL
;
}
}
}
}
...
@@ -81,7 +95,8 @@ parsePath(const char *path)
...
@@ -81,7 +95,8 @@ parsePath(const char *path)
struct
passwd
*
passwd
=
getpwnam
(
user
);
struct
passwd
*
passwd
=
getpwnam
(
user
);
if
(
!
passwd
)
{
if
(
!
passwd
)
{
g_warning
(
"user
\"
%s
\"
not found"
,
user
);
g_set_error
(
error_r
,
parse_path_quark
(),
0
,
"no such user: %s"
,
user
);
g_free
(
user
);
g_free
(
user
);
return
NULL
;
return
NULL
;
}
}
...
...
src/utils.h
View file @
b42a8d23
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#ifndef MPD_UTILS_H
#ifndef MPD_UTILS_H
#define MPD_UTILS_H
#define MPD_UTILS_H
#include <glib.h>
#include <stdbool.h>
#include <stdbool.h>
#ifndef assert_static
#ifndef assert_static
...
@@ -32,6 +33,6 @@
...
@@ -32,6 +33,6 @@
#endif
/* !assert_static */
#endif
/* !assert_static */
char
*
char
*
parsePath
(
const
char
*
path
);
parsePath
(
const
char
*
path
,
GError
**
error_r
);
#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