Commit graph

182 commits

Author SHA1 Message Date
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
Tanu Kaskinen
f04e31dc5e core-util: Add pa_unset_env()
Since we already have pa_set_env(), it's nice to also have a
corresponding function for unsetting environment variables.
2014-10-02 12:14:09 +03:00
David Henningsson
076601ee28 core-util: Fail if XDG_RUNTIME_DIR belongs to someone else
Usually, PA will use the PULSE_SERVER X11 property instead of using XDG_RUNTIME_DIR,
so this environment variable does not matter.

If this property is not available, or if one is using the pacmd cli protocol,
the client will go ahead and call pa_make_secure_dir on XDG_RUNTIME_DIR/pulse.
This will either fail (if you're another regular user), or succeed (if you're root).
Both scenarios are bad - failing will cause the connection to fail, and succeeding
is even worse, as it can cause *other* connections to fail (as the directory
ownership has changed).

Instead fail and complain loudly.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=83007
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-09-08 13:46:01 +02:00
Peter Meerwald
4540401167 core-util: Avoid warnings when missing certain system calls
on systems lacking #defines HAVE_ACCEPT4, HAVE_PIPE2, SOCK_CLOEXEC

pulsecore/core-util.c: In function 'pa_open_cloexec':
pulsecore/core-util.c:3348:1: warning: label 'finish' defined but not used [-Wunused-label]
pulsecore/core-util.c: In function 'pa_socket_cloexec':
pulsecore/core-util.c:3370:1: warning: label 'finish' defined but not used [-Wunused-label]
pulsecore/core-util.c: In function 'pa_pipe_cloexec':
pulsecore/core-util.c:3393:1: warning: label 'finish' defined but not used [-Wunused-label]
pulsecore/core-util.c: In function 'pa_accept_cloexec':
pulsecore/core-util.c:3415:1: warning: label 'finish' defined but not used [-Wunused-label]

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2014-08-18 15:31:31 +02:00
Tanu Kaskinen
440f37af00 core-util: Add pa_append_to_config_home_dir() 2014-06-24 13:20:22 +03:00
Tanu Kaskinen
6c5c65a718 core-util: Add pa_get_config_home_dir() 2014-06-24 13:17:53 +03:00
Tanu Kaskinen
50042da434 core-util: Add pa_append_to_home_dir() 2014-06-24 13:15:43 +03:00
Alexander E. Patrakov
f2f5dffb1d core-util: Remove redundant check of directory permissions
Initially (in commit ef422fa4ae),
pa_make_secure_dir followed a simple principle: "make a directory, or,
if it exists, check that it is suitable". Later this evolved into "make
a directory, or, if it exists, ensure that it is suitable". But the
check remained.

The check is now neither sufficient nor necessary. On POSIX-compliant
systems, the fstat results being checked are actually post-conditions of
fchmod and fchown. And on systems implementing POSIX ACLs, fstat only
reflects a part of the information relevant to the security of the
directory permissions, so PulseAudio could accept an existing insecure
directory anyway.

Also, the check still fires on non-POSIX-compliant filesystems like CIFS.
As a user cannot do anything to fix it, just accept insecure permissions
in this case.
2014-04-25 15:07:34 +03:00
Bradley Broom
5610d41482 core-util: Call fchown() only when necessary
This reportedly fixes some cases where the home directory is on NFS.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=45656
2014-04-25 13:00:00 +03:00
Peter Meerwald
ff9e9e05df core: Fix resource leak in core-util
https://scan7.coverity.com:8443/reports.htm#v10205/p10016/fileInstanceId=8477&defectInstanceId=3693&mergedDefectId=591269

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-12-20 12:54:18 +01:00
Ryan Lortie
6f954c7674 core-util: set_scheduler: check for RLIMIT_RTTIME
set_scheduler() assumes that if sys/resource.h was found then we will
find RLIMIT_RTTIME there, but this is a non-POSIX extension on Linux.

Change the check to ensure that RLIMIT_RTTIME is actually defined.
Linux indeed defines this as a macro, and POSIX specifies that the other
RLIMIT_ constants must be macros, so having this as an #ifdef seems
correct.
2013-12-13 14:00:14 +02:00
Peter Meerwald
345de08f2b core-util: Check that we actually have regexec before we use it
Thanks to Pierre Ossman for reporting the bug and providing an initial
fix on which this patch is based.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=69708
2013-12-06 13:30:27 +02:00
Pierre Ossman
e7df7bcd76 Revert "core: Transparently handle non-blocking sockets on Windows"
This reverts commit c327850d9e as
the workaround in that commit is no longer needed after the real
bug has been fixed.

Conflicts:
	src/pulsecore/core-util.c
2013-11-15 10:53:26 +02:00
Pierre Ossman
0138a51a2c core: make sure win32 sockets remain blocking
Commit 7e344b5 hade the side effect of forcing every socket to
be non-blocking on Windows. This is because of a (documented)
side effect of WSAEventSelect(). So we need to make sure to restore
blocking behaviour afterwards for relevant sockets.
2013-11-15 10:53:19 +02:00
Anton Lundin
35fea579cb build-sys: Fix building with Android toolchain
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2013-10-05 09:49:20 +05:30
poljar (Damir Jelić)
b358aea89b Revert dbus_bool_t variables to use TRUE/FALSE instead of true/false 2013-07-04 12:25:47 +03:00
poljar (Damir Jelić)
d806b19714 Remove pa_bool_t and replace it with bool.
commands used for this (executed from the pulseaudio/src directory):
    find . -regex '\(.*\.[hc]\|.*\.cc\|.*\.m4\)' -not -name 'macro.h' \
        -a -not -name 'reserve.[ch]' -a -not -name 'reserve-monitor.[ch]' \
        -a -not -name 'glib-mainloop.c' -a -not -name 'gkt-test.c' \
        -a -not -name 'glib-mainloop.c' -a -not -name 'gkt-test.c' \
        -a -not -name 'poll-win32.c' -a -not -name 'thread-win32.c' \
        -a -not -name 'dllmain.c' -a -not -name 'gconf-helper.c' \
        -exec sed -i -e 's/\bpa_bool_t\b/bool/g' \
        -e 's/\bTRUE\b/true/g' -e 's/\bFALSE\b/false/g' {} \;

and:
    sed -i -e '181,194!s/\bpa_bool_t\b/bool/' \
        -e '181,194!s/\bTRUE\b/true/' -e \
        '181,194!s/\bFALSE\b/false/' pulsecore/macro.h
2013-07-04 12:25:30 +03:00
Tanu Kaskinen
0587b5aa31 core-util: Fix log message levels
This code is from heftig, but the mistake that I'm fixing here is my
own. Before applying heftig's patch, I downgraded the level of one of
the log messages. I managed to downgrade a different message than what
I intended, so now I'm undoing that mistake.
2013-06-23 10:27:28 +03:00
Jan Alexander Steffens (heftig)
07290d9da7 core-util: Clamp RLIMIT_RTTIME to what RealtimeKit accepts
In the default configuration, PulseAudio's rlimit-rttime is set to
1000000 (100%), which is higher than what RealtimeKit requires from
its clients (200000, 20%).

Make an attempt to still get realtime scheduling by clamping the
current RLIMIT_RTTIME to what RealtimeKit accepts. Warn about doing
this.
2013-06-10 16:52:44 +03:00
Tanu Kaskinen
1fd79c4439 core-util: Don't accept random words in pa_parse_boolean()
The old code accepted any word that started with "y", "Y",
"n", "N", "t", "T", "f" or "F". Fix this by having
a whitelist of full strings instead of checking just the
first letter.
2013-06-04 00:38:40 +05:30
Arun Raghavan
4c23720ef1 pulsecore: Make run-from-build not readlink() on every call
Since this is no longer only defined in debug builds, let's make sure
that there is no impact if this is indavertently called repeatedly at
startup.
2013-04-20 10:12:34 +05:30
Arun Raghavan
ae559c0724 pulsecore: Don't conditionally inline pa_run_from_build_tree()
There's no good reason to assume an in-tree build will be debug-only.
This breaks alsa-mixer-path-test on make distcheck, for example.
2013-04-14 10:50:15 +05:30
Tanu Kaskinen
02d6aa6480 core-util: Improve get_path() documentation 2012-12-19 12:31:48 +02:00
Arun Raghavan
968c9c45ac core: Remove bad free() call
The string created when trying to use XDG_RUNTIME_DIR is freed before it
is used in a debug message, and is freed again.

https://bugs.freedesktop.org/show_bug.cgi?id=57280
2012-11-19 21:32:18 +05:30
Thomas Martitz
a8e7d8bc2c core-util: Don't error out on existing runtime directory.
When compiling without HAVE_SYMLINK the runtime dir is a real directory,
which is attempted to be created. In the case it already exists we shouldn't
error out. The HAVE_SYMLINK-enabled code already does this.
2012-10-30 16:22:30 +05:30
Arun Raghavan
6fe3bfe6df core: Fix warning on non-win32 builds 2012-10-29 17:49:00 +05:30
Flavio Ceolin
dd31d65217 utils: Adding a function to get volume from string
The allowed volume formats are dB, % or integer.
For example: 10% or 10db or 10.
2012-10-25 12:42:26 +03:00
Thomas Martitz
c327850d9e core: Transparently handle non-blocking sockets on Windows
On Windows, fdsem.c:flush() fails because sockets are set to non-blocking
mode, since pa_read() returns -1 (and errno == EWOULDBLOCK). I guess pa_read()
is expected to block in this case so make it actually block by calling poll().
2012-10-23 12:12:02 +05:30
Deng Zhengrong
9b80d1d14a core: add more verbose error info
I'm debugging an issue, and find that it's more useful for users to know which
directory hasn't been created instead of just knowing error code.
2012-07-17 11:12:53 +05:30
Arun Raghavan
1ff604c298 core-util: Fix permissions handling while creating directories
This makes updating of permissions on existing directories optional with
pa_make_secure_dir() and pa_make_secure_parent_dir(). This makes sure
that the recursive directory creation doesn't end up modifying existing
directories, and also fixes a problem where creating an auth cookie
(specifically ~/.esd_auth) would end up modifying permissions on ~.
Thanks to Frédéric Danis for reporting this.
2012-07-03 08:49:26 +05:30
Mihai Moldovan
56ce2c67c2 core-util: use the generic PATH_MAX variant of pa_realpath on Mac OS X
realpath() on OS X behaves GNUish and accepts NULL for resolved_name
only on 10.6 and higher. Older versions will crash, if resolved_name is
NULL.

All versions define PATH_MAX, though. Better play it safe and use the
generic PATH_MAX version of pa_realpath on Mac OS X systems.

Signed-off-by: Mihai Moldovan <ionic@ionic.de>
2012-06-16 10:34:41 +05:30
Arun Raghavan
59968f8e2c core-util: Make pa_make_secure_dir() act like mkdir -p
This makes pa_make_secure_dir() create any missing parent directories in
the given path as well. This is useful, for example, on a pristine
system with a clean $HOME that needs ~/.config/pulse/ to be created when
~/.config does not exist.
2012-06-13 16:37:20 +05:30
Arun Raghavan
b942af65fe core-util: Add a pa_split_in_place() string utility function
For specialised uses of pa_split() such as finding substrings for
comparison, this avoids the need to repeatedly allocate and deallocate
memory.
2012-06-13 16:37:20 +05:30
Arti Trivedi Bora
96a52257a9 pulsecore: Use pa_streq instead of strcmp. 2012-06-09 16:22:13 +03:00
Lennart Poettering
9ab510a692 core-util: when searching for configuration files, honour XDG basedir spec 2012-05-15 23:25:00 +02:00
Lennart Poettering
4c195bcc9d core-util: move configuration home directory from ~/,pulse to ~/.config/pulse to follow XDG basedir spec
If ~/.pulse/ already exists we stick to it in order not to lose
configuration and so that pulse configuration may still be shared across
the network with different PA versions.
2012-05-15 23:13:28 +02:00
Lennart Poettering
7fad67c461 util: hook up pa_get_runtime_dir() with XDG_RUNTIME_DIR 2012-05-15 19:06:53 +02:00
Lennart Poettering
bea524cb7a util: use the return value of gethosid() as fallback, not the address of the function
Yikes!
2012-05-15 14:13:19 +02:00
Lennart Poettering
10f146ddc8 util: /etc/machine-id should be tried first, the D-Bus only as fallback for legacy systems 2012-05-15 14:13:19 +02:00
Lennart Poettering
8a55219599 util: XDG_SESSION_COOKIE is unsuitable as session ID
XDG_SESSION_COOKIE was supposed to be used for access control to the
session and should not be exposed to other users.

Replace usage of XDG_SESSION_COOKIE by XDG_SESSION_ID which is the right
choice here since it is actually a proper session ID that may be
published.
2012-05-15 14:04:31 +02:00
Colin Guthrie
664985b7c2 core-util: Attempt to make runtime paths smaller to avoid 108 char limit.
When the runtime path gets long (which can happen on some NFS
mounts where $HOME is not just /home/$USER), it can grow
longer the 108 char limit imposed by sockaddr_un.sun_path.

This just calls realpath which should ultimately point into
/tmp in most cases and result in a much smaller path.

Only do this when we are adding on a name component to the
runtime path so creating the actual symlink will still get
the original, long name, but this shouldn't be a problem
as it never goes into the sockaddr_un.sun_path.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=44680
2012-03-28 11:17:29 +01:00
Peter Meerwald
49fd49f21f core: fix potential memory leak 2011-12-20 10:16:39 +05:30
Arun Raghavan
42881d2770 core: Look up /etc/machine-id if D-Bus machine-id is not found
It appears that this is currently the fallback for early boot and other
such cases where /var might not be available. Relevant upstream commit:

http://cgit.freedesktop.org/dbus/dbus/commit/?id=66e52541d5bdd4927a5c702963749760643313f4

Thanks to Samuli Suominen <ssuominen@gentoo.org> for pointing this out
in https://bugs.gentoo.org/show_bug.cgi?id=390287
2011-11-15 12:51:31 +05:30
Arun Raghavan
06fc121eef core: Add a string list membership check function
This adds a pa_str_in_list() to check for a given string in a
space-separated list of strings. For now, this is merely present to
avoid duplication of role matching code (intended roles can be a
space-separate list) across modules.
2011-10-28 15:21:09 +02:00
Maarten Bosmans
c5dca7cf2b More spelling fixes 2011-08-25 11:27:47 +01:00
Maarten Bosmans
5818a2c63e win32: Make some unused-variable warnings go away 2011-06-24 00:34:05 +01:00