summaryrefslogtreecommitdiff
path: root/src/basic
AgeCommit message (Collapse)Author
2015-08-26basic: document that people shouldn't use refcnt.h without reasonLennart Poettering
refcnt.h only exists for cases where objects are simultaneously handled by different threads. Otherwise it should not be used. The only case where this applies is sd_bus, really, and pretty much none of our APIs, since we do not claim thread-safety for them.
2015-08-26time-util: add new get_timezone() call to get local timezoneLennart Poettering
Let's move the timedated-specific code to time-util.h and make it generic.
2015-08-24machined: introduce pseudo-machine ".host" refererring to the host systemLennart Poettering
Some of the operations machined/machinectl implement are also very useful when applied to the host system (such as machinectl login, machinectl shell or machinectl status), hence introduce a pseudo-machine by the name of ".host" in machined that refers to the host system, and may be used top execute operations on the host system with. This copies the pseudo-image ".host" machined already implements for image related commands. (This commit also adds a PK privilege for opening a PTY in a container, which was previously not accessible for non-root.)
2015-08-24machined: validate machine names at more placesLennart Poettering
When enumerating machines from /run, and when accepting machine names for operations, be more strict and always validate. Note that these checks are strictly speaking unnecessary, since enumeration happens only on the trusted /run...
2015-08-24util: make machine_name_is_valid() a macro and move it to hostname-util.hLennart Poettering
As it turns out machine_name_is_valid() does the exact same thing as hostname_is_valid() these days, as it just invoked that and checked the name length was < 64. However, hostname_is_valid() checks the length against HOST_NAME_MAX anyway (which is 64 on Linux), hence any additional check is redundant. We hence replace machine_name_is_valid() by a macro that simply maps it to hostname_is_valid() but sets the allow_trailing_dot parameter to false. We also move this this call to hostname-util.h, to the same place as the hostname_is_valid() declaration.
2015-08-24util: make hostname_is_valid() easier to readLennart Poettering
Add more comments, and rename some parameters and variables to be more expressive.
2015-08-21hostname-util: introduce new is_gateway_hostname() callLennart Poettering
This moves is_gateway() from nss-myhostname into the basic APIs, and makes it more like is_localhost(). Also, we rename it to is_gateway_hostname() to make it more expressive. Sharing this function in src/basic/ allows us to reuse the function for routing name requests in resolved (in a later commit).
2015-08-17Merge pull request #977 from richardmaw-codethink/machinectl-userns-login-v2Lennart Poettering
Fix machinectl login with containers in user namespaces (v2)
2015-08-17namespace helpers: Allow entering a UID namespaceRichard Maw
To be able to use `systemd-run` or `machinectl login` on a container that is in a private user namespace, the sub-process must have entered the user namespace before connecting to the container's D-Bus, otherwise the UID and GID in the peer credentials are garbage. So we extend namespace_open and namespace_enter to support UID namespaces, and we enter the UID namespace in bus_container_connect_{socket,kernel}. namespace_open will degrade to a no-op if user namespaces are not enabled in the kernel. Special handling is required for the setns call in namespace_enter with a user namespace, since transitioning to your own namespace is forbidden, as it would result in re-entering your user namespace as root. Arguably it may be valid to check this at the call site, rather than inside namespace_enter, but it is less code to do it inside, and if the intention of calling namespace_enter is to *be* in the target namespace, rather than to transition to the target namespace, it is a reasonable approach. The check for whether the user namespace is the same must happen before entering namespaces, as we may not be able to access /proc during the intermediate transition stage. We can't instead attempt to enter the user namespace and then ignore the failure from it being the same namespace, since the error code is not distinct, and we can't compare namespaces while mid-transition.
2015-08-16Merge pull request #908 from richardmaw-codethink/nspawn-path-escapes-v3Lennart Poettering
Allow arbitrary file paths to be passed to nspawn (v3)
2015-08-11 sd-bus: do not connect to dbus-1 socket when kdbus is availableKay Sievers
We should not fall back to dbus-1 and connect to the proxy when kdbus returns an error that indicates that kdbus is running but just does not accept new connections because of quota limits or something similar. Using is_kdbus_available() in libsystemd/ requires it to move from shared/ to libsystemd/. Based on a patch from David Herrmann: https://github.com/systemd/systemd/pull/886
2015-08-07strv: Add strv_shell_escapeRichard Maw
This modifies the strv in-place, replacing strings with their escaped version. It's mostly just a convenience function for when you need to join a strv together because it's passed as a string to something, and the separator needs escaping.
2015-08-07util: Add shell_escapeRichard Maw
This is for shell-style \ escaping rather than quoting, which while it has the same effect in produced shell commands, is not exclusively useful for shell commands. shell_escape would be useful for producing sed commands, as you would be able to \ escape the normal special characters, plus whichever argument separator was chosen; or it could be used to escape arguments passed to the overlayfs mount command.
2015-08-07strv: convert strv_split_quotes into a generic strv_split_extractRichard Maw
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-07util: Allow non-separator coalescing parsing in extract_first_wordRichard Maw
If EXTRACT_DONT_COALESCE_SEPARATORS is passed, then leading separators, trailing separators and spans of multiple separators aren't skipped, and empty arguments from before, after or between separators may be extracted.
2015-08-07util: Don't interpret quotes by default in extract_first_wordRichard Maw
This adds an EXTRACT_QUOTES option to allow the previous behaviour, of not interpreting any character inside ' or " quotes as separators.
2015-08-07util: change unquote_*_word to extract_*_wordRichard Maw
It now takes a separators argument, which defaults to WHITESPACE if NULL is passed.
2015-08-07unquote_first_word: set *p=NULL on terminationRichard Maw
To add a flag to allow an empty string to be parsed as an argument, we need to be able to distinguish between the end of the string, and after the end of the string, so when we *do* reach the end, let's set *p to this state.
2015-08-05Merge branch 'hostnamectl-dot-v2'Zbigniew Jędrzejewski-Szmek
Manual merge of https://github.com/systemd/systemd/pull/751.
2015-08-05hostname-util: ignore case when checking if hostname is localhostZbigniew Jędrzejewski-Szmek
2015-08-05hostname-util: get rid of unused parameter of hostname_cleanup()Zbigniew Jędrzejewski-Szmek
All users are now setting lowercase=false.
2015-08-05hostname-util: add relax parameter to hostname_is_validZbigniew Jędrzejewski-Szmek
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-05Merge pull request #877 from crawford/dhcp-private-options-v4Lennart Poettering
networkd: save private-zone DHCP options
2015-08-04Use getxpid syscall on alpha for raw_getpid()Matt Turner
Alpha does not have a getpid syscall, but rather has getxpid to match OSF/1.
2015-08-04smack-util: revise smack-util apis and add read smack attr apisWaLyong Cho
- Add smack xattr lookup table - Unify all of mac_smack_apply_xxx{_fd}() to mac_smack_apply() and mac_smack_apply_fd(). - Add smack xattr read apis similar with apply apis as mac_smack_read{_fd}().
2015-08-04util: add getxattr helper apisWaLyong Cho
To get xattr of given path or fd on newly allocated buffer, add new helper api getxattr_malloc() and fgetxattr_malloc().
2015-08-04basic: add LIST_INSERT_BEFOREAlex Crawford
Similar in function to LIST_INSERT_AFTER, this will insert a new element into the list before the specified position. If the specified position is NULL, the element is added as the tail of the list.
2015-08-03Merge pull request #845 from poettering/terminal-o-nonblockDaniel Mack
add O_NONBLOCK to terminal handling
2015-08-03tree-wide: convert some more mfree() candidatesDaniel Mack
2015-08-03terminal-util: no real reason to assert on O_CREATLennart Poettering
That's just handle this as a normal error.
2015-08-03terminal-util: cast a couple of ioctl()s to voidLennart Poettering
2015-08-03terminal-util: when resetting terminals, don't wait for carrierLennart Poettering
In case of non-CLOCAL lines (i.e. those with carrier detect configured) we shouldnt wait for a carrier if all we try to do is reset the TTY. Hence, whenever we open such a TTY pass O_NONBLOCK. Note that we continue to open ttys we intend to write to without O_ONBLOCK, we only add it in cases we invoke ioctl()s or other terminal operations without reading or writing to the device. Fixes #835.
2015-07-31Merge pull request #814 from dvdhrm/mfreeDaniel Mack
tree-wide: introduce mfree()
2015-07-31tree-wide: introduce mfree()David Herrmann
Pretty trivial helper which wraps free() but returns NULL, so we can simplify this: free(foobar); foobar = NULL; to this: foobar = mfree(foobar);
2015-07-31Merge pull request #811 from namhyung/busctl-misc-v2Daniel Mack
busctl: Misc cleanups and a fix (v2)
2015-08-01busctl: add and use strcmp_ptr()Namhyung Kim
In member_compare_func(), it compares interface, type and name of members. But as it can contain NULL pointer, it needs to check them before calling strcmp(). So make it as a separate strcmp_ptr function (named after streq_ptr) so that it can be used by others. Also let streq_ptr() to use it in order to make the code simpler.
2015-07-31bitmap: make bitmap_clear free the bitmap arrayMartin Mikkelsen
Given two bitmaps and the following code: Bitmap *a = bitmap_new(), *b = bitmap_new(); bitmap_set(a, 1); bitmap_clear(a); bitmap_set(a, 0); bitmap_set(b, 0); These two bitmaps should now have the same bits set and they should be equal but bitmap_equal() will return false in this case because while bitmap_clear() resets the number of elements in the array it does not clear the array and bitmap_set() expects the array to be cleared. GREEDY_REALLOC0 looks at the allocated size and not the actual size so it does not clear any memory. Fix this by freeing the allocated memory and resetting the whole Bitmap to an initial state in bitmap_clear(). This also adds test code for this issue.
2015-07-31bitmap: fix bitmap_equal on bitmaps with unset bitsMartin Mikkelsen
Given two bitmaps and the following code: Bitmap *a = bitmap_new(), *b = bitmap_new(); bitmap_set(a, 0); bitmap_unset(a, 0); These two bitmaps should now have the same bits set and they should be equal but bitmap_equal() will return false in this case because the bitmaps array in a is larger because of the bit which was previously set. Fix this by comparing only the bits which exists in both bitmaps and then check that the rest of the bits (if any) is all zero. This also adds test code for this issue.
2015-07-31basic: fix error/memleak in socket-utilDavid Herrmann
Probably a typo, checking 'ret' instead of the return value 'p'. This might cause the function to return failure, even though it succeeded. Furthermore, it might leak resources.
2015-07-30unit-name: fix memory leakDaniel Mack
Fix a memory leak introduced by 2fc09a9c. 's' is used twice in this function, and if free_and_strdup() fails, the pointer is left untouched.
2015-07-30tree-wide: use free_and_strdup()Daniel Mack
Use free_and_strdup() where appropriate and replace equivalent, open-coded versions.
2015-07-29tree-wide: port everything over to fflush_and_check()Lennart Poettering
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-29socket-util: library calls shouldn't log on their ownLennart Poettering
Instead, make sure that all callers log properly.
2015-07-27util: base32hex - explain distinction with base32Tom Gundersen
2015-07-24Merge pull request #704 from richardmaw-codethink/empty-arg-unquoteDaniel Mack
unquote_first_word: parse ` '' ` as an empty argument instead of no arg
2015-07-24unquote_first_word: parse ` '' ` as an empty argument instead of no argumentRichard Maw
2015-07-24exit-status: add a missing string for EXIT_SMACK_PROCESS_LABELSungbae Yoo
2015-07-24Merge pull request #694 from poettering/fileio-fixesDaniel Mack
Fileio fixes
2015-07-23process: an empty environment block should be returned as suchLennart Poettering
An empty env block is completely valid, hence return it as such, and don't turn it into an error.
2015-07-23process: return ESRCH when a PID is not valid anymoreLennart Poettering
so far, when we read something from /proc/$PID we would pass on the ENOENT from the kernel as error, if the process was missing. With this change we systematically convert this to ESRCH, which is the more appropriate error code, and what all the other glibc/syscalls like kill() use. All code that calls these functions should be fine with this change. In fact, one invocation of get_process_exe() in bus-creds.c already assumed ESRCH would be returned if a process is missing, and this assumption is now validated after the change.