summaryrefslogtreecommitdiff
path: root/src/shared/util.h
AgeCommit message (Collapse)Author
2014-01-05shared: util.c: unify split and split_quotedSimon Peeters
2014-01-05shared: procfs_file_alloca: handle pid==0Simon Peeters
when pid is set to 0 use /proc/self
2014-01-02Use format patterns for usec_t, pid_t, nsec_t, usec_tZbigniew Jędrzejewski-Szmek
It is nicer to predefine patterns using configure time check instead of using casts everywhere. Since we do not need to use any flags, include "%" in the format instead of excluding it like PRI* macros.
2013-12-26systemctl: allow globbing in commands which take multiple unit namesZbigniew Jędrzejewski-Szmek
2013-12-25bus: rename message "serial" to "cookie"Lennart Poettering
Even if the lower-leveld dbus1 protocol calls it "serial", let's expose the word "cookie" for this instead, as this is what kdbus uses and since it doesn't imply monotonicity the same way "serial" does.
2013-12-24util: unify SO_PEERCRED/SO_PEERSEC invocationsLennart Poettering
Introduce new call getpeercred() which internally just uses SO_PEERCRED but checks if the returned data is actually useful due to namespace quirks.
2013-12-22shared: switch our hash table implementation over to SipHashLennart Poettering
SipHash appears to be the new gold standard for hashing smaller strings for hashtables these days, so let's make use of it.
2013-12-21util: remove union dirent_storageFlorian Weimer
2013-12-18service: watch main pid even in final statesLennart Poettering
In some circumstances, for example when start-up times out we immediately jump into the final state, at which point we still should try to watch the main pid so that the SIGCHLD allows us to quickly move into dead state.
2013-12-17_noreturn_ --> noreturn for C11 compatShawn Landden
also define noreturn w/o <stdnoreturn.h>
2013-12-17libsystemd-bus: true/false instead of yes/no in msg dumpLukasz Skalski
Due to this patch, message dump (for message which includes boolean type) is more consistent with dbus-send (which display true/false instead of yes/no for boolean). It's only simple 'cosmetics change'. ** For dbus-send ** dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply / org.freedesktop.DBus.NameHasOwner string:org.freedesktop.login1 method return sender=org.freedesktop.DBus -> dest=:1.97 reply_serial=2 boolean true ** For libsystemd-bus (without this patch) ** ‣ Type=method_call Endian=l Flags=0 Version=2 Serial=8 Destination=org.freedesktop.DBus Path=/org/freedesktop/DBus Interface=org.freedesktop.DBus Member=NameHasOwner MESSAGE "s" { STRING "org.freedesktop.login1"; }; ‣ Type=method_return Endian=l Flags=1 Version=2 Serial=51 ReplySerial=8 Sender=:1.59 Destination=:1.67 UniqueName=:1.59 WellKnownNames={org.freedesktop.DBus} MESSAGE "b" { BOOLEAN yes; }; For me true/false seems to be better readable than yes/no for BOOLEAN.
2013-12-16systemctl: highlight filenames in catZbigniew Jędrzejewski-Szmek
2013-12-17bus: when entering an existing namespace to connect to a container's system ↵Lennart Poettering
bus also switch over PID namespace This is necessary to ensure that kdbus can collect creds of the destination namespace when connecting.
2013-12-16core: refuse doing %h, %s, %U specifier resolving in PID 1Lennart Poettering
These specifiers require NSS lookups to work, and we really shouldn't do them from PID 1 hence. With this change they are now only supported for user systemd instance, or when the configured user for a unit is root.
2013-12-14bus: when connecting to a container's kdbus instance, enter namespace firstLennart Poettering
Previously we'd open the connection in the originating namespace, which meant most peers of the bus would not be able to make sense of the PID/UID/... identity of us since we didn't exist in the namespace they run in. However they require this identity for privilege decisions, hence disallowing access to anything from the host. Instead, when connecting to a container, create a temporary subprocess, make it join the container's namespace and then connect from there to the kdbus instance. This is similar to how we do it for socket conections already. THis also unifies the namespacing code used by machinectl and the bus APIs.
2013-12-01util: add greedy_realloc0()David Herrmann
Compared to greedy_realloc(), this sets all newly allocated memory to 0. As the old variant has been used a lot for string-handling, we avoid changing it as clearing memory is not needed there.
2013-11-27service: add the ability for units to join other unit's PrivateNetwork= and ↵Lennart Poettering
PrivateTmp= namespaces
2013-11-22systemctl: indicate in list-dependencies whether a unit is already runningLennart Poettering
2013-11-21bus: add API calls to escape string components of objects pathsLennart Poettering
2013-11-07util: add circle to special chars we can drawLennart Poettering
2013-11-06util: unify reading of /proc/cmdlineLennart Poettering
Instead of individually checking for containers in each user do this once in a new call proc_cmdline() that read the file only if we are not in a container.
2013-10-31machinectl: add new command to spawn a getty inside a containerLennart Poettering
2013-10-19kerne-command-line: introduce option 'systemd.restore_state'Tom Gundersen
When set to 0 this will stop tools like the backlight and rfkill tools to restore state from previous boot. This is useful in case the stored state is bogus to the extent that it is preventing you from resetting it (e.g., the backlight settings cause the screen to be off on boot on a system where the backlight can not be adjusted directly from the keyboard).
2013-10-16macro: clean up usage of gcc attributesLennart Poettering
Always use our own macros, and name all our own macros the same style.
2013-10-14util: allow trailing semicolons on define_trivial_cleanup_func linesLennart Poettering
Emacs C indenting really gets confused by these lines if they carry no trailing semicolon, hence let's make this nicer for good old emacs. The other macros which define functions already do this too, so let's copy the scheme here. Also, let's use an uppercase name for the macro. So far our rough rule was that macros that are totally not function-like (like this ones, which define a function) are uppercase. (Well, admittedly it is a rough rule only, for example function and variable decorators are all lower-case SINCE THE CONSTANT YELLING IN THE SOURCES WOULD SUCK, and also they at least got underscore prefixes.) Also, the macros that define functions that we already have are all uppercase, so let's do the same here...
2013-10-13Introduce udev object cleanup functionsZbigniew Jędrzejewski-Szmek
2013-10-13Never call qsort on potentially NULL arraysZbigniew Jędrzejewski-Szmek
This extends 62678ded 'efi: never call qsort on potentially NULL arrays' to all other places where qsort is used and it is not obvious that the count is non-zero.
2013-10-13util, utf8: make ellipsize take multi-byte characters into accountShawn Landden
rename old versions to ascii_* Do not take into account zerowidth characters, but do consider double-wide characters. Import needed utf8 helper code from glib. v3: rebase ontop of utf8 restructuring work [zj: tweak the algorithm a bit, move new code to separate file]
2013-10-03Introduce _cleanup_endmntent_Zbigniew Jędrzejewski-Szmek
2013-10-02nspawn: always copy /etc/resolv.conf rather than bind mountLennart Poettering
We were already creating the file if it was missing, and this way containers can reconfigure the file without running into problems. This also makes resolv.conf handling more alike to handling of /etc/localtime, which is also not a bind mount.
2013-10-01hashmap: randomize hash functions a bitLennart Poettering
2013-08-22Optimize startswith() to macroKay Sievers
I guess it's easier and cleaner anyway to use simple static inline functions instead of defines.
2013-08-04systemd-delta: Only print colors when on a ttyDaniel Schaal
This make systemd-delta follow the behaviour of systemctl and journalctl. https://bugs.freedesktop.org/show_bug.cgi?id=67656 [zj: unify color query methods between those three programs.]
2013-07-18util: add split_pair() for splitting foo=bar stringsLennart Poettering
2013-07-16journal: add logging of effective capabilities _CAP_EFFECTIVEShawn Landden
I think this is the most important of the capabilities bitmasks to log.
2013-06-10journalctl: allow the user to specify the file(s) to useZbigniew Jędrzejewski-Szmek
This is useful for debugging and feels pretty natural. For example answering the question "is this big .journal file worth keeping?" is made easier.
2013-06-09Allow for the use of @ in remote host callsDaniel Wallace
Without this you have to use %40 with the -H flag because dbus doesn't like the @ sign being unescaped.
2013-05-07hostname: only suppress setting of pretty hostname if it is non-equal to the ↵Lennart Poettering
static hostname and if the static hostname is set, too https://bugzilla.redhat.com/show_bug.cgi?id=957814
2013-05-06systemd-sleep: add support for freeze and standbyZbigniew Jędrzejewski-Szmek
A new config file /etc/systemd/sleep.conf is added. It is parsed by systemd-sleep and logind. The strings written to /sys/power/disk and /sys/power/state can be configured. This allows people to use different modes of suspend on systems with broken or special hardware. Configuration is shared between systemd-sleep and logind to enable logind to answer the question "can the system be put to sleep" as correctly as possible without actually invoking the action. If the user configured systemd-sleep to only use 'freeze', but current kernel does not support it, logind will properly report that the system cannot be put to sleep. https://bugs.freedesktop.org/show_bug.cgi?id=57793 https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=7e73c5ae6e7991a6c01f6d096ff8afaef4458c36 http://lists.freedesktop.org/archives/systemd-devel/2013-February/009238.html SYSTEM_CONFIG_FILE and USER_CONFIG_FILE defines were removed since they were used in only a few places and with the addition of /etc/systemd/sleep.conf it becomes easier to just append the name of each file to the dir name.
2013-05-02Add __attribute__((const, pure, format)) in various placesZbigniew Jędrzejewski-Szmek
I'm assuming that it's fine if a _const_ or _pure_ function calls assert. It is assumed that the assert won't trigger, and even if it does, it can only trigger on the first call with a given set of parameters, and we don't care if the compiler moves the order of calls.
2013-05-01Annotate some functions as _const_Cristian Rodríguez
hexchar,unhexchar,octchar,unoctchar,decchar,undecchar are all const functions.
2013-04-30util: Add _sentinel_ to strextend()Colin Walters
Since it must be NULL terminated.
2013-04-30id128: when taking user input for a 128bit ID, validate syntaxLennart Poettering
Also, always accept both our simple hexdump syntax and UUID syntax.
2013-04-25Use attribute(unused) in PROTECT_ERRNOZbigniew Jędrzejewski-Szmek
clang emits warnings about unused attribute _saved_errno_, which drown out other—potentially useful—warnings. gcc documentation is not exactly verbose about the effects of __attribute__((unused)) on variables, but let's assume that it works if the unit test passes.
2013-04-25Add some extra __attribute__ ((format)) sCristian Rodríguez
2013-04-25Make up for attribute malloc with alloc_sizeZbigniew Jędrzejewski-Szmek
It is imperative that open source code be well attributed. Sprinkle attribute((alloc_size)) here and there, telling gcc how much memory we are actually allocating.
2013-04-25Remove erroneous attribute((malloc)) annotationsZbigniew Jędrzejewski-Szmek
According to gcc documentation, returned pointer "cannot alias any other pointer valid when the function returns" and "the memory has undefined content". This second part is (hopefully) untrue for all those functions.
2013-04-25util: rework safe_atod() to be locale-independentLennart Poettering
This adds some syntactic sugar with a macro RUN_WITH_LOCALE() that reset the thread-specific locale temporarily.
2013-04-19core/killall: use procfs_file_allocaZbigniew Jędrzejewski-Szmek
2013-04-16path-util: unify code for detecting OS treesLennart Poettering
This also makes sure we always detect an OS tree the same way, by checking for /etc/os-release.