Commit graph

281 commits

Author SHA1 Message Date
Jaroslav Kysela
b348abcbfe alsactl: add new -U argument text to man page
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 13:05:12 +02:00
Andrew Hlynskyi
d7bf45edc3 alsactl: init - add -U option to disable UCM based init
The reason is to use it with internal init extra commands like:
  alsactl -U -E CMD=info init

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 13:03:03 +02:00
Jaroslav Kysela
225a9afbc3 alsactl: fix the syslog message - add : delimiter after function:line
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-20 08:47:01 +02:00
Jaroslav Kysela
f8a2aad5bb alsactl: ucm - rename _once command to _boot command
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:21:25 +02:00
Jaroslav Kysela
570ea6c455 alsactl: allow to compile alsactl without UCM support
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 19:54:04 +02:00
Jaroslav Kysela
0adca4cac7 alsactl: use the right priority for syslog messages
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 19:41:40 +02:00
Jaroslav Kysela
b68e854d28 alsactl: add -D argument to execute also the UCM defaults section
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 19:34:18 +02:00
Jaroslav Kysela
8fb4016a17 alsactl: redirect alsa-lib errors
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 19:09:53 +02:00
Jaroslav Kysela
4bea8fe3a7 alsactl: add initial support for UCM init
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 18:19:20 +02:00
Jaroslav Kysela
598488c4af alsactl: init - iterate through all cards for the initial settings
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>
2020-05-14 18:18:22 +02:00
Jaroslav Kysela
f9abf36d34 alsactl: daemon.c - fix gcc warning in write_pid_file() 2020-05-14 16:49:06 +02:00
Oscar65
d2bf87608a alsactl: fix error handling for sched_setscheduler() call
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>
2020-04-17 09:29:24 +02:00
Zev Weiss
5fe6b86659 alsactl: avoid needless wakeups in monitor loop.
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>
2020-04-14 15:34:00 +02:00
Zev Weiss
5830fc726a alsactl: don't exit on EINTR from epoll_wait().
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>
2020-04-14 15:33:58 +02:00
Michael Forney
646b3b1c0b Use %lli for long long in printf
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>
2020-02-10 12:39:17 +01:00
Michael Forney
f80a290153 Use __func__ instead of __FUNCTION__
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>
2020-02-10 12:38:28 +01:00
Jaroslav Kysela
34e373d0b1 alsactl: fix --sched-idle (set it really to SCHED_IDLE)
Reported-by: tommy <tommy@kelsos.ptp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-12-03 13:53:25 +01:00
Jaroslav Kysela
3c740d9049 alsactl: sysfs - add /sys/kernel/uevent_seqnum check to init
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-25 18:01:32 +01:00
Rosen Penev
80fd81f4a8 treewide: Fix printf formats
Found with cppcheck

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2019-11-20 19:46:17 +01:00
Jaroslav Kysela
8c026b9562 alsactl: monitor - remove dead code in run_dispatcher() (coverity)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-03-13 14:46:33 +01:00
Jaroslav Kysela
cf2cc37502 alsactl: simple coverity fix
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-03-12 16:05:48 +01:00
Jaroslav Kysela
d751320608 alsactl: lock - fix the array size (gcc warning)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-10-14 17:01:38 +02:00
Takashi Sakamoto
46cb575b9b alsactl: use signalfd to catch UNIX signal
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>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
e57a0a0809 alsactl: handle detection of new sound card
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>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
440ea7d38d alsactl: handle disconnection of sound card
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>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
af14a2fab0 alsactl: obsolete array for maintenance of handlers
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>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
89ab7146ba alsactl: use a list of source for event dispatcher instead of an array of source
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>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
5e010366d3 alsactl: use link list to maintain source of events
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>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
5c859fa649 alsactl: use epoll(7) instead of poll(2)
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>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
fbc31a7593 alsactl: add an iterator of registered instances of sound card
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>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
0ef92b4ee7 alsactl: split event loop code to a function
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>
2018-10-14 16:57:15 +02:00
Ikey Doherty
f1eba0b5de alsactl: Only start restore service when asoundrc file exists
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>
2017-12-14 11:24:40 +01:00
Jaroslav Kysela
b1e3d945b7 Change FSF address (Franklin Street)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2017-11-14 14:28:53 +01:00
Chris Mayo
f72a296d23 alsactl: Move systemd unit start-up from basic.target to sound.target
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>
2017-10-06 14:32:16 +02:00
Paul Menzel
e9a6d425b5 alsactl: Remove standard output definition in systemd unit
`/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>
2016-12-28 17:08:52 +01:00
Takashi Iwai
9839813e7c alsactl: Fix potential NULL dereferences in daemon mode
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>
2016-12-09 17:28:47 +01:00
Jaroslav Kysela
c5b022e621 alsactl: init/ca0106, init/hda - use CTL{values} instead CTL{value}
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2016-03-22 16:54:05 +01:00
Jaroslav Kysela
3ad94da0c8 alsactl: remove debug line in set_ctl_values()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2016-03-22 16:50:33 +01:00
Takashi Iwai
7d6673cc13 alsactl: Manage both save and restore in a single unit
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>
2015-09-29 17:54:17 +02:00
Takashi Iwai
0e864e1a3a alsactl: Add path condition to alsa-store and alsa-restore services
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>
2015-08-10 14:42:24 +02:00
Tobias Stoeckmann
13c8269414 alsactl: terminate readlink result string
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>
2015-07-13 16:37:28 +02:00
David Henningsson
e1745a69fe alsactl/init: Add "Line Out" to list of outputs to initialize
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-01-12 17:01:06 +01:00
David Henningsson
d522b45508 alsactl/init: Change the "basic rules" description
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>
2015-01-12 17:00:56 +01:00
Jaroslav Kysela
55d41b7fe3 alsactl: add missing state_unlock() call 2014-12-24 20:15:26 +01:00
Jaroslav Kysela
89a4f490bd alsactl: coverity - missing_va_end – va_end was not called for "ap" 2014-09-24 10:52:17 +02:00
Jaroslav Kysela
17d4a5dd35 monitor: fix clang warning - Declared variable-length array (VLA) has zero size 2014-09-24 10:50:54 +02:00
Jaroslav Kysela
74e5d57c99 alsactl: aded missing monitor() prototype 2014-09-24 10:46:02 +02:00
Jaroslav Kysela
1363f852e9 alsactl: Fix the file locking routines (for the state management) 2014-09-24 10:35:53 +02:00
Jaroslav Kysela
03a652e18d alsactl: save state - do not call rename for stdio
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2014-06-25 10:54:26 +02:00
David Henningsson
3a7c1c59ec alsactl: Fixup test for mydatadir/sbindir
Use the "mydatadir" name consistently.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2014-06-13 11:54:45 +02:00