Commit graph

227 commits

Author SHA1 Message Date
Xidorn Quan
d09d81da55 Merge branch 'autogroup-nice' into 'master'
core-util: Set nice value for the task group

Closes #792

See merge request pulseaudio/pulseaudio!234
2025-10-06 18:53:00 +00:00
Alistair Leslie-Hughes
96bd4e57b5 pulsecore: Set errno before calling read
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/759>
2022-12-14 13:29:20 +11:00
Patrick Gaskin
4f3ca10d9e daemon: Add support for running as a service on win32
* Minimal implementation of --system on win32.
* Wrap main with a Windows Service on win32 (with a fallback to
  running it directly).
* Update PA_SYSTEM_{RUNTIME,STATE,CONFIG}_PATH and HOME dynamically
  on Windows (overrides the build config, similar to the existing
  config path replacement logic).

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/549>
2021-06-16 09:17:27 +00:00
Patrick Gaskin
a01cce726f win32: Fix environment variables set with pa_{unset,set}_env not taking effect
SetEnvironmentVariable is not visible to getenv.

See https://github.com/curl/curl/issues/4774.
See https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getenv-wgetenv.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/546>
2021-06-16 09:05:58 +00:00
Patrick Gaskin
dd87e9f229 win32: Fix format specifiers for DWORD values
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/458>
2021-01-13 03:42:24 +00:00
Edward Lee
9c774c6295 win32: Handle (WSA)EWOULDBLOCK as EAGAIN.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/360>
2020-12-16 11:05:28 -05:00
SimonP
9b0ae8327d alsa-mixer: Respect XDG base directory spec when loading path configs
Try $XDG_DATA_HOME, then $XDG_DATA_DIRS, and finally fall back to old
behaviour (prefix-defined directory).

core-util: Ignore non-absolute XDG base dirs

These are invalid per the spec.

Fixes: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/862
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/293>
2020-12-14 19:25:12 +00:00
Tanu Kaskinen
6bc00720f3 core-util: Never parse integers as octal
I believe nobody needs to pass octal numbers to PulseAudio, and if we
encounter integer strings starting with zeros, the intention is to use
them in base 10. Hexadecimal numbers are more common, and they can't be
interpreted in base 10 anyway, so they are still supported.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/51>
2020-12-03 14:41:39 +00:00
Tanu Kaskinen
d50145a916 core-util: Reduce repetition in number parsing functions
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/51>
2020-12-03 14:41:39 +00:00
Tanu Kaskinen
6722b2d8c4 core-util: Make range checks easier to read
It wasn't immediately obvious to me what these checks are supposed to
do. Explicitly checking against the min/max values should make the code
easier to understand.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/51>
2020-12-03 14:41:39 +00:00
Georg Chini
ca66388608 core-util: Add pa_atoi64() and pa_atou64() functions
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/51>
2020-12-03 14:41:39 +00:00
Xidorn Quan
d17c299e57 core-util: Set nice value for the task group 2020-06-07 23:49:39 +00:00
Nick Moriarty
97d0eda256 Permit root-owned home directory
On certain types of filesystem (especially NFS appliances which support
multiple operating systems), the user's home directory may report as
being owned by root rather than the user, yet still permit the user to
create and modify files normally (which will be owned by them).

Our users have home directories hosted on a NetApp storage appliance
which uses mixed-mode ACLs but where the home directory is set up with
NTFS ACLs at the top level.  This means they have the expected effective
permissions, but the ownership reports as root.  This could also be the
case if the filesystem were using NFS4 ACLs or similar.
2020-01-20 10:34:16 +00:00
Tanu Kaskinen
4dba56c1af core-util: Handle zero-length volume string
Without checking for zero we end up accessing memory outside the str
buffer: str[len - 1].

Fixes: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/768
2019-12-27 07:33:52 +02:00
Arun Raghavan
3dfccada46 alsa-ucm: Support Playback/CaptureVolume
This allows us to support the PlaybackVolume and CaptureVolume commands
in UCM, specifying a mixer control to use for hardware volume control.
This only works with ports corresponding to single devices at the
moment, and doesn't support stacking controls for combination ports.

The configuration is intended to provide a control (like Headphone
Playback Volume), but we try to resolve to a simple mixer control
(Headphone) to reuse existing volume paths.

On the UCM side, this also requires that when disabling the device for
the port, the volume should be reset to some default.

When enabling/disabling combination devices, things are a bit iffy since
we have no way to reset the volume before switching to a combination
device. It would be nice to have a combination-transition-sequence
command in UCM to handle this and other similar cases.

PlaybackSwitch and CaptureSwitch are yet to be implemented.
2019-12-06 10:05:44 +00:00
Ryszard Knop
ad16d77dfe switch-on-connect: Add blacklisting
Add a new module argument, blacklist, which is a regular expression.
If the sink/source name matches the provided blacklist regex, don't
automatically switch to it. By default, no devices are blacklisted.

Add a new function to check whenever a regex pattern is valid, plus
extra NULL asserts in pa_match.
2019-11-21 22:19:44 +01:00
Arun Raghavan
2ed4f388de core-util: Fix detection when running in a VM
The original code that was written was trying to detect what hypervisor
we were running under, rather than testing the presence bit first. We
don't really need the former, so let's use the more comprehensive latter
instead.

Fixes: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/684
2019-07-04 07:13:51 +00:00
Alan Coopersmith
4be2625ef8 core-util: Use /proc/fd on Solaris as well in pa_close_all
Gets rid of > 65,000 unnecessary close() syscalls

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2019-07-01 01:37:04 +00:00
Georg Chini
ab9fed9523 core-util: Avoid usage of pa_strbuf in pa_escape()
The current code uses a pa_strbuf to construct the escaped string. This
will generate a linked list member for each character which may be very
inefficient.
This patch avoids the use of pa_strbuf by allocating a sufficiently large
string which can be filled with the output data.
2019-05-25 15:28:41 +03:00
Sangchul Lee
eec27ec686 core-util: Use size_t for out parameter of pa_split_*in_place()
pa_split_in_place() and pa_split_spaces_in_place() are modifed
to use size_t type instead of integer type.

alsa-ucm.c is revised according to this change.

Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
2019-03-19 11:42:19 +09:00
scootergrisen
8b6006c0c6 "e g " to "e.g." 2019-02-16 10:49:53 +00:00
Hongxu Jia
3d9deb1e56 build-sys: introduce a special build flag to explicitly disables running from build tree
It is helpful to improve reproducibility build [1] since
PA_SRCDIR/PA_BUILDDIR contains build path,
--disable-running-from-build-tree could drop these macros at
precompilation.

[1] https://reproducible-builds.org/

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
2018-12-11 16:15:32 +02:00
Arun Raghavan
878ef44079 core: Expose API to elevate a thread to realtime priority
This should make it easier for clients to elevate their audio threads to
real time priority without having to dig through much through specific
system internals.
2018-06-21 06:29:32 +05:30
Georg Chini
4762aa45d9 core-util: correct error in set_nonblock()
set_nonblock() will always set the file descriptor to non-blocking,
regardless of the nonblock argument.

This patch fixes the issue by passing the correct argument to the
fcntl() call. The bug had no impact because there is only one caller
of pa_make_fd_block() in poll-win32.c
2018-06-21 05:50:29 +05:30
Tanu Kaskinen
c8bd93c5a7 core-util, cpu-x86: use __get_cpuid() instead of homegrown assembly
The get_cpuid() function in cpu-x86.c was buggy on x86-64. When building
without optimizations, the homegrown assembly code overwrote the
beginning of the function argument list on the stack. That happened to
work fine on regular x86-64, but caused crashing with the x32 ABI.

At least GCC and clang provide cpuid.h, which has the __get_cpuid()
function that can be used instead of the homegrown assembly.

The PA_REG_* constants can be removed as well, because they're not used
any more.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=103656
2017-12-07 01:06:48 +02:00
Peter Meerwald-Stadler
6b7b70c472 core-util: Fix description of pa_split()
Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
2017-03-08 14:31:29 +01:00
Hajime Fujita
43bf134aa1 core-util: do in-place search in pa_str_in_list_spaces
Reviewed-by: Anton Lundin <glance@acc.umu.se>
2017-01-19 03:00:45 +02:00
Hajime Fujita
04b46803cd core-util: add pa_split_space_in_place function
Reviewed-by: Anton Lundin <glance@acc.umu.se>
2017-01-19 03:00:45 +02:00
Martin Blanchard
736fabf0ca raop: Add pulsecore/core-utils a pa_str_in_list function
Reviewed-by: Anton Lundin <glance@acc.umu.se>
2017-01-19 02:56:53 +02:00
Marcin Lewandowski
8cda1fe3e2 core-util: log error if we hit file descriptors limit 2016-09-10 18:00:52 +03:00
Peter Meerwald-Stadler
45d9030638 core: Replace PA_PAGE_SIZE with pa_page_size()
PA_PAGE_SIZE using sysconf() may return a negative number

CID 1137925, CID 1137926, CID 1138485

instead of calling sysconf() directly, add function pa_page_size()
which uses the guestimate 4096 in case sysconf(_SC_PAGE_SIZE) fails

using PA_ONCE to only evaluate sysconf() once
2016-09-02 14:52:53 +02:00
Peter Meerwald-Stadler
8b076c3ed9 Remove newline at end of log messages
Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
2016-08-16 07:03:25 +02:00
John Paul Adrian Glaubitz
1df21e6ab6 core-util: Use _SC_NPROCESSORS_ONLN instead of _SC_NPROCESSORS_CONF
pa_ncpu() is supposed to report the number of processors available on
the system. For that, it currently calls sysconf(_SC_NPROCESSORS_CONF).
However, since the operating system can disable individual processors,
we should call sysconf(_SC_NPROCESSORS_ONLN) to determine the number
of processors currently available [1]. Consequently, the once-test will
fail since pthread_setaffinity_np() is called with CPUs that are
currently not available.

It might also be advisable to change the code in the future to use CPU
sets on Linux as even the suggested change is not 100% safe but at least
it improves over the existing code. If PulseAudio was to be run in a CPU
set [2], the number of processors available to PulseAudio could be even
less than the number of CPUs currently online (_SC_NPROCESSORS_CONF).

[1] https://www.gnu.org/software/libc/manual/html_node/Processor-Resources.html
[2] http://man7.org/linux/man-pages/man7/cpuset.7.html

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=96809
Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
2016-08-15 17:23:36 +03:00
Ulrich Eckhardt
111e332556 core-util: Improve pa_replace() behaviour
- Assert that the search string isn't empty.
 - Add test.
 - Improve documentation.
2016-06-22 12:55:55 +05:30
Deepak Srivastava
ccc83b6cd7 pulsecore: Fixed possible memory leak
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=95291

Signed-off-by: Deepak Srivastava <srivastava.d@samsung.com>
Signed-off-by: Arun Raghavan <git@arunraghavan.net>
2016-05-06 11:09:17 +05:30
Kamil Rytarowski
93cccdee8d core, pulse, modules: Fix undefined behavior with array subscript of invalid type
From the NetBSD manual:

     The first argument of these functions is of type int, but only a very
     restricted subset of values are actually valid.  The argument must either
     be the value of the macro EOF (which has a negative value), or must be a
     non-negative value within the range representable as unsigned char.
     Passing invalid values leads to undefined behavior.

     --  ctype(3)
2015-12-08 08:56:07 +05:30
Tanu Kaskinen
96f4b4ffe3 core-util: improve comments in pa_machine_id() 2015-12-07 10:18:48 +01:00
Kamil Rytarowski
2d555ba15c netbsd: Improve handling of <locale> and <xlocale.h> headers
NetBSD ships with strtod_l(3) in <stdlib.h>.
Having strtol_l(3) doesn't imply to have <xlocale.h>.
Generalize inclusion of <locale.h> and <xlocale.h>.
2015-12-07 09:01:21 +01:00
Kamil Rytarowski
3753f50755 netbsd: NetBSD ships with paccept(2) a superset of Linux-specific accept4()
[diwic: Moved paccept to #bsd line in configure.ac]
2015-11-27 09:52:10 +01:00
Julien Isorce
c021bfc6e0 core-util: avoid calling fchmod if already right mode
fchmod is denied in chromium sandbox.
2015-10-19 08:53:40 +05:30
Deepak Srivastava
2d5eec2d2c Rename functions with "tostring" in the name to one with "to_string" to conform with the convention.
component: core

<EP-E358F00C1D9A449EAE69225B9D2530F8>
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=88833

Signed-off-by: Deepak Srivastava <srivastava.d@samsung.com>
2015-09-25 17:29:02 +05:30
Peter Meerwald
bb88d90950 core: Fallbacks for machine-id in filesystem
see https://bugs.freedesktop.org/show_bug.cgi?id=88834

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2015-09-25 17:29:02 +05:30
Tanu Kaskinen
83de5a0995 core-util: include xlocale.h when using strtod_l()
Based on some googling, strtod_l() is defined in xlocale.h on BSD.
Glibc seems to define it in stdlib.h, but only if GNU extensions are
enabled (otherwise the function won't be available). So, this patch
should fix the use of strtod_l() on BSDs, but on other systems things
may or may not be still broken.

The original patch author is Jakob Fink <jfink@gmx.at>. He sent this
patch to the freebsd-gnome mailing list:
http://lists.freebsd.org/pipermail/freebsd-gnome/2015-April/032138.html

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=90285
2015-09-07 14:54:31 +02:00
Tanu Kaskinen
27d71c00d8 build-sys: check strtod_l instead of strtof_l
We have no strtof_l calls in the code, so it doesn't make sense to
check that function's availability. We have one strtod_l call, so
let's check that instead.

I don't know if this change makes any practical difference. I just
wondered why we had HAVE_STRTOF_L ifdefs in core-util.c for code that
didn't use strtof_l.
2015-09-07 14:54:27 +02:00
Tanu Kaskinen
bae15c420a core-util: Make pa_parse_volume() more strict
Previously pa_parse_volume() clamped the value to fit in the valid
range, but I think it's better to reject values outside the valid
range.

This also changes the percentage parsing to allow non-integer values.
2015-04-29 18:14:27 +03:00
Tanu Kaskinen
ef864eeab0 core-util: Filter out not-a-numbers in pa_atod()
We don't and probably never will have any pa_atod() callers that would
require "NaN" to be accepted, so let's filter those out in pa_atod(),
instead of requiring the callers to handle not-a-numbers appropriately
(which they generally forget to do).
2015-04-10 12:58:10 +03:00
Tanu Kaskinen
c0ab9e6ce0 core-util: Make number parsing stricter
pa_atou(), pa_atol() and pa_atod() are stricter than the libc
counterparts (the PA functions reject strings that have trailing extra
stuff in them). I have been under the impression that the PA functions
only accept "obviously valid numbers", that is, I have assumed that
these would be rejected: " 42" (leading whitespace), "" (empty
string) and "-18446744073709551615" in case of pa_atou().

I noticed that empty strings are accepted, however, and on closer
inspection I found that leading whitespace is accepted too, and even
that pa_atou() thinks that "-18446744073709551615" is the same thing
as "1"! This patch makes the parsing functions more strict, so that
they indeed only accept "obviously valid numbers". I decided to also
disallow leading plus signs, just because I don't like them.
2015-03-16 18:52:41 +02:00
David Herrmann
b8bcfeb78d core-util: Fix set_nice() to use private bus connections
In src/pulsecore/core-util.c:set_nice() we currently use a temporary
dbus-connection to set the nice-level via rtkit. However, we never
close that connection. This is fine, as the connection is shared and
dbus-core will manage it. But no other part of pulseaudio (except
set_scheduler()) uses the libdbus1 managed connections. Therefore,
we effectively end up with an unused dbus-connection that is not
integrated into any main-loop. dbus-daemon will send bus-notifications
to the connection (as libdbus1 installs matches for those by default
(it has to!)) until the outgoing queue is full. Thus, we waste several
KBs (or MBs? I didn't look it up) of memory for a message queue that
is never dispatched.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2015-03-12 13:42:46 +01:00
Ondrej Holecek
5effc83479 update FSF addresses to FSF web page
FSF addresses used in PA sources are no longer valid and rpmlint
generates numerous warnings during packaging because of this.
This patch changes all FSF addresses to FSF web page according to
the GPL how-to: https://www.gnu.org/licenses/gpl-howto.en.html

Done automatically by sed-ing through sources.
2015-01-14 22:20:40 +02:00
David Henningsson
686baf80d9 core-util: Fix build on mingw32
mingw32 does not have "getuid", so ifdef it properly.

Reported-by: Michael DePaulo <mikedep333@gmail.com>
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-12-04 15:39:03 +01:00