We added the check of asound.state file presence some time ago to
assure that alsactl gets called only if the state file is already
present. Since then, the situation has changed significantly:
e.g. now alsactl does initialize if the state file isn't present, and
the same alsa-restore.service is used to save the state. This means
that we should start this service no matter the state file exists at
the boot time or not. So, revert the old change again.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
A race at creating a lock file in state_lock() was discovered
recently: namely, between the first open(O_RDWR) and the second
open(O_RDWR|O_CREAT|O_EXCL) calls, another alsactl invocation may
already create a lock file, then the second open() will return EEXIST,
which isn't handled properly and treated as a fatal error.
In this patch, we check EEXIST case and try again open() with O_RDWR.
This must succeed usually, and if it fails, handle finally as the
fatal error.
BugLink: https://bugzilla.opensuse.org/show_bug.cgi?id=1179904
Signed-off-by: Takashi Iwai <tiwai@suse.de>
The state_lock() has a loop to wait for the lock file creation, and
the timeout value gets decremented twice mistakenly, which leads to a
half timeout (5 seconds) than expected 10 seconds. Fix it.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
The generic initialization code returns error code 99 (-99). Take
all those codes equal or above (bellow) this value as non-fatal.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
As man page says: "If successful, the sched_setparam() function shall return zero."
Without update I got this output in the syslog (journalctl):
abr 16 09:25:30 mypc alsactl[1652]: alsactl 1.2.2 daemon started
abr 16 09:25:30 mypc alsactl[1652]: /usr/bin/alsactl: do_nice:165sched_setparam failed: No such file or directory
If sched_setscheduler() returns 0, so it means that the call was successful.
Signed-off-by: Oscar Megía <megia.oscar@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
The timeout wasn't really being used for anything; disabling it should
reduce idle energy consumption slightly.
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Tested-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Previously, things like attaching strace to a running 'alsactl monitor'
process would cause it to exit.
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Tested-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
The `L` length modifier only applies to floating-point conversion
specifiers, and `ll` is used for `long long` integers.
Although glibc accepts %Li, musl does not and returns EINVAL.
Signed-off-by: Michael Forney <mforney@mforney.org>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
They are equivalent, but __func__ is in C99. __FUNCTION__ exists only
for backwards compatibility with old gcc versions.
Signed-off-by: Michael Forney <mforney@mforney.org>
Reviewd-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
In a mode of 'monitor, event loop runs to dispatch asynchronous event
emitted by control node. In this case, UNIX signal is used to terminate
the event loop.
This commit uses signalfd to catch the UNIX signal.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
At present, plug-and-play is not supported in a mode of 'monitor',
thus new sound card is not handled during runtime. This is not happy.
This commit uses Linux-specific inotify(7) to monitor '/dev/snd'
directory. When some files are newly added to the directory,
event dispatcher is suspended. Event sources are scanned again and the
dispatcher continue to run.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Once sound card becomes disconnection state, corresponding control node
becomes to emit error event for listeners. When catching this type of
event, event dispatcher should stop observation of the node. However,
at present, a mode of monitor can't handle this correctly. As a result,
poll(2) is executed quite frequently in loop with no wait. This results
100% consumption of CPU time.
This commit takes the dispatcher to remove the node from observation
list when detecting the disconnection state.
Reported-by: Thomas Gläßle <thomas@coldfix.de>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
In former commits, handlers of control node are maintained by link list,
instead of one-dimensional array.
This commit obsoletes the array and split source preparation to a
function.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
In a previous commit, handlers of control nodes are maintained by link
list.
This commit uses the list to register/unregister event sources to
dispatcher.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
At present, handlers for control nodes are maintained by one-dimensional
array. This is not necessarily useful to maintain handlers with
associated information.
This commit adds link-list for the maintenance.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Linux kernel supports unique system call; epoll(7). This allows
applications to make associations for descriptor-unique data in a
easy way.
This commit uses epoll(7) instead of poll(2) for this point.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
In a mode of 'monitor', when given no argument, all of available control
node is observed for their events. At present, discovering the nodes is
done according to sound card number, instead of listing nodes in
configuration space of alsa-lib.
This commit adds a structure to discover sound cards with a simple
interface.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
In a mode of 'monitor', an event loop runs.
This commit applies a small refactoring to splits the loop into a
function for readability.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This solves the chicken and egg problem on fresh installations whereby
the alsa state file does not yet exist, and alsa-restore unit attempted
to launch without first having a state file.
Signed-off-by: Ikey Doherty <ikey@solus-project.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Ensures soundcard is ready before restoring state.
sound.target added to systemd in v18:
https://cgit.freedesktop.org/systemd/systemd/commit/?id=88dfa2938af
Simplify dependencies:
- After=alsa-state.service is not needed because both units test for
@daemonswitch@ with opposite outcomes.
- After=sysinit.target is automatically added by systemd.
First proposed by Tom Yan.
Signed-off-by: Chris Mayo <aklhfex@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
`/lib/systemd/system/alsa-restore.service` specifies
`StandardOutput=syslog`. This overrides the `DefaultStandardOutput`
setting from `/etc/systemd/system.conf`, which the system administrator
can use to specify how output gets logged. In particular, the sysadmin
may want output to go to the journal, or to syslog, or nowhere at all [1].
This patch removes the definition entirely, so the units can use the
system default.
Upstream the patch from the Debian package [2].
[1] https://bugs.debian.org/741123
"systemd services should not use StandardOutput=syslog; should rely
on DefaultStandardOutput"
[2] https://sources.debian.net/src/alsa-utils/1.1.2-1/debian/patches/systemd_standardoutput.patch/
Signed-off-by: Paul Menzel <paulepanter@users.sourceforge.net>
CC: Jordi Mallach <jordi@debian.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
The code releasing the each card object may access to NULL when a
bogus count is given. Add a NULL check just to make sure.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
With RemainAfterExit=true, we can manage both save and restore of the
card state in a single unit file. This will fix also the case where
systemd reloads the service; with two individual units, it will
restore the previous state before saving, and may lead to inconsistent
state suddenly.
Also fix alsa-state.service as well to make both start and stop
working in a simpler way.
Bugzilla: https://bugzilla.novell.com/show_bug.cgi?id=929619
Signed-off-by: Takashi Iwai <tiwai@suse.de>
With alsa-restore.service and alsa-store.service, systemd invokes
alsactl at boot and shutdown times. When this is invoked on a system
without sound cards, it results in an ugly error message from alsact
/usr/sbin/alsactl: save_state:1590: No soundcards found...
return code is "19"
Add ConditionPathExistsGlob checks of /dev/snd/control* devices for
avoiding unnecessary invocations of alsactl on such a system.
Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=940950
Signed-off-by: Takashi Iwai <tiwai@suse.de>
readlink does not guarantee that its result string is nul-terminated.
Instead, increase the buffer by one byte to make sure that we can
add '\0' at the end.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
We now enable more outputs than just the main speaker, so update
the basic rules to reflect the actual situation.
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>