Commit Graph

100 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Zbigniew Jędrzejewski-Szmek 032b75419d basic/log: fix _printf_ annotation on log_object_internalv
Fixup for 4b58153dd2.

I saw this because of a clang warning. With gcc the -Wformat-nonliteral warning
doesn't seem to work as expected.

In two places, a string constructed with strjoina is used as the pattern. This
is safe, because we're taking a pattern which was already marked with _printf_
and prepending a known value to it.  Those places are marked with #pragma to
silence the warning.
2017-04-20 14:42:43 -04:00
Zbigniew Jędrzejewski-Szmek 048c386eee tree-wide: use %m in calls to sd_bus_error_set_errnof
sd_bus_error_set_errnof supports %m, so there's no need to call
strerror manually.
2016-09-13 20:10:57 -04:00
Zbigniew Jędrzejewski-Szmek 4897d1dc0f localed: split out keymap parsing to a separate file
This way the dbus and management logic is seperated from the business logic
and we can write test cases for the mapping functionality.
2016-06-06 09:22:33 -04:00
Zbigniew Jędrzejewski-Szmek 78c97cbe74 localed: get rid of duplicated enum and string table 2016-06-06 08:34:23 -04:00
Lennart Poettering 3c6f7c3402 util-lib: make localed's nonempty() generic, rename it to empty_to_null() and make use of it everywhere 2016-05-30 17:59:43 +02:00
Lennart Poettering 5de344704d localed: downgrade libxkbcommon to an optional runtime dependency
Previously, libxkbcommon was a compile-time option. When enabled the localed
binary would strictly depend on it, thus pulling in libxkbcommon and its
dependencies, which are non-trivial in size.

With this change we dlopen() libxkbcommon when it is available instead. If the
library is available behaviour is as before. However, if it isn't the system is
considered "headless", i.e. without local hardware and all attempts to set the
local keyboard configuration will be refused.

This is useful for general-purpose distributions which want to support
"headless" (such as container systems) and "full" systems with the same build.
2016-04-12 13:43:31 +02:00
Zbigniew Jędrzejewski-Szmek c3dacc8bbf selinux: always try to load the full selinux db
https://github.com/systemd/systemd/pull/2508#issuecomment-190901170
Maybe fixes https://bugzilla.redhat.com/show_bug.cgi?id=1308771.
2016-03-01 20:39:30 -05:00
Vito Caputo 313cefa1d9 tree-wide: make ++/-- usage consistent WRT spacing
Throughout the tree there's spurious use of spaces separating ++ and --
operators from their respective operands.  Make ++ and -- operator
consistent with the majority of existing uses; discard the spaces.
2016-02-22 20:32:04 -08:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Zbigniew Jędrzejewski-Szmek f5e5c28f42 tree-wide: check if errno is greater then zero
gcc is confused by the common idiom of
  return errno ? -errno : -ESOMETHING
and thinks a positive value may be returned. Replace this condition
with errno > 0 to help gcc and avoid many spurious warnings. I filed
a gcc rfe a long time ago, but it hard to say if it will ever be
implemented [1].

Both conventions were used in the codebase, this change makes things
more consistent. This is a follow up to bcb161b023.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61846
2016-01-13 15:09:55 -05:00
Lennart Poettering 4afd3348c7 tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.

With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.

The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).

This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.

Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:

       #define _cleanup_(function) __attribute__((cleanup(function)))

Or similar, to make the gcc feature easier to use.

Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.

See #2008.
2015-11-27 19:19:36 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering ee104e11e3 user-util: move UID/GID related macros from macro.h to user-util.h 2015-10-27 13:25:57 +01:00
Lennart Poettering bb15fafe9c util: move filename_is_valid() and path_is_safe() to path-util.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Daniel Mack 87699fe313 locale: kill free_and_replace()
That function really makes little sense, as the open-coded variant
is much more readable. Also, if the 2nd argument is NULL, mfree()
is a much better candidate.

Convert the only users of this function in localed, and then remove it
entirely.
2015-09-09 15:15:14 +02:00
Michael Chapman 403ed0e5c9 bus-util: support details in CheckAuthorization calls
Extra details for an action can be supplied when calling polkit's
CheckAuthorization method. Details are a list of key/value string pairs.
Custom policy can use these details when making authorization decisions.
2015-09-06 00:07:16 +10:00
Cristian Rodríguez 3cb063fdb2 locale: add printf attribute to log_xkb() 2015-08-30 19:21:31 -03:00
Richard Maw 8adaf7bd23 strv: convert strv_split_quotes into a generic strv_split_extract
strv_split_extract is to strv_split_quotes as extract_first_word was to
unquote_first_word.

Now there's extract_first_word for extracting a single argument,
extract_many_words for extracting a bounded number of arguments,
and strv_split_extract for extracting an arbitrary number of arguments.
2015-08-07 15:50:43 +00:00
Zbigniew Jędrzejewski-Szmek 73974f6768 Merge branch 'hostnamectl-dot-v2'
Manual merge of https://github.com/systemd/systemd/pull/751.
2015-08-05 21:02:41 -04:00
Zbigniew Jędrzejewski-Szmek 8fb4944358 hostname-util: add relax parameter to hostname_is_valid
Tests are modified to check behaviour with relax and without relax.
New tests are added for hostname_cleanup().
Tests are moved a new file (test-hostname-util) because there's
now a bunch of them.

New parameter is not used anywhere, except in tests, so there should
be no observable change.
2015-08-05 20:49:20 -04:00
Lennart Poettering dacd6cee76 tree-wide: port everything over to fflush_and_check()
Some places invoked fflush() directly with their own manual error
checking, let's unify all that by using fflush_and_check().

This also unifies the general error paths of fflush()+rename() file
writers.
2015-07-29 20:31:07 +02:00
Lennart Poettering 03976f7b4a sd-bus: introduce new sd_bus_flush_close_unref() call
sd_bus_flush_close_unref() is a call that simply combines sd_bus_flush()
(which writes all unwritten messages out) + sd_bus_close() (which
terminates the connection, releasing all unread messages) +
sd_bus_unref() (which frees the connection).

The combination of this call is used pretty frequently in systemd tools
right before exiting, and should also be relevant for most external
clients, and is hence useful to cover in a call of its own.

Previously the combination of the three calls was already done in the
_cleanup_bus_close_unref_ macro, but this was only available internally.

Also see #327
2015-07-03 19:49:03 +02:00
Lennart Poettering 190700621f sd-bus: drop bus parameter from message callback prototype
This should simplify the prototype a bit. The bus parameter is redundant
in most cases, and in the few where it matters it can be derived from
the message via sd_bus_message_get_bus().
2015-04-29 18:36:25 +02:00
Lennart Poettering 4034a06ddb util: rework word parsing and c unescaping code
When parsing words from input files, optionally automatically unescape
the passed strings, controllable via a new flags parameter.

Make use of this in tmpfiles, and port everything else over, too.

This improves parsing quite a bit, since we no longer have to process the
same string multiple times with different calls, where an earlier call
might corrupt the input for a later call.
2015-03-26 11:56:22 +01:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Lennart Poettering c529695e7a logind: open up most bus calls for unpriviliged processes, using PolicyKit
Also, allow clients to alter their own objects without any further
priviliges. i.e. this allows clients to kill and lock their own sessions
without involving PK.
2015-02-18 12:55:25 +01:00
Zbigniew Jędrzejewski-Szmek 4e829d218c localed: add LANGUAGE= fallback when LANG= is specified
For the entries listed in the first column of language-fallback-map,
the entry from the second column will be used for LANGUAGE=, if
LANGUAGE= is not explicitly specified.

https://bugzilla.redhat.com/show_bug.cgi?id=624158
2015-02-06 09:13:12 -05:00
Lennart Poettering 63c372cb9d util: rework strappenda(), and rename it strjoina()
After all it is now much more like strjoin() than strappend(). At the
same time, add support for NULL sentinels, even if they are normally not
necessary.
2015-02-03 02:05:59 +01:00
Lennart Poettering d7b8eec7dc tmpfiles: add new line type 'v' for creating btrfs subvolumes 2014-12-28 02:08:40 +01:00
Filipe Brandenburger 8ea763865f localed: remove spurious include of <sys/capability.h>
It does not use any functions from libcap directly. The CAP_SYS_ADMIN constant
in use by this file comes from <linux/capability.h> imported through "missing.h".

Tested that "systemd-localed" builds cleanly and works after this change.
2014-12-25 10:57:08 -05:00
Lennart Poettering ae6c3cc009 util: when using basename() for creating temporary files, verify the resulting name is actually valid
Also, rename filename_is_safe() to filename_is_valid(), since it
actually does a full validation for what the kernel will accept as file
name, it's not just a heuristic.
2014-12-12 13:35:32 +01:00
Jan Synacek 8433e33955 localed: log xkbcommon errors
The errors are prefixed with "libxkbcommon" to provide some context,
because they are quite confusing without it. With the prefix, we at
least know where they come from.
2014-12-03 18:11:31 +01:00
Michal Schmidt f647962d64 treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
 'local $/;
  local $_=<>;
  s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
  print;'
 $f
done

And a couple of manual whitespace fixups.
2014-11-28 18:56:16 +01:00
Michal Schmidt c33b329709 treewide: more log_*_errno() conversions, multiline calls
Basically:

find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
'local $/;
 local $_=<>;
 s/log_(debug|info|notice|warning|error|emergency)\("([^"]*)%s"([^;]*),\s*strerror\(-?([->a-zA-Z_]+)\)\);/log_\1_errno(\4, "\2%m"\3);/gms;print;' \
 $f; done

Plus manual indentation fixups.
2014-11-28 17:17:51 +01:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +01:00
David Herrmann 8623d3a3b2 localed: verify xkb keymaps after pk-queries
Make sure not to run xkb-keymap validation twice if pk-queries are used.
Move it below pk-checks.
2014-11-25 10:26:08 +01:00
David Herrmann d4f5a1f47d localed: validate xkb keymaps
Introduce a new optional dependency on libxkbcommon for systemd-localed.
Whenever the x11 keymap settings are changed, use libxkbcommon to compile
the keymap. If the compilation fails, print a warning so users will get
notified.

On compilation failure, we still update the keymap settings for now. This
patch just introduces the xkbcommon infrastructure to have keymap
validation in place. We can later decide if/how we want to enforce this.
2014-11-24 15:16:33 +01:00
Lennart Poettering f88e6be5ee strv: rework strv_split_quoted() to use unquote_first_word()
This should make the unquoting scheme a bit less naive.
2014-11-10 23:45:12 +01:00
WaLyong Cho cc56fafeeb mac: rename apis with mac_{selinux/smack}_ prefix 2014-10-23 17:13:15 +02:00
Zbigniew Jędrzejewski-Szmek e78af5ffe5 localed: rename write_data_x11 to x11_write_data
Other functions in this file follow this pattern,
we have vconsole_write_data and locale_write_data.
2014-09-23 09:24:15 -04:00
Zbigniew Jędrzejewski-Szmek 78bd12a05a localed: check for partially matching converted keymaps
If a user specifies multiple X11 keymaps, with a (at least the first
one) nonempty variant, and we don't match the whole combo, use
a converted keymap which includes the variant in preference to
the default, variantless, keymap.

E.g.: We would convert X11 config "layout=fr variant=mac" to "fr-mac",
but "layout=fr,us variant=mac," to "fr", because we don't have a
converted keymap which would match "fr,us", and we don't have a legacy
mapping for "fr,us". This is unexpected, and if we cannot match both,
it is still better to match the primary mapping and use "fr-mac".
2014-09-03 22:55:54 -04:00
Zbigniew Jędrzejewski-Szmek 81fd105a5f localed: introduce helper function to simplify matching 2014-09-03 22:55:52 -04:00
Zbigniew Jędrzejewski-Szmek 502f961425 localed: log locale/keymap changes in detail
Converting X11 to legacy keymaps and back is a fucking mess. Let's
make it at least possible to request detailed logs of what is being
changed and why (LOG_DEBUG level).

At LOG_INFO level, we would log the requested change of X11 or console
keymap, but not the resulting change after conversion to console or X11.
Make sure that every change of configuration on disk has a matching
line in the logs.
2014-09-03 22:55:16 -04:00
Zbigniew Jędrzejewski-Szmek af76d302c1 localed: remove free_and_copy
It was mostly a duplicate of free_and_strdup().
2014-09-03 22:53:23 -04:00
Zbigniew Jędrzejewski-Szmek 28efac0d37 localed: double free in error path and modernization
Very unlikely to trigger, but in principle strv_free
could be called twice: once explictly, and once from cleanup.
2014-09-03 14:47:02 -04:00
David Herrmann c168eb6785 locale: fix sending PropertiesChanged for x11 keymap changed
The sd_bus_emit_properties_changed() call for x11 keymap changes lacks
commas.. whoops. Fix it! Now localed emits PropertiesChanged signals
again.
2014-08-28 15:25:51 +02:00
Lennart Poettering f38857914a bus-util: simplify bus_verify_polkit_async() a bit
First, let's drop the "bus" argument, we can determine it from the
message anyway.

Secondly, determine the right callback/userdata pair automatically from
what is currently is being dispatched. This should simplify things a lot
for us, since it makes it unnecessary to pass pointers through the
original handlers through all functions when we process messages, which
might require authentication.
2014-08-18 17:49:53 +02:00