summaryrefslogtreecommitdiff
path: root/src/shared/util.h
AgeCommit message (Collapse)Author
2014-05-05timesyncd: lookup name server via sd-resolve, support IPv6, react to ↵Lennart Poettering
SIGINT/SITERM
2014-04-23delta: draw arrows with draw_special_char()Lennart Poettering
Let's unify generation of unicode chars at one place. Also, don't add an extra space into chars we print, except for the tree chars where this is really necessary.
2014-04-21systemctl: delete REBOOT_PARAM_FILE if no parameter is specifiedMichael Olbrich
And move it to sperate function.
2014-04-21implement a union to pad out file_handleDave Reisner
Cases where name_to_handle_at is used allocated the full struct to be MAX_HANDLE_SZ, and assigned this size to handle_bytes. This is wrong since handle_bytes should describe the length of the flexible array member and not the whole struct. Define a union type which includes sufficient padding to allow assignment of MAX_HANDLE_SZ to be correct.
2014-04-12Unify GREEDY_REALLOC and GREEDY_REALLOC_TZbigniew Jędrzejewski-Szmek
greedy_realloc() and greedy_realloc0() now store the allocated size as the count, not bytes. Replace GREEDY_REALLOC uses with GREEDY_REALLOC_T everywhere, and then rename GREEDY_REALLOC_T to GREEDY_REALLOC. It is just too error-prone to have two slightly different macros which do the same thing.
2014-03-24util: replace close_pipe() with new safe_close_pair()Lennart Poettering
safe_close_pair() is more like safe_close(), except that it handles pairs of fds, and doesn't make and misleading allusion, as it works similarly well for socketpairs() as for pipe()s...
2014-03-18util: replace close_nointr_nofail() by a more useful safe_close()Lennart Poettering
safe_close() automatically becomes a NOP when a negative fd is passed, and returns -1 unconditionally. This makes it easy to write lines like this: fd = safe_close(fd); Which will close an fd if it is open, and reset the fd variable correctly. By making use of this new scheme we can drop a > 200 lines of code that was required to test for non-negative fds or to reset the closed fd variable afterwards.
2014-03-14timedated: use builtins for integer log and expZbigniew Jędrzejewski-Szmek
2014-03-14util: add hexdump() call to create pretty hexdumps of dataLennart Poettering
This is very useful when debugging sd-bus to look at messages.
2014-03-14shared: add root argument to search_and_fopenMichael Marineau
This adds the same root argument to search_and_fopen that conf_files_list already has. Tools that use those two functions as a pair can now be easily modified to load configuration files from an alternate root filesystem tree.
2014-03-12util: Make in_charset a static inline in util.hJosh Triplett
With in_charset now reduced to a one-liner (plus asserts), make it a static inline.
2014-03-11systemctl: for switch-root check, if we switch to a systemd initHarald Hoyer
If "systemctl switch-root" is called with a specific "INIT" or /proc/cmdline contains "init=", then systemd would not serialize itsself. Let systemctl check, if the new init is in the standard systemd installation path and if so, clear the INIT parameter, to let systemd serialize itsself.
2014-03-11util: add files_same() helper functionHarald Hoyer
files_same() returns 1, if the files are the same 0, if the files have different inode/dev numbers errno, for any stat error
2014-03-07fstab-generator: merge /proc/cmdline parsing loops into oneLennart Poettering
2014-03-06util: move more intellegince into parse_proc_cmdline()Lennart Poettering
Already split variable assignments before invoking the callback. And drop "rd." settings if we are not in an initrd.
2014-03-06util: add timeout to generator executionLennart Poettering
2014-03-04logind: make $XDG_RUNTIME_DIR a per-user tmpfsLennart Poettering
This way each user allocates from his own pool, with its own size limit. This puts the size limit by default to 10% of the physical RAM size but makes it configurable in logind.conf.
2014-02-25login: fix pos-array allocationDavid Herrmann
GREEDY_REALLOC takes a pointer to the real size, not the array-width as argument. Therefore, our array is currently way to small to keep the seat positions. Introduce GREEDY_REALLOC0_T() as typed version of GREEDY_REALLOC and store the array-width instead of array-size.
2014-02-23core: clean up some confusing regarding SI decimal and IEC binary suffixes ↵Lennart Poettering
for sizes According to Wikipedia it is customary to specify hardware metrics and transfer speeds to the basis 1000 (SI decimal), while software metrics and physical volatile memory (RAM) sizes to the basis 1024 (IEC binary). So far we specified everything in IEC, let's fix that and be more true to what's otherwise customary. Since we don't want to parse "Mi" instead of "M" we document each time what the context used is.
2014-02-19core: add Personality= option for units to set the personality for spawned ↵Lennart Poettering
processes
2014-02-18nspawn: add new --personality= switch to make it easier to run 32bit ↵Lennart Poettering
containers on a 64bit host
2014-02-18util: generalize code that checks whether PIDs are alive or unwaited forLennart Poettering
2014-02-17core: fixate show_status earlier, so that we actually print the welcome messageLennart Poettering
Previously, we'd fixed show_state only after printing the welcome message which had the effect that the welcome message was almost always suppressed.
2014-02-17Extract looping over /proc/cmdline into a shared functionZbigniew Jędrzejewski-Szmek
In cryptsetup-generator automatic cleanup had to be replaced with manual cleanup, and the code gets a bit longer. But existing code had the issue that it returned negative values from main(), which was wrong, so should be reworked anyway.
2014-02-14Fix prototype of get_process_stateZbigniew Jędrzejewski-Szmek
2014-02-14core: fix detection of dead processesYuxuan Shui
Commit 5ba6985b moves the UNIT_VTABLE(u)->sigchld_event before systemd actually reaps the zombie. Which leads to service_load_pid_file accepting zombie as a valid pid. This fixes timeouts like: [ 2746.602243] systemd[1]: chronyd.service stop-sigterm timed out. Killing. [ 2836.852545] systemd[1]: chronyd.service still around after SIGKILL. Ignoring. [ 2927.102187] systemd[1]: chronyd.service stop-final-sigterm timed out. Killing. [ 3017.352560] systemd[1]: chronyd.service still around after final SIGKILL. Entering failed mode.
2014-02-11util: drop parse_user_at_host() since its unused nowLennart Poettering
2014-02-03conf-parser: warn when we open configuration files with weird access bitsLennart Poettering
2014-01-30util: add u32ctz() call for determining ctz of uint32_tLennart Poettering
2014-01-28util: introduce new dev_urandom() call that is like random_bytes() but ↵Lennart Poettering
doesn't fall back to PRNG
2014-01-27journal: guarantee async-signal-safety in sd_journald_sendvZbigniew Jędrzejewski-Szmek
signal(7) provides a list of functions which may be called from a signal handler. Other functions, which only call those functions and don't access global memory and are reentrant are also safe. sd_j_sendv was mostly OK, but would call mkostemp and writev in a fallback path, which are unsafe. Being able to call sd_j_sendv in a async-signal-safe way is important because it allows it be used in signal handlers. Safety is achieved by replacing mkostemp with open(O_TMPFILE) and an open-coded writev replacement which uses write. Unfortunately, O_TMPFILE is only available on kernels >= 3.11. When O_TMPFILE is unavailable, an open-coded mkostemp is used. https://bugzilla.gnome.org/show_bug.cgi?id=722889
2014-01-27Replace mkostemp+unlink with open(O_TMPFILE)Zbigniew Jędrzejewski-Szmek
This will only work on Linux >= 3.11, and probably not on all filesystems. Fallback code is provided.
2014-01-22DEFINE_STRING_TABLE_LOOKUP: return _INVALID_* rather than assert on NULL stringTom Gundersen
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