1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
From c5c6b5677854d2e835ed7d8d0497ab4f475c63fc Mon Sep 17 00:00:00 2001
From: Justin Bronder <jsbronder@gmail.com>
Date: Wed, 16 Sep 2009 11:50:20 -0400
Subject: [PATCH 2/3] mpd_conf_file search order.
Make sure the search order for mpd.conf is the following:
- MPD_CONF_FILE set in environment
- .mpd.conf in the user's home directory
- The system wide default in SYSCONFDIR/mpd.conf
---
src/pm/mpd/Makefile.in | 9 ++++++---
src/pm/mpd/mpdroot.c | 27 +++++++++++++++++++++++++--
2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/src/pm/mpd/Makefile.in b/src/pm/mpd/Makefile.in
index e1752f8..4ef65fc 100644
--- a/src/pm/mpd/Makefile.in
+++ b/src/pm/mpd/Makefile.in
@@ -74,7 +74,7 @@ mpdroot: ${mpdroot_OBJECTS}
$(C_LINK) -o mpdroot ${mpdroot_OBJECTS} $(LIBS)
mpdroot.o: ${srcdir}/mpdroot.c ${srcdir}/mpdroot.h mpdconf.h
- ${C_COMPILE} -c $<
+ ${C_COMPILE} -DSYSCONFDIR=\"@sysconfdir@\" -c $<
# The following lines provide the right libraries for all example programs
.c:
@@ -128,7 +128,10 @@ install: all
@echo "copying python files/links into " $(DESTDIR)${bindir}
-@for cmd in ${PYTHON_SOURCE} ; do \
if [ ! -s $(srcdir)/$$cmd.py ] ; then continue ; fi ; \
- sed -e 's#/usr/bin/env python.*#/usr/bin/env ${PYTHON}#' ${srcdir}/$$cmd.py > $(DESTDIR)${bindir}/temp$$cmd.py ; \
+ sed \
+ -e 's#/usr/bin/env python.*#/usr/bin/env ${PYTHON}#' \
+ -e 's,/etc/mpd.conf,@sysconfdir@/mpd.conf,g' \
+ ${srcdir}/$$cmd.py > $(DESTDIR)${bindir}/temp$$cmd.py ; \
${INSTALL} -m 755 $(DESTDIR)${bindir}/temp$$cmd.py $(DESTDIR)${bindir}/$$cmd.py; \
( rm -f $(DESTDIR)${bindir}/temp$$cmd.py >/dev/null 2>&1 || exit 0 ) ; \
done
@@ -210,7 +213,7 @@ mpich2-mpdroot: mpich2-mpdroot.o
mpich2-mpdroot.o: ${srcdir}/mpdroot.c ${srcdir}/mpdroot.h mpdconf.h
${INSTALL} -m 644 ${srcdir}/mpdroot.c mpich2-mpdroot.c
- ${C_COMPILE} -c mpich2-mpdroot.c
+ ${C_COMPILE} -DSYSCONFDIR=\"@sysconfdir@\" -c mpich2-mpdroot.c
rm -f mpich2-mpdroot.c
# A special alternate installation target when using multiple process managers
diff --git a/src/pm/mpd/mpdroot.c b/src/pm/mpd/mpdroot.c
index 348c7b6..1a4f2a5 100644
--- a/src/pm/mpd/mpdroot.c
+++ b/src/pm/mpd/mpdroot.c
@@ -19,6 +19,7 @@ int main(int argc, char *argv[])
struct passwd *pwent;
char input_line[NAME_LEN+1], secretword[NAME_LEN+1];
FILE *conf_file;
+ char *mpdconf_path = NULL;
if ((pwent = getpwuid(getuid())) == NULL) /* for real id */
{
@@ -26,10 +27,32 @@ int main(int argc, char *argv[])
exit(-1);
}
- conf_file = fopen("/etc/mpd.conf","r");
+ /*
+ * We look for a readable mpd.conf in the following order.
+ * - MPD_CONF_FILE set in environment
+ * - .mpd.conf in the user's home directory
+ * - The system wide default in SYSCONFDIR/mpd.conf
+ */
+ mpdconf_path = getenv("MPD_CONF_FILE");
+ if ( ! (mpdconf_path && access( mpdconf_path, R_OK ) == 0) ){
+ /* By far, the largest we'll need */
+ size_t mpdconf_path_len = strlen(pwent->pw_dir) \
+ + strlen(SYSCONFDIR) + strlen("/.mpd.conf");
+
+ mpdconf_path = (char*) malloc( sizeof(char) * mpdconf_path_len );
+ if ( ! mpdconf_path ){
+ fprintf( stderr, "%s: Failed to allocate a buffer for path to mpd.conf\n", argv[0]);
+ exit(-1);
+ }
+ snprintf( mpdconf_path, mpdconf_path_len-1, "%s/.mpd.conf", pwent->pw_dir );
+ if ( access( mpdconf_path, R_OK ) != 0 )
+ snprintf( mpdconf_path, mpdconf_path_len-1, "%s/mpd.conf", SYSCONFDIR );
+ }
+ conf_file = fopen( mpdconf_path, "r");
+
if (conf_file == NULL)
{
- printf("%s: open failed for root's mpd conf file",argv[0]);
+ printf("%s: open failed for root's mpd conf file\n",argv[0]);
exit(-1);
}
secretword[0] = '\0';
--
1.6.3.3
|