Commit graph

314 commits

Author SHA1 Message Date
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
Lennart Poettering 266f3e269d bus-util: rename bus_open_transport() to bus_connect_transport()
In sd-bus, the sd_bus_open_xyz() family of calls allocates a new bus,
while sd_bus_default_xyz() family tries to reuse the thread's default
bus. bus_open_transport() sometimes internally uses the former,
sometimes the latter family, but suggests it only calls the former via
its name. Hence, let's avoid this confusion, and generically rename the
call to bus_connect_transport().

Similar for all related calls.

And while we are at it, also change cgls + cgtop to do direct systemd
connections where possible, since all they do is talk to systemd itself.
2015-09-29 21:55:52 +02:00
Lennart Poettering 3f6fd1ba65 util: introduce common version() implementation and use it everywhere
This also allows us to drop build.h from a ton of files, hence do so.
Since we touched the #includes of those files, let's order them properly
according to CODING_STYLE.
2015-09-29 21:08:37 +02: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
Lennart Poettering 75f86906c5 basic: rework virtualization detection API
Introduce a proper enum, and don't pass around string ids anymore. This
simplifies things quite a bit, and makes virtualization detection more
similar to architecture detection.
2015-09-07 13:42:47 +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
Thomas Hindoe Paaboel Andersen 7d6884b65e tree-wide: fix indentation 2015-08-06 00:44:19 +02: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
David Herrmann e7e55dbdc3 tree-wide: fix memory leaks in users of bus_map_all_properties()
If you use bus_map_all_properties(), you must be aware that it might
touch output variables even though it may fail. This is, because we parse
many different bus-properties and cannot tell how to clean them up, in
case we fail deep down in the parser.

Fix all callers of bus_map_all_properties() to correctly cleanup any
context structures at all times.
2015-06-14 15:08:52 +02:00
Torstein Husebø ff9b60f38b treewide: Correct typos and spell plural of bus consistent 2015-05-11 15:51:30 +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
Daniele Medri a1166fe970 language fallback: it_CH (Italian, Swiss) -> it_IT (Italian, Italy) 2015-02-09 07:39:24 +01:00
Piotr Drąg 2a7e23fbba Add Silesian and Kashubian to language fallback map
Silesian and Kashubian speakers would prefer to fall back to Polish (pl)
translations instead of English (C).

https://bugs.freedesktop.org/show_bug.cgi?id=89021
2015-02-07 11:55:48 -05: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
Naveen Kumar 757b23a6cd Add language fallback map
This map will be used to provide a fallback for translations.
For example, a Niederdeutsch (nds) speaker prefers to fall back to
German (de) translations rather then the English (C) ones.

https://bugzilla.redhat.com/show_bug.cgi?id=624158#c9
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
Mindaugas Baranauskas 534644b7be kbd-model-map: add more mappings for Slovak, Lithuanian, and Khmer
https://bugs.freedesktop.org/show_bug.cgi?id=88545
2015-01-22 01:14:54 -05: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 de33fc6257 sd-bus: rename sd_bus_open_system_container() to sd_bus_open_system_machine()
Pretty much everywhere else we use the generic term "machine" when
referring to containers in API, so let's do though in sd-bus too. In
particular, since the concept of a "container" exists in sd-bus too, but
as part of the marshalling system.
2014-12-24 16:53:04 +01: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
Zbigniew Jędrzejewski-Szmek 2ebcf93670 localectl,man: make it obvious that set-*-keymaps sets both keymaps
https://bugs.freedesktop.org/show_bug.cgi?id=85411
2014-12-11 00:02:54 -05: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 4a62c710b6 treewide: another round of simplifications
Using the same scripts as in f647962d64 "treewide: yet more log_*_errno
+ return simplifications".
2014-11-28 19:57:32 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +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 ff49bc3212 treewide: drop unnecessary trailing \n in log_*() calls 2014-11-28 14:26:31 +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
Jan Synacek 31cf921abb localectl: fix localectl set-x11-keymap syntax description
This complements the fix in:

    commit cd4c6fb125
    Author: Jan Synacek <jsynacek@redhat.com>
    Date:   Mon Oct 20 12:43:39 2014 +0200

        man: fix localectl set-x11-keymap syntax description
2014-11-04 08:27:30 +01:00
WaLyong Cho cc56fafeeb mac: rename apis with mac_{selinux/smack}_ prefix 2014-10-23 17:13:15 +02:00
Marko Myllynen 70ae006b43 fi-latin1 console keymap is no more
http://git.altlinux.org/people/legion/packages/kbd.git?p=kbd.git;a=commitdiff;h=a88711232f3216debbb02d0171187442863ccedb
2014-10-13 08:58:40 -04:00
Lennart Poettering b344bcbbfd localectl: always print warnings with log_warning() instead of printf()
They really should got to stderr, not stdout.
2014-10-02 14:39:07 +02:00
Lennart Poettering 63229aa1ab localectl: count locale variables from 0, instead of VARIABLE_LANG
That way the we make our code safe regarding reordering of the variables
in the enum.
2014-10-02 14:39:07 +02:00
Michal Sekletar a34286684e localectl: print warning when there are options given on kernel cmdline 2014-09-25 09:19:56 +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
Michal Schmidt d5099efc47 hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in
struct Hashmap separately. The functions always comprise a pair.
Store a single pointer to struct hash_ops instead.

systemd keeps hundreds of hashmaps, so this saves a little bit of
memory.
2014-09-15 16:08:50 +02: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
Lennart Poettering b5af2aca12 Merge commit 'b39a2770ba55637da80e2e389222c59dbea73507' 2014-08-15 20:25:10 +02:00
Lennart Poettering def9a7aa01 sd-bus: add API to check if a client has privileges
This is a generalization of the vtable privilege check we already have,
but exported, and hence useful when preparing for a polkit change.

This will deal with the complexity that on dbus1 one cannot trust the
capability field we retrieve via the bus, since it is read via
/proc/$$/stat (and thus might be out-of-date) rather than directly from
the message (like on kdbus) or bus connection (as for uid creds on
dbus1).

Also, port over all code to this new API.
2014-08-15 20:08:51 +02:00
Stef Walter 36e34057a2 sd-bus: Remove bus arg from bus_verify_polkit_async_registry_free()
It's unneccessary, not used, and complicates callers of the
function.
2014-08-15 14:07:07 +02:00
Lennart Poettering 249968612f bus: always explicitly close bus from main programs
Since b5eca3a205 we don't attempt to GC
busses anymore when unsent messages remain that keep their reference,
when they otherwise are not referenced anymore. This means that if we
explicitly want connections to go away, we need to close them.

With this change we will no do so explicitly wherver we connect to the
bus from a main program (and thus know when the bus connection should go
away), or when we create a private bus connection, that really should go
away after our use.

This fixes connection leaks in the NSS and PAM modules.
2014-08-04 16:25:24 +02:00
Zbigniew Jędrzejewski-Szmek 601185b43d Unify parse_argv style
getopt is usually good at printing out a nice error message when
commandline options are invalid. It distinguishes between an unknown
option and a known option with a missing arg. It is better to let it
do its job and not use opterr=0 unless we actually want to suppress
messages. So remove opterr=0 in the few places where it wasn't really
useful.

When an error in options is encountered, we should not print a lengthy
help() and overwhelm the user, when we know precisely what is wrong
with the commandline. In addition, since help() prints to stdout, it
should not be used except when requested with -h or --help.

Also, simplify things here and there.
2014-08-03 21:46:07 -04:00
Zbigniew Jędrzejewski-Szmek b2fadec604 Properly report invalid quoted strings
$ systemd-analyze verify trailing-g.service
[./trailing-g.service:2] Trailing garbage, ignoring.
trailing-g.service lacks ExecStart setting. Refusing.
Error: org.freedesktop.systemd1.LoadFailed: Unit trailing-g.service failed to load: Invalid argument.
Failed to create trailing-g.service/start: Invalid argument
2014-07-31 08:56:03 -04:00
Zbigniew Jędrzejewski-Szmek 3fb97a58fa Nuke update-kbd-map
Our version has evolved independently of the original table
in systemd-config-keyboard, so it cannot be ever regenerated from
original upstream. Remove script to avoid confusion.
2014-07-18 21:44:59 -04:00
Lennart Poettering 7568345034 shared: make timezone and locale enumeration and validation generic
This way we can reuse it other code thatn just localectl/localed +
timedatectl/timedated.
2014-07-07 15:25:55 +02:00
Lennart Poettering 717603e391 machinectl: show /etc/os-release information of container in status output 2014-07-03 17:54:24 +02:00
Michal Sekletar 387066c2e5 localed: consider an unset model as a wildcard 2014-07-02 16:11:50 +02:00
Lennart Poettering 19befb2d5f sd-bus: introduce sd_bus_slot objects encapsulating callbacks or vtables attached to a bus connection
This makes callback behaviour more like sd-event or sd-resolve, and
creates proper object for unregistering callbacks.

Taking the refernce to the slot is optional. If not taken life time of
the slot will be bound to the underlying bus object (or in the case of
an async call until the reply has been recieved).
2014-05-15 01:15:30 +02:00
Lennart Poettering 151b9b9662 api: in constructor function calls, always put the returned object pointer first (or second)
Previously the returned object of constructor functions where sometimes
returned as last, sometimes as first and sometimes as second parameter.
Let's clean this up a bit. Here are the new rules:

1. The object the new object is derived from is put first, if there is any

2. The object we are creating will be returned in the next arguments

3. This is followed by any additional arguments

Rationale:

For functions that operate on an object we always put that object first.
Constructors should probably not be too different in this regard. Also,
if the additional parameters might want to use varargs which suggests to
put them last.

Note that this new scheme only applies to constructor functions, not to
all other functions. We do give a lot of freedom for those.

Note that this commit only changes the order of the new functions we
added, for old ones we accept the wrong order and leave it like that.
2014-02-20 00:03:10 +01:00
Djalal Harouni 6046278f40 localectl: log error if bus_map_all_properties() fails 2014-02-14 02:19:42 +01:00
Lennart Poettering d14ab08b29 bus: fix a couple of format string mistakes 2013-12-28 15:09:26 +01:00
Lennart Poettering 37224a5ff5 bus: fix exit-on-idle for driverd 2013-12-19 22:18:39 +01:00
Lennart Poettering 6203e07a83 event: rework sd-event exit logic
With this change a failing event source handler will not cause the
entire event loop to fail. Instead, we just disable the specific event
source, log a message at debug level and go on.

This also introduces a new concept of "exit code" which can be stored in
the event loop and is returned by sd_event_loop(). We also rename "quit"
to "exit" everywhere else.

Altogether this should make things more robus and keep errors local
while still providing a way to return event loop errors in a clear way.
2013-12-13 04:06:43 +01:00
Kay Sievers 5bb658a178 bus: remove explicit activator-specific flags, the kdbus supports it now 2013-12-12 20:27:23 +01:00
Kay Sievers d90bb66996 bus: add SD_BUS_NAME_REPLACE_EXISTING to all activatable services, fix one flags conversion 2013-12-12 06:41:23 +01:00
Lennart Poettering 29a07cdb4a bus: instead of exposing the dbus1 flags when acquiring a name use our own that are closer to kdbus
This turns around DO_NOT_QUEUE into QUEUE which implies a more useful
default. (And negative options are awful anyway.)
2013-12-12 05:55:58 +01:00
Lennart Poettering cde93897cd event: hook up sd-event with the service watchdog logic
Adds a new call sd_event_set_watchdog() that can be used to hook up the
event loop with the watchdog supervision logic of systemd. If enabled
and $WATCHDOG_USEC is set the event loop will ping the invoking systemd
daemon right after coming back from epoll_wait() but not more often than
$WATCHDOG_USEC/4. The epoll_wait() will sleep no longer than
$WATCHDOG_USEC/4*3, to make sure the service manager is called in time.

This means that setting WatchdogSec= in a .service file and calling
sd_event_set_watchdog() in your daemon is enough to hook it up with the
watchdog logic.
2013-12-11 18:20:09 +01:00
Lennart Poettering adacb9575a bus: introduce "trusted" bus concept and encode access control in object vtables
Introduces a new concept of "trusted" vs. "untrusted" busses. For the
latter libsystemd-bus will automatically do per-method access control,
for the former all access is automatically granted. Per-method access
control is encoded in the vtables: by default all methods are only
accessible to privileged clients. If the SD_BUS_VTABLE_UNPRIVILEGED flag
is set for a method it is accessible to unprivileged clients too. By
default whether a client is privileged is determined via checking for
its CAP_SYS_ADMIN capability, but this can be altered via the
SD_BUS_VTABLE_CAPABILITY() macro that can be ORed into the flags field
of the method.

Writable properties are also subject to SD_BUS_VTABLE_UNPRIVILEGED and
SD_BUS_VTABLE_CAPABILITY() for controlling write access to them. Note
however that read access is unrestricted, as PropertiesChanged messages
might send out the values anyway as an unrestricted broadcast.

By default the system bus is set to "untrusted" and the user bus is
"trusted" since per-method access control on the latter is unnecessary.

On dbus1 busses we check the UID of the caller rather than the
configured capability since the capability cannot be determined without
race. On kdbus the capability is checked if possible from the attached
meta-data of a message and otherwise queried from the sending peer.

This also decorates the vtables of the various daemons we ship with
these flags.
2013-12-10 16:52:49 +00:00
Adam Williamson 18c92a4958 correct name of Tajik kbd layout in kbd-model-map 2013-12-10 05:16:46 -05:00
Adam Williamson 70dc36d17f drop several entries from kbd-model-map whose kbd layouts do not exist
kbd-model-map was generated from system-config-keyboard's keyboard_models.py.
Several of the kbd layouts referred in that file do not exist and, so far as I
can tell, never did. I believe these entries existed simply to provide the xkb
configuration information for those layouts, and there never were matching kbd
entries; the kbd names were entirely notional, to satisfy the need for some
entry or other in that field.

For systemd, the only function of kbd-model-map is to 'match' kbd and xkb
configurations, so it does not make any sense to maintain entries for cases
where only one or the other exists in this context.
2013-12-10 05:16:46 -05:00
Zbigniew Jędrzejewski-Szmek 2b6bf07dd2 Get rid of our reimplementation of basename
The only problem is that libgen.h #defines basename to point to it's
own broken implementation instead of the GNU one. This can be fixed
by #undefining basename.
2013-12-06 21:29:55 -05:00
Lennart Poettering e7176abbe8 bus: make sd_bus_request_name() and sd_bus_release_name() behave more like other calls
Instead of returning an enum of return codes, make them return error
codes like kdbus does internally.

Also, document this behaviour so that clients can stick to it.

(Also rework bus-control.c to always have to functions for dbus1 vs.
kernel implementation of the various calls.)
2013-12-03 18:02:46 +01:00
Lennart Poettering ebcf1f97de bus: rework message handlers to always take an error argument
Message handler callbacks can be simplified drastically if the
dispatcher automatically replies to method calls if errors are returned.

Thus: add an sd_bus_error argument to all message handlers. When we
dispatch a message handler and it returns negative or a set sd_bus_error
we send this as message error back to the client. This means errors
returned by handlers by default are given back to clients instead of
rippling all the way up to the event loop, which is desirable to make
things robust.

As a side-effect we can now easily turn the SELinux checks into normal
function calls, since the method call dispatcher will generate the right
error replies automatically now.

Also, make sure we always pass the error structure to all property and
method handlers as last argument to follow the usual style of passing
variables for return values as last argument.
2013-11-21 21:12:36 +01:00
Lennart Poettering df2d202e6e bus: let's simplify things by getting rid of unnecessary bus parameters 2013-11-21 02:07:35 +01:00
Zbigniew Jędrzejewski-Szmek 0732ef7acf localed: match converted keymaps before legacy
Before, X11 keymap fr-pc105-oss would be converted to fr,
even though fr-oss exists. Now, if
/usr/lib/kbd/keymaps/xkb/<layout>[-<variant>].map[.gz] exists,
<layout>[-<variant>] will be used as the console keymap,
falling back to the legacy mappings otherwise.

% sudo localectl set-x11-keymap pl pc105
% localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: pl                      (was pl2 before)
      X11 Layout: pl
       X11 Model: pc105
% sudo localectl set-x11-keymap fr pc105 oss
% localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: fr-oss                  (was fr before)
      X11 Layout: fr
       X11 Model: pc105
     X11 Variant: oss
% sudo localectl set-x11-keymap fr pc105
% localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: fr
      X11 Layout: fr
       X11 Model: pc105
% sudo localectl set-x11-keymap gb
% localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: gb                     (was uk before)
      X11 Layout: gb
2013-11-18 20:35:52 -05:00
Zbigniew Jędrzejewski-Szmek 98fce79dea localed: use _cleanup_ 2013-11-18 20:35:52 -05:00
Thomas Hindoe Paaboel Andersen d5d217eae1 remove unused variables 2013-11-18 23:04:16 +01:00
Lennart Poettering 76b543756e bus: introduce concept of a default bus for each thread and make use of it everywhere
We want to emphasize bus connections as per-thread communication
primitives, hence introduce a concept of a per-thread default bus, and
make use of it everywhere.
2013-11-12 00:12:43 +01:00
Lennart Poettering afc6adb5ec bus: introduce concept of a "default" event loop per-thread and make use of it everywhere
Try to emphasize a bit that there should be a mapping between event
loops and threads, hence introduce a logic that there's one "default"
event loop for each thread, that can be queried via
"sd_event_default()".
2013-11-12 00:12:43 +01:00
Lennart Poettering c49b30a235 bus: rename sd_bus_send_with_reply_and_block() to sd_bus_call()
The call is one of the most important ones we expose, where we place
major emphasis on. We should make sure to give it a short, memorable
name.
2013-11-12 00:12:43 +01:00
Lennart Poettering 94676f3e93 localectl: port over to bus_log_create_error() 2013-11-08 19:48:42 +01:00
Lennart Poettering a86a47ce1f clients: try to follow roughly the same order in --help texts for common options 2013-11-07 21:31:13 +01:00
Lennart Poettering 46e65dcc3a polkit: don't spawn local client if we access a remote system 2013-11-07 21:06:44 +01:00
Kay Sievers 102d8f8169 consistently use "int" when retrieving "bool" from bus messages 2013-11-07 02:05:57 +01:00
Lennart Poettering eb9da376d7 clients: unify how we invoke getopt_long()
Among other things this makes sure we always expose a --version command
and show it in the help texts.
2013-11-06 18:28:39 +01:00
Lennart Poettering 84f6181c2a clients: various simplifications 2013-11-06 17:32:51 +01:00
Kay Sievers 9f6eb1cd58 bus: update bus_map_all_properties() 2013-11-05 02:57:49 +01:00
Lennart Poettering 6d1bd3b2bb localed: mark bus properties as change emitting
Otherwise sd_bus_emit_properties_changed() will refuse sending out
change signals
2013-11-05 01:13:05 +01:00
Kay Sievers ffc06c3513 bus: use internal helper to read org.freedesktop.DBus.Properties::GetAll variables 2013-11-02 01:48:22 +01:00
Lennart Poettering e1636421f4 localectl: always print error message when an operation fails 2013-10-31 03:14:37 +01:00
Thomas Hindoe Paaboel Andersen 4b4bec1958 localectl: remove unused 'P' arg 2013-10-30 23:13:25 +01:00
Kay Sievers 4d7859d173 localectl: port to libsystemd-bus 2013-10-30 22:50:09 +01:00
Kay Sievers 8d45130966 localed: port from libdbus to libsystemd-bus 2013-10-22 13:25:17 +02:00
Kay Sievers ca2871d9b0 bus: remove static introspection file export 2013-10-21 00:41:26 +02:00
Zbigniew Jędrzejewski-Szmek b47d419c25 Modernization
Fixes minor leak in error path in device.c.
2013-10-13 17:56:54 -04:00
Michał Górny 4a9e80b3b5 Add /usr/share/keymaps to localectl supported locations.
This is the standard upstream location where kbd installs keymaps.
2013-08-01 00:09:58 +02:00
Daniel Wallace 7085053a43 Allow for the use of @ in remote host calls
Without this you have to use %40 with the -H flag because dbus doesn't
like the @ sign being unescaped.
2013-06-09 18:26:41 -04:00
Jan Janssen 546158bc6f Fix --no-ask-password
POSIX_ME_HARDER mode is disabled for localectl. It doesn't
make much sense in case of localectl, and there's little reason
for localectl to behave specially.
2013-05-23 00:28:04 -04:00
Jan Janssen 2927b326cc man: Document missing options 2013-05-21 09:23:51 -04:00
Zbigniew Jędrzejewski-Szmek ef42202ac8 Add set_consume which always takes ownership
Freeing in error path is the common pattern with set_put().
2013-04-24 00:25:04 -04:00
Harald Hoyer 7fd1b19bc9 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-18 09:11:22 +02:00
Lennart Poettering c62e11ce39 localectl: read X11 keymaps from the correct file
As reported by Sergey Udaltsov.
2013-04-15 01:30:21 +02:00
Zbigniew Jędrzejewski-Szmek 7914d6bba4 Remove a few NULLs
Just {} is used in a lot of places now, and there's nothing
special abose those few.
2013-04-13 20:24:39 -04:00
Lennart Poettering 0affed79d2 localctl: skip locale entries with non-UTF8 names
glibc should place these in the locale archive. For now, let's just skip
them from our output, since they are aliases anyway.

https://bugs.freedesktop.org/show_bug.cgi?id=63389
2013-04-10 23:23:19 +02:00
Zbigniew Jędrzejewski-Szmek b92bea5d2a Use initalization instead of explicit zeroing
Before, we would initialize many fields twice: first
by filling the structure with zeros, and then a second
time with the real values. We can let the compiler do
the job for us, avoiding one copy.

A downside of this patch is that text gets slightly
bigger. This is because all zero() calls are effectively
inlined:

$ size build/.libs/systemd
         text    data     bss     dec     hex filename
before 897737  107300    2560 1007597   f5fed build/.libs/systemd
after  897873  107300    2560 1007733   f6075 build/.libs/systemd

… actually less than 1‰.

A few asserts that the parameter is not null had to be removed. I
don't think this changes much, because first, it is quite unlikely
for the assert to fail, and second, an immediate SEGV is almost as
good as an assert.
2013-04-05 19:50:57 -04:00
Lennart Poettering 50cfc57928 localectl: add support for listing X11 keymap information 2013-04-05 00:23:23 +02:00
Lennart Poettering f73141d765 shared: rework env file reader
Implement this with a proper state machine, so that newlines and
escaped chars can appear in string assignments. This should bring the
parser much closer to shell.
2013-04-03 20:12:57 +02:00
Zbigniew Jędrzejewski-Szmek 8333c77edf Always use errno > 0 to help gcc
gcc thinks that errno might be negative, and functions could return
something positive on error (-errno). Should not matter in practice,
but makes an -O4 build much quieter.
2013-03-29 10:12:41 -04:00
Colin Walters c6a818c820 Use bus_maybe_send_reply() where applicable
This is a followup to: commit 1a37b9b904

It will fix denial messages from dbus-daemon between gdm and
systemd-logind on logging into GNOME due to this.

See the previous commit for more details.
2013-03-18 19:59:32 -04:00
Harald Hoyer 1b12a7b589 pager: introduce "jump to end" option
$ journalctl -be

is what you want :)

https://bugzilla.redhat.com/show_bug.cgi?id=867841
2013-03-07 21:16:04 +01:00
Harald Hoyer a5c32cff1f honor SELinux labels, when creating and writing config files
Also split out some fileio functions to fileio.c and provide a SELinux
aware pendant in fileio-label.c

see https://bugzilla.redhat.com/show_bug.cgi?id=881577
2013-02-14 16:19:38 +01:00
Thomas Hindoe Paaboel Andersen 641906e936 use strneq instead of strncmp 2013-02-13 00:56:13 +01:00
Lennart Poettering 82c1d8f4eb localectl: fix --help text
https://bugs.freedesktop.org/show_bug.cgi?id=60595
2013-02-12 00:34:41 +01:00
Lennart Poettering 4d1a690438 env: considerably beef up environment cleaning logic
Now, actually check if the environment variable names and values used
are valid, before accepting them. With this in place are at some places
more rigid than POSIX, and less rigid at others. For example, this code
allows lower-case environment variables (which POSIX suggests not to
use), but it will not allow non-UTF8 variable values.

All in all this should be a good middle ground of what to allow and what
not to allow as environment variables.

(This also splits out all environment related calls into env-util.[ch])
2013-02-11 03:54:50 +01:00
Thomas Hindoe Paaboel Andersen 7c2d80944a strv: add strv_print
Clearer, and spares the temp variable.
2013-02-07 00:38:09 +01:00
Lennart Poettering 65426b7632 locale: make sense of "dvorak-alt-intel" X variant in mapping database
https://bugzilla.redhat.com/show_bug.cgi?id=873634
2013-01-14 18:24:00 +01:00
Zbigniew Jędrzejewski-Szmek bac3c8eefe localectl: use automatic cleanup
set_freep() is added to automatize set_free().
2013-01-07 11:43:41 -05:00
Giovanni Campagna 17d33cecaa localectl: support systems without locale-archive
Not all systems ships with locales inside /usr/lib/locale-archive, some
prefer to have locale data as individual subdirectories of /usr/lib/locale.
(A notable example of this is OpenEmbeddded, and OSes deriving from it
like gnome-ostree).
Given that glibc supports both ways, localectl should too.
2013-01-07 15:31:17 +01:00
Zbigniew Jędrzejewski-Szmek c4eb236a2c build-sys: invoke scripts with $PYTHON during build
Python binary to be used during compilation can be set with
./configure PYTHON=...

The she-bang line is removed, since it is not used anymore.
2013-01-04 22:22:21 -05:00
Lennart Poettering bc2708414b build-sys: drop all distribution specfic checks
Yay, we now have a completely generic systemd. No distribution specific checks anymore!
2013-01-04 23:26:21 +01:00
Michał Bartoszkiewicz 9a9bb3ca1e localed: create /etc/X11/xorg.conf.d if needed
Use mkdir_p_label instead of mkdir_parents_label, so that the final
directory component is created too.
2013-01-04 00:26:27 +01:00
Adam Williamson 768aa35871 correct Macedonian keyboard mapping (X layout is 'mk', not 'mkd') 2013-01-03 23:10:07 +01:00
Adam Williamson 12939e7217 add Lithuanian keyboard mapping (lt/lt) 2013-01-03 23:09:59 +01:00
Adam Williamson 177c11eddf add Kazakh keyboard mapping (kazakh/kz) 2013-01-03 23:09:51 +01:00
Adam Williamson 2eaaf10fe0 add Hebrew (Israel) - simple, il/il 2013-01-03 23:09:37 +01:00
Adam Williamson fa593cfd87 French Canadian xlayout is just "ca", not "ca(fr)" any more 2013-01-03 23:09:27 +01:00
Adam Williamson 40b5bbb91e add Belarussian mapping: simple, 'by' and 'by' 2013-01-03 23:09:09 +01:00
Lennart Poettering 3960015566 polkit: add "imply" rules to a number of polkit actions 2012-12-31 21:24:26 +01:00
Michal Schmidt 6b2b6f30e3 localectl: fix dbus call arguments in set_x11_keymap
Fixes an assertion failure in the dbus lib.
https://bugzilla.redhat.com/show_bug.cgi?id=882212
2012-12-12 22:29:06 +01:00
Dave Reisner a9cdc94f7f enable localization for common *ctl commands 2012-11-12 14:16:07 -05:00
Michal Sekletar 7ca7021a9e localectl: fix memleak, use _cleanup_strv_free_
l might contain zero strings, however there is still memory
allocated for NULL terminator, use _cleanup_strv_free_ instead to
prevent tiny leak in such case.
2012-10-28 02:14:41 +02:00
Michal Sekletar 2f7a4867ba localectl: fix memleak, jump to finish before returning 2012-10-28 02:14:40 +02:00
Lennart Poettering 2087a7aff2 locale: add client tool localectl similar to hostnamectl/timedatectl 2012-10-19 04:55:49 +02:00
Lennart Poettering 0b507b17a7 dbus: add some more safety checks before accepting data from bus clients 2012-10-03 13:29:20 -04:00
Václav Pavlín f2cc3753ce locale: make sure that l is freed 2012-09-21 16:10:34 +02:00
Lennart Poettering f687b27382 localed: system-setup-keyboard is no more on fedora 2012-09-05 23:54:09 -07:00
Shawn Landden 0d0f0c50d3 log.h: new log_oom() -> int -ENOMEM, use it
also a number of minor fixups and bug fixes: spelling, oom errors
that didn't print errors, not properly forwarding error codes,
few more consistency issues, et cetera
2012-07-26 11:48:26 +02:00
Shawn Landden 669241a076 use "Out of memory." consistantly (or with "\n")
glibc/glib both use "out of memory" consistantly so maybe we should
consider that instead of this.

Eliminates one string out of a number of binaries. Also fixes extra newline
in udev/scsi_id
2012-07-25 11:23:57 +02:00
Kay Sievers d2e54fae5c mkdir: append _label to all mkdir() calls that explicitly set the selinux context 2012-05-31 12:40:20 +02:00
Lennart Poettering 5430f7f2bc relicense to LGPLv2.1 (with exceptions)
We finally got the OK from all contributors with non-trivial commits to
relicense systemd from GPL2+ to LGPL2.1+.

Some udev bits continue to be GPL2+ for now, but we are looking into
relicensing them too, to allow free copy/paste of all code within
systemd.

The bits that used to be MIT continue to be MIT.

The big benefit of the relicensing is that closed source code may now
link against libsystemd-login.so and friends.
2012-04-12 00:24:39 +02:00
Kay Sievers 49e942b2bc rename basic.la to shared.la and put selinux deps in shared-selinx.la
Only 34 of 74 tools need libselinux linked, and libselinux is a pain
with its unconditional library constructor.
2012-04-10 22:43:05 +02:00
Lennart Poettering 89f134406a logind: introduce CanReboot/CanPowerOff bus calls 2012-02-11 00:13:10 +01:00
Kay Sievers 131a4dcfd4 login: move seat udev rules to login subdir 2012-01-22 18:32:13 +01:00
Michal Schmidt d200735e13 dbus: more efficient implementation of properties
The way the various properties[] arrays are initialized is inefficient:
 - only the .data members change at runtime, yet the whole arrays of
   properties with all the fields are constructed on the stack one by
   one by the code.
 - there's duplication, eg. the properties of "org.freedesktop.systemd1.Unit"
   are repeated in several unit types.

Fix it by moving the information about properties into static const
sections. Instead of storing the .data directly in the property, store
a constant offset from a run-time base.
The small arrays of struct BusBoundProperties bind together the constant
information with the right runtime information (the base pointer).

On my system the code shrinks by 60 KB, data increases by 10 KB.
2012-01-16 13:34:42 +01:00
Lennart Poettering 2f9dec073b build-sys: add stub makefiles to subdirs 2012-01-05 16:29:21 +01:00
Lennart Poettering 776a564f54 build-sys: move kbd-model-map to locale/ 2012-01-03 21:08:57 +01:00
Kay Sievers 681cfc6c40 hostnamed, localed: move config files to subdir 2011-12-31 07:23:57 +01:00
Kay Sievers 1822350db1 localed: move sources to subdirectory 2011-12-31 06:50:34 +01:00