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>
Use the "mydatadir" name consistently.
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Sometimes 90-alsa-restore.rules is run before /usr is mounted,
and alsactl restore depends on /usr/share/alsa being present.
If /usr/share/alsa is not present, we're so early in the boot
process that alsa-restore.service (or upstart equivalent) will
run later on.
BugLink: https://bugs.launchpad.net/bugs/1289730
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
It can not be generally assumed that the directories in which asound.state
resides are writable. Use /var/lock and allow users to alter this path.
Signed-off-by: Julian Scheel <julian@jusst.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
$attr{number} in the RUN rule is an empty expansion. This makes sense,
because the path doesn't exist -- i.e., it refers to the path:
/sys/devices/pci0000:00/foo/bar/sound/card0/controlC0/number
Instead, refer to $attr{device/number}, which does exist.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
SND_CTL_EVENT_MASK_REMOVE has to be checked at first and ignore the
rest if it matches. Suggested by Clemens.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
The file alsactl/init/00main includes the line:
CARDINFO{driver}=="CA0106", INCLUDE="ca0106", GOTO="init_end"
However, the file alsactl/init/ca0106 is not making it into the
release tarballs (nor to user installations).
This patch adds the ca0106 file to the build.
Signed-off-by: Gabriel M. Beddingfield <gabrbedd@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sprintf() is a bit dangerous unless you explicitly know your type size
and want to keep it in sync always. Its safer to just use snprintf() and
ensure your string doesn't overflow and is NULL terminated.
Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
The state management can run at low priority, add --nice and --sched-idle
options to set the scheduler.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
For the plug-and-play hardware, like USB devices, it may be helpful
to manage the sound state periodically, before the devices are removed.
This change implements new commands 'daemon' and 'rdaemon' to save
the sound state in defined intervals when the sound controls are changed.
The udev rules can notify the daemon using the 'kill' or 'nrestore'
commands to rescan available cards in the system.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
- store new configuration to file + ".new" extension, rename later
- free the configuration tree on exit from load_state()/save_state()
- call snd_config_update_free_global() at the end of command blocks
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
When alsactl init is invoked and a directory path is passed to INCLUDE
command in the config file, read only *.conf files in that directory.
This will avoid reading backup files or invalid files that have been
created accidentally.
Also by using scandir() with alphasort(), alsactl reads the files in
alphabetical order. Thus it's highly recommended to use some number
prefix to the file name for assuring the order.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
When the global state does not exist, alsactl tries to
initialize all soundcards. It is not good when alsactl
is called multiple times from udev. Also, selinux can deny
access to non-existent devices.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
When I was reading the source code, I stumbled over this typo causing
Center, LFE, and Surround speakers not to be initialized.
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Add missing initialization of surround and CLFE playback volumes and
switches. Ditto for "Front Speaker", etc.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
The alsactl Makefile used 'sed $(SED)' which is going to failed when SED
is actually set. Replaced that with '$(SED)', and a few 'sed' calls in
alsaconf Makefile as well. Added AC_PROG_SED to configure to have it
set.
Fixes: https://bugtrack.alsa-project.org/alsa-bug/view.php?id=5363
Fixes: http://bugs.gentoo.org/show_bug.cgi?id=366587
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
The CD analog playback line is seldom used these days, as all
modern players rip the CD and use the DAC on the sound card.
In addition, it causes background hum on some machines.
Therefore keep it muted by default.
BugLink: http://bugs.launchpad.net/bugs/747184
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
After the previous patch to install udev rules it is impossible to do a
non-root, custom-prefix make install. This is generally not a problem
when building official packages but it can be a pain for developers
and debuggers etc.
This is essentially the same patch as was already made in PulseAudio
in commit e8a5746f2fcae59bfd18d39b621509b3ef130453.
Signed-off-by: Colin Guthrie <gmane@colin.guthr.ie>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
.... and add configure switch for it.
/etc might be on a read-only partition which is not suitable for dynamic
data such as the mixer settings. Hence move the location of asound.state
to /var/lib.
This is based on a patch from Ubuntu/Debian which hardcoded the pah in
/var/lib.
Signed-off-by: Lennart Poettering <mznyfn@0pointer.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Add minimal systemd and udev support to alsactl so that mixer settings
are restored at boot, when sound cards are plugged in and saved on
shutdown.
This is similar to existing udev/init script solutions in various
distributions.
Note that alsactl is called both synchronously from the udev rules as
well as asynchronously at boot. This is intended, and to ensure two
things:
- At boot the asound.state file might not be readable, since it resides
on a different file system. That means exclusively restoring sound card
settings from udev rules will no suffice, since if the rule is
executed at early boot (for example within udev settle) then the file
will no be readable and cannot be restored.
- We need to ensure that applications monitoring sound cards coming and
going (such as PA) must not get these events before the mixer settings
have been restored. That means the mixer settings must be restored
synchronously withing the udev rules, before the events are passed on
to the apps.
That basically means we need to restore the settings once in udev, to
deal with sound cards becoming available during runtime. And once in
early boot to deal with coldplugged soundcards whose data files might
not have been available at time of plugging. Hence we call alsactl
twice: one from the udev rule, and once from he systemd unit file.
Signed-off-by: Lennart Poettering <mznyfn@0pointer.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
The inactive controls are stored, but they are not restored
when they are marked inactive in the state file or in the
driver.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Make the comment node a separate node in the state file (join=0), and
move it after the other fields of the respective control.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
When the range of a control has changed between driver versions, it is a
good idea to restore the same dB value of the control. However,
computing the dB value by interpolating betweem the min/max dB values
duplicates alsa-lib's TLV functions and does not even work for controls
with a linear dB range.
A simple conversion to dB and back can be done if we add the dB value(s)
to the saved state.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Reserving new space from the stack in every loop iteration is not
necessary, so move the call to snd_ctl_elem_id_alloca outside where it
is executed only once.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
To save a call to snd_config_set_xxx, replace the calls to
snd_config_make_xxx with snd_config_imake_xxx.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Also, make the initialization & restore logic for one card similar to
multiple card initialization & restore.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
If initialization file (-i option) does not exists, the free_space()
function was called with NULL pointer.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>