summaryrefslogtreecommitdiff
path: root/src/shared/util.h
Commit message (Collapse)AuthorAge
* util: replace close_pipe() with new safe_close_pair()Lennart Poettering2014-03-24
| | | | | | 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...
* util: replace close_nointr_nofail() by a more useful safe_close()Lennart Poettering2014-03-18
| | | | | | | | | | | | | | | 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.
* timedated: use builtins for integer log and expZbigniew Jędrzejewski-Szmek2014-03-14
|
* util: add hexdump() call to create pretty hexdumps of dataLennart Poettering2014-03-14
| | | | This is very useful when debugging sd-bus to look at messages.
* shared: add root argument to search_and_fopenMichael Marineau2014-03-14
| | | | | | | 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.
* util: Make in_charset a static inline in util.hJosh Triplett2014-03-12
| | | | | With in_charset now reduced to a one-liner (plus asserts), make it a static inline.
* systemctl: for switch-root check, if we switch to a systemd initHarald Hoyer2014-03-11
| | | | | | | | | | 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.
* util: add files_same() helper functionHarald Hoyer2014-03-11
| | | | | | | files_same() returns 1, if the files are the same 0, if the files have different inode/dev numbers errno, for any stat error
* fstab-generator: merge /proc/cmdline parsing loops into oneLennart Poettering2014-03-07
|
* util: move more intellegince into parse_proc_cmdline()Lennart Poettering2014-03-06
| | | | | Already split variable assignments before invoking the callback. And drop "rd." settings if we are not in an initrd.
* util: add timeout to generator executionLennart Poettering2014-03-06
|
* logind: make $XDG_RUNTIME_DIR a per-user tmpfsLennart Poettering2014-03-04
| | | | | | | 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.
* login: fix pos-array allocationDavid Herrmann2014-02-25
| | | | | | | | | 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.
* core: clean up some confusing regarding SI decimal and IEC binary suffixes ↵Lennart Poettering2014-02-23
| | | | | | | | | | | 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.
* core: add Personality= option for units to set the personality for spawned ↵Lennart Poettering2014-02-19
| | | | processes
* nspawn: add new --personality= switch to make it easier to run 32bit ↵Lennart Poettering2014-02-18
| | | | containers on a 64bit host
* util: generalize code that checks whether PIDs are alive or unwaited forLennart Poettering2014-02-18
|
* core: fixate show_status earlier, so that we actually print the welcome messageLennart Poettering2014-02-17
| | | | | | Previously, we'd fixed show_state only after printing the welcome message which had the effect that the welcome message was almost always suppressed.
* Extract looping over /proc/cmdline into a shared functionZbigniew Jędrzejewski-Szmek2014-02-17
| | | | | | | 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.
* Fix prototype of get_process_stateZbigniew Jędrzejewski-Szmek2014-02-14
|
* core: fix detection of dead processesYuxuan Shui2014-02-14
| | | | | | | | | | | | 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.
* util: drop parse_user_at_host() since its unused nowLennart Poettering2014-02-11
|
* conf-parser: warn when we open configuration files with weird access bitsLennart Poettering2014-02-03
|
* util: add u32ctz() call for determining ctz of uint32_tLennart Poettering2014-01-30
|
* util: introduce new dev_urandom() call that is like random_bytes() but ↵Lennart Poettering2014-01-28
| | | | doesn't fall back to PRNG
* journal: guarantee async-signal-safety in sd_journald_sendvZbigniew Jędrzejewski-Szmek2014-01-27
| | | | | | | | | | | | | | | | | | 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
* Replace mkostemp+unlink with open(O_TMPFILE)Zbigniew Jędrzejewski-Szmek2014-01-27
| | | | | This will only work on Linux >= 3.11, and probably not on all filesystems. Fallback code is provided.
* DEFINE_STRING_TABLE_LOOKUP: return _INVALID_* rather than assert on NULL stringTom Gundersen2014-01-22
|
* shared: util.c: unify split and split_quotedSimon Peeters2014-01-05
|
* shared: procfs_file_alloca: handle pid==0Simon Peeters2014-01-05
| | | | when pid is set to 0 use /proc/self
* Use format patterns for usec_t, pid_t, nsec_t, usec_tZbigniew Jędrzejewski-Szmek2014-01-02
| | | | | | | | 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.
* systemctl: allow globbing in commands which take multiple unit namesZbigniew Jędrzejewski-Szmek2013-12-26
|
* bus: rename message "serial" to "cookie"Lennart Poettering2013-12-25
| | | | | | 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.
* util: unify SO_PEERCRED/SO_PEERSEC invocationsLennart Poettering2013-12-24
| | | | | | Introduce new call getpeercred() which internally just uses SO_PEERCRED but checks if the returned data is actually useful due to namespace quirks.
* shared: switch our hash table implementation over to SipHashLennart Poettering2013-12-22
| | | | | SipHash appears to be the new gold standard for hashing smaller strings for hashtables these days, so let's make use of it.
* util: remove union dirent_storageFlorian Weimer2013-12-21
|
* service: watch main pid even in final statesLennart Poettering2013-12-18
| | | | | | | 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.
* _noreturn_ --> noreturn for C11 compatShawn Landden2013-12-17
| | | | also define noreturn w/o <stdnoreturn.h>
* libsystemd-bus: true/false instead of yes/no in msg dumpLukasz Skalski2013-12-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* systemctl: highlight filenames in catZbigniew Jędrzejewski-Szmek2013-12-16
|
* bus: when entering an existing namespace to connect to a container's system ↵Lennart Poettering2013-12-17
| | | | | | | bus also switch over PID namespace This is necessary to ensure that kdbus can collect creds of the destination namespace when connecting.
* core: refuse doing %h, %s, %U specifier resolving in PID 1Lennart Poettering2013-12-16
| | | | | | 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.
* bus: when connecting to a container's kdbus instance, enter namespace firstLennart Poettering2013-12-14
| | | | | | | | | | | | | | | | 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.
* util: add greedy_realloc0()David Herrmann2013-12-01
| | | | | | 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.
* service: add the ability for units to join other unit's PrivateNetwork= and ↵Lennart Poettering2013-11-27
| | | | PrivateTmp= namespaces
* systemctl: indicate in list-dependencies whether a unit is already runningLennart Poettering2013-11-22
|
* bus: add API calls to escape string components of objects pathsLennart Poettering2013-11-21
|
* util: add circle to special chars we can drawLennart Poettering2013-11-07
|
* util: unify reading of /proc/cmdlineLennart Poettering2013-11-06
| | | | | | 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.
* machinectl: add new command to spawn a getty inside a containerLennart Poettering2013-10-31
|