1 |
From fcdcc60b87c765de9b9cb018e76183e1c4815308 Mon Sep 17 00:00:00 2001 |
2 |
From: Lennart Poettering <lennart@poettering.net> |
3 |
Date: Tue, 23 Nov 2010 01:45:08 +0100 |
4 |
Subject: [PATCH 1/4] alsactl: systemd and udev hookup |
5 |
|
6 |
Add minimal systemd and udev support to alsactl so that mixer settings |
7 |
are restored at boot, when sound cards are plugged in and saved on |
8 |
shutdown. |
9 |
|
10 |
This is similar to existing udev/init script solutions in various |
11 |
distributions. |
12 |
|
13 |
Note that alsactl is called both synchronously from the udev rules as |
14 |
well as asynchronously at boot. This is intended, and to ensure two |
15 |
things: |
16 |
|
17 |
- At boot the asound.state file might not be readable, since it resides |
18 |
on a different file system. That means exclusively restoring sound card |
19 |
settings from udev rules will no suffice, since if the rule is |
20 |
executed at early boot (for example within udev settle) then the file |
21 |
will no be readable and cannot be restored. |
22 |
|
23 |
- We need to ensure that applications monitoring sound cards coming and |
24 |
going (such as PA) must not get these events before the mixer settings |
25 |
have been restored. That means the mixer settings must be restored |
26 |
synchronously withing the udev rules, before the events are passed on |
27 |
to the apps. |
28 |
|
29 |
That basically means we need to restore the settings once in udev, to |
30 |
deal with sound cards becoming available during runtime. And once in |
31 |
early boot to deal with coldplugged soundcards whose data files might |
32 |
not have been available at time of plugging. Hence we call alsactl |
33 |
twice: one from the udev rule, and once from he systemd unit file. |
34 |
|
35 |
Signed-off-by: Lennart Poettering <mznyfn@0pointer.de> |
36 |
Signed-off-by: Jaroslav Kysela <perex@perex.cz> |
37 |
--- |
38 |
Makefile.am | 3 ++ |
39 |
alsactl/.gitignore | 3 ++ |
40 |
alsactl/90-alsa-restore.rules.in | 2 + |
41 |
alsactl/Makefile.am | 46 ++++++++++++++++++++++++++++++++++++++ |
42 |
alsactl/alsa-restore.service.in | 11 +++++++++ |
43 |
alsactl/alsa-store.service.in | 9 +++++++ |
44 |
configure.in | 17 +++++++++++-- |
45 |
7 files changed, 88 insertions(+), 3 deletions(-) |
46 |
create mode 100644 alsactl/.gitignore |
47 |
create mode 100644 alsactl/90-alsa-restore.rules.in |
48 |
create mode 100644 alsactl/alsa-restore.service.in |
49 |
create mode 100644 alsactl/alsa-store.service.in |
50 |
|
51 |
diff --git a/Makefile.am b/Makefile.am |
52 |
index 5296977..0d54809 100644 |
53 |
--- a/Makefile.am |
54 |
+++ b/Makefile.am |
55 |
@@ -34,3 +34,6 @@ dist-hook: |
56 |
else \ |
57 |
$(TAR) --create --verbose --file=- $(distdir) | bzip2 -c -9 > $(distdir).tar.bz2 ; \ |
58 |
fi |
59 |
+ |
60 |
+DISTCHECK_CONFIGURE_FLAGS = \ |
61 |
+ --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) |
62 |
diff --git a/alsactl/.gitignore b/alsactl/.gitignore |
63 |
new file mode 100644 |
64 |
index 0000000..56ab3a2 |
65 |
--- /dev/null |
66 |
+++ b/alsactl/.gitignore |
67 |
@@ -0,0 +1,3 @@ |
68 |
+alsa-store.service |
69 |
+alsa-restore.service |
70 |
+90-alsa-restore.rules |
71 |
diff --git a/alsactl/90-alsa-restore.rules.in b/alsactl/90-alsa-restore.rules.in |
72 |
new file mode 100644 |
73 |
index 0000000..0bcee5b |
74 |
--- /dev/null |
75 |
+++ b/alsactl/90-alsa-restore.rules.in |
76 |
@@ -0,0 +1,2 @@ |
77 |
+ACTION=="add", SUBSYSTEM=="sound", KERNEL=="controlC*", KERNELS=="card*", \ |
78 |
+ RUN+="@sbindir@/alsactl restore $attr{number}" |
79 |
diff --git a/alsactl/Makefile.am b/alsactl/Makefile.am |
80 |
index 359f73a..9a2d30e 100644 |
81 |
--- a/alsactl/Makefile.am |
82 |
+++ b/alsactl/Makefile.am |
83 |
@@ -10,5 +10,51 @@ EXTRA_DIST=alsactl.1 alsactl_init.xml |
84 |
alsactl_SOURCES=alsactl.c state.c utils.c init_parse.c |
85 |
noinst_HEADERS=alsactl.h list.h init_sysdeps.c init_utils_string.c init_utils_run.c init_sysfs.c |
86 |
|
87 |
+udevrulesdir=/lib/udev/rules.d |
88 |
+ |
89 |
+dist_udevrules_DATA = \ |
90 |
+ 90-alsa-restore.rules |
91 |
+ |
92 |
+if HAVE_SYSTEMD |
93 |
+ |
94 |
+systemdsystemunit_DATA = \ |
95 |
+ alsa-store.service \ |
96 |
+ alsa-restore.service |
97 |
+ |
98 |
+install-data-hook: |
99 |
+ $(MKDIR_P) -m 0755 \ |
100 |
+ $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants \ |
101 |
+ $(DESTDIR)$(systemdsystemunitdir)/shutdown.target.wants |
102 |
+ ( cd $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants && \ |
103 |
+ rm -f alsa-restore.service && \ |
104 |
+ $(LN_S) ../alsa-restore.service alsa-restore.service ) |
105 |
+ ( cd $(DESTDIR)$(systemdsystemunitdir)/shutdown.target.wants && \ |
106 |
+ rm -f alsa-store.service && \ |
107 |
+ $(LN_S) ../alsa-store.service alsa-store.service ) |
108 |
+ |
109 |
+endif |
110 |
+ |
111 |
+edit = \ |
112 |
+ sed $(SED) -r 's,@sbindir\@,$(sbindir),g' < $< > $@ || rm $@ |
113 |
+ |
114 |
+alsa-store.service: alsa-store.service.in |
115 |
+ $(edit) |
116 |
+ |
117 |
+alsa-restore.service: alsa-restore.service.in |
118 |
+ $(edit) |
119 |
+ |
120 |
+90-alsa-restore.rules: 90-alsa-restore.rules.in |
121 |
+ $(edit) |
122 |
+ |
123 |
+EXTRA_DIST += \ |
124 |
+ alsa-store.service.in \ |
125 |
+ alsa-restore.service.in \ |
126 |
+ 90-alsa-restore.rules.in |
127 |
+ |
128 |
+CLEANFILES = \ |
129 |
+ alsa-store.service \ |
130 |
+ alsa-restore.service \ |
131 |
+ 90-alsa-restore.rules |
132 |
+ |
133 |
%.7: %.xml |
134 |
xmlto man $? |
135 |
diff --git a/alsactl/alsa-restore.service.in b/alsactl/alsa-restore.service.in |
136 |
new file mode 100644 |
137 |
index 0000000..e97d196 |
138 |
--- /dev/null |
139 |
+++ b/alsactl/alsa-restore.service.in |
140 |
@@ -0,0 +1,11 @@ |
141 |
+[Unit] |
142 |
+Description=Restore Sound Card State |
143 |
+DefaultDependencies=no |
144 |
+After=sysinit.target |
145 |
+Before=shutdown.target |
146 |
+Conflicts=shutdown.target |
147 |
+ |
148 |
+[Service] |
149 |
+Type=oneshot |
150 |
+ExecStart=-@sbindir@/alsactl restore |
151 |
+StandardOutput=syslog |
152 |
diff --git a/alsactl/alsa-store.service.in b/alsactl/alsa-store.service.in |
153 |
new file mode 100644 |
154 |
index 0000000..0e2823c |
155 |
--- /dev/null |
156 |
+++ b/alsactl/alsa-store.service.in |
157 |
@@ -0,0 +1,9 @@ |
158 |
+[Unit] |
159 |
+Description=Store Sound Card State |
160 |
+DefaultDependencies=no |
161 |
+Before=shutdown.target |
162 |
+ |
163 |
+[Service] |
164 |
+Type=oneshot |
165 |
+ExecStart=@sbindir@/alsactl store |
166 |
+StandardOutput=syslog |
167 |
diff --git a/configure.in b/configure.in |
168 |
index 8bae007..1bd5804 100644 |
169 |
--- a/configure.in |
170 |
+++ b/configure.in |
171 |
@@ -26,6 +26,7 @@ fi |
172 |
AC_PROG_CC |
173 |
dnl AC_PROG_CXX |
174 |
AC_PROG_INSTALL |
175 |
+AC_PROG_MKDIR_P |
176 |
AC_PROG_LN_S |
177 |
AM_PATH_ALSA(1.0.16) |
178 |
|
179 |
@@ -117,7 +118,7 @@ if test x$alsamixer = xtrue; then |
180 |
CURSES_CFLAGS=`ncursesw5-config --cflags` |
181 |
curseslib="ncursesw" |
182 |
else |
183 |
- AC_CHECK_LIB(ncursesw, initscr, |
184 |
+ AC_CHECK_LIB(ncursesw, initscr, |
185 |
[ CURSESINC='<ncurses.h>'; CURSESLIB='-lncursesw'; curseslib="ncursesw"]) |
186 |
fi |
187 |
if test -n "$CURSESINC"; then |
188 |
@@ -134,12 +135,12 @@ if test x$alsamixer = xtrue; then |
189 |
CURSES_CFLAGS=`ncurses5-config --cflags` |
190 |
curseslib="ncurses" |
191 |
else |
192 |
- AC_CHECK_LIB(ncurses, initscr, |
193 |
+ AC_CHECK_LIB(ncurses, initscr, |
194 |
[ CURSESINC='<ncurses.h>'; CURSESLIB='-lncurses'; curseslib="ncurses"]) |
195 |
fi |
196 |
fi |
197 |
if test "$curseslib" = "curses" -o "$curseslib" = "auto"; then |
198 |
- AC_CHECK_LIB(curses, initscr, |
199 |
+ AC_CHECK_LIB(curses, initscr, |
200 |
[ CURSESINC='<curses.h>'; CURSESLIB='-lcurses'; curseslib="curses"]) |
201 |
fi |
202 |
if test -z "$CURSESINC"; then |
203 |
@@ -265,6 +266,16 @@ SAVE_UTIL_VERSION |
204 |
|
205 |
AC_SUBST(LIBRT) |
206 |
|
207 |
+dnl Check for systemd |
208 |
+PKG_PROG_PKG_CONFIG |
209 |
+AC_ARG_WITH([systemdsystemunitdir], |
210 |
+ AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]), |
211 |
+ [], [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)]) |
212 |
+if test "x$with_systemdsystemunitdir" != xno; then |
213 |
+ AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir]) |
214 |
+fi |
215 |
+AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ]) |
216 |
+ |
217 |
AC_OUTPUT(Makefile alsactl/Makefile alsactl/init/Makefile \ |
218 |
alsamixer/Makefile amidi/Makefile amixer/Makefile \ |
219 |
m4/Makefile po/Makefile.in \ |
220 |
-- |
221 |
1.7.3.5 |
222 |
|