summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaroslav Kysela <perex@perex.cz>2013-04-08 14:49:31 +0200
committerJaroslav Kysela <perex@perex.cz>2013-04-08 14:51:39 +0200
commite05b903b1fb16e967d838edac408304cd4470fee (patch)
tree680bdeb84d83e3b19c3aba19322925d998db2f14
parent46cb355d4ff41c8065b02644b0534ab42d16cb72 (diff)
alsactl: move systemd config to the daemon mode
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
-rw-r--r--.gitignore1
-rw-r--r--alsactl/90-alsa-restore.rules.in2
-rw-r--r--alsactl/Makefile.am16
-rw-r--r--alsactl/alsa-restore.service.in11
-rw-r--r--alsactl/alsa-state.service.in11
-rw-r--r--alsactl/alsa-store.service.in9
-rw-r--r--alsactl/alsactl.c13
-rw-r--r--configure.in6
8 files changed, 33 insertions, 36 deletions
diff --git a/.gitignore b/.gitignore
index 546ec6b..096b126 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,6 +25,7 @@ ABOUT-NLS
alsactl/alsactl
alsactl/alsactl_init.7
+alsactl/alsa-state.service
alsaconf/alsaconf
alsamixer/alsamixer
amidi/amidi
diff --git a/alsactl/90-alsa-restore.rules.in b/alsactl/90-alsa-restore.rules.in
index 0bcee5b..fe0e1ed 100644
--- a/alsactl/90-alsa-restore.rules.in
+++ b/alsactl/90-alsa-restore.rules.in
@@ -1,2 +1,2 @@
ACTION=="add", SUBSYSTEM=="sound", KERNEL=="controlC*", KERNELS=="card*", \
- RUN+="@sbindir@/alsactl restore $attr{number}"
+ RUN+="@sbindir@/alsactl nrestore $attr{number}"
diff --git a/alsactl/Makefile.am b/alsactl/Makefile.am
index 8090d02..2a439e9 100644
--- a/alsactl/Makefile.am
+++ b/alsactl/Makefile.am
@@ -8,7 +8,7 @@ endif
EXTRA_DIST=alsactl.1 alsactl_init.xml
alsactl_SOURCES=alsactl.c state.c lock.c utils.c init_parse.c daemon.c
-alsactl_CFLAGS=$(AM_CFLAGS) -DSYS_ASOUNDRC=\"$(ASOUND_STATE_DIR)/asound.state\"
+alsactl_CFLAGS=$(AM_CFLAGS) -DSYS_ASOUNDRC=\"$(ASOUND_STATE_DIR)/asound.state\" -DSYS_PIDFILE=\"$(ALSACTL_PIDFILE_DIR)/alsactl.pid\"
noinst_HEADERS=alsactl.h list.h init_sysdeps.c init_utils_string.c init_utils_run.c init_sysfs.c
dist_udevrules_DATA = \
@@ -17,8 +17,7 @@ dist_udevrules_DATA = \
if HAVE_SYSTEMD
systemdsystemunit_DATA = \
- alsa-store.service \
- alsa-restore.service
+ alsa-state.service
install-data-hook:
$(MKDIR_P) -m 0755 \
@@ -36,23 +35,18 @@ endif
edit = \
$(SED) -r 's,@sbindir\@,$(sbindir),g' < $< > $@ || rm $@
-alsa-store.service: alsa-store.service.in
- $(edit)
-
-alsa-restore.service: alsa-restore.service.in
+alsa-state.service: alsa-state.service.in
$(edit)
90-alsa-restore.rules: 90-alsa-restore.rules.in
$(edit)
EXTRA_DIST += \
- alsa-store.service.in \
- alsa-restore.service.in \
+ alsa-state.service.in \
90-alsa-restore.rules.in
CLEANFILES = \
- alsa-store.service \
- alsa-restore.service \
+ alsa-state.service \
90-alsa-restore.rules
%.7: %.xml
diff --git a/alsactl/alsa-restore.service.in b/alsactl/alsa-restore.service.in
deleted file mode 100644
index e97d196..0000000
--- a/alsactl/alsa-restore.service.in
+++ /dev/null
@@ -1,11 +0,0 @@
-[Unit]
-Description=Restore Sound Card State
-DefaultDependencies=no
-After=sysinit.target
-Before=shutdown.target
-Conflicts=shutdown.target
-
-[Service]
-Type=oneshot
-ExecStart=-@sbindir@/alsactl restore
-StandardOutput=syslog
diff --git a/alsactl/alsa-state.service.in b/alsactl/alsa-state.service.in
new file mode 100644
index 0000000..119be1b
--- /dev/null
+++ b/alsactl/alsa-state.service.in
@@ -0,0 +1,11 @@
+[Unit]
+Description=Manage Sound Card State (restore and store)
+DefaultDependencies=no
+After=sysinit.target
+Before=shutdown.target
+Conflicts=shutdown.target
+
+[Service]
+Type=simple
+ExecStart=-@sbindir@/alsactl -s rdaemon
+ExecStop=-@sbindir@/alsactl -s rkill save_and_quit
diff --git a/alsactl/alsa-store.service.in b/alsactl/alsa-store.service.in
deleted file mode 100644
index 0e2823c..0000000
--- a/alsactl/alsa-store.service.in
+++ /dev/null
@@ -1,9 +0,0 @@
-[Unit]
-Description=Store Sound Card State
-DefaultDependencies=no
-Before=shutdown.target
-
-[Service]
-Type=oneshot
-ExecStart=@sbindir@/alsactl store
-StandardOutput=syslog
diff --git a/alsactl/alsactl.c b/alsactl/alsactl.c
index 8a4d9ee..f00cfff 100644
--- a/alsactl/alsactl.c
+++ b/alsactl/alsactl.c
@@ -159,6 +159,7 @@ int main(int argc, char *argv[])
int init_fallback = 1; /* new default behavior */
int period = 5*60;
int background = 0;
+ int daemoncmd = 0;
struct arg *a;
struct option *o;
int i, j, k, res;
@@ -178,7 +179,7 @@ int main(int argc, char *argv[])
if ((a->sarg & 0xff) == 0)
continue;
o = &long_option[j];
- o->name = args->larg;
+ o->name = a->larg;
o->has_arg = (a->sarg & (ENVARG|FILEARG|INTARG)) != 0;
o->flag = NULL;
o->val = a->sarg & 0xff;
@@ -296,12 +297,15 @@ int main(int argc, char *argv[])
daemon(0, 0);
}
+ cmd = argv[optind];
+ daemoncmd = strcmp(cmd, "daemon") == 0 || strcmp(cmd, "rdaemon") == 0;
+
if (use_syslog) {
openlog("alsactl", LOG_CONS|LOG_PID, LOG_DAEMON);
- syslog(LOG_INFO, "alsactl " SND_UTIL_VERSION_STR " daemon started");
+ if (daemoncmd)
+ syslog(LOG_INFO, "alsactl " SND_UTIL_VERSION_STR " daemon started");
}
- cmd = argv[optind];
if (!strcmp(cmd, "init")) {
res = init(initfile, cardname);
snd_config_update_free_global();
@@ -328,7 +332,8 @@ int main(int argc, char *argv[])
snd_config_update_free_global();
if (use_syslog) {
- syslog(LOG_INFO, "alsactl daemon stopped");
+ if (daemoncmd)
+ syslog(LOG_INFO, "alsactl daemon stopped");
closelog();
}
return res < 0 ? -res : 0;
diff --git a/configure.in b/configure.in
index e0dc883..bcb5321 100644
--- a/configure.in
+++ b/configure.in
@@ -322,6 +322,12 @@ AC_ARG_WITH([asound-state-dir],
[ASOUND_STATE_DIR="/var/lib/alsa"])
AC_SUBST(ASOUND_STATE_DIR)
+AC_ARG_WITH([alsactl-pidfile-dir],
+ AS_HELP_STRING([--with-alsactl-pidfile-dir=DIR], [Directory to place alsactl.pid file in]),
+ [ALSACTL_PIDFILE_DIR="$withval"],
+ [ALSACTL_PIDFILE_DIR="/var/run"])
+AC_SUBST(ALSACTL_PIDFILE_DIR)
+
AC_OUTPUT(Makefile alsactl/Makefile alsactl/init/Makefile \
alsamixer/Makefile amidi/Makefile amixer/Makefile \
m4/Makefile po/Makefile.in \