summaryrefslogtreecommitdiff
path: root/src/shared/util.c
AgeCommit message (Collapse)Author
2014-01-05shared: util.c: unify split and split_quotedSimon Peeters
2014-01-05util.c: use read_one_line_file where possibleSimon Peeters
2014-01-05shared: procfs_file_alloca: handle pid==0Simon Peeters
when pid is set to 0 use /proc/self
2013-12-24util: don't accept an empty peer label as validLennart Poettering
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-23util: when we try to read /proc/cmdline in a container, read /proc/1/cmdline ↵Lennart Poettering
instead
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: replace readdir_r with readdirFlorian Weimer
This fixes rm_rf_children_dangerous to detect errors during directory reading. Previously, it could dereference an uninitialized pointer.
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-17util: no need for in_initrd() cache to be thread-localShawn Landden
the process only has one working directory, and a race is harmless
2013-12-17__thread --> thread_local for C11 compatShawn Landden
Also make thread_local available w/o including <threads.h>. (as the latter hasn't been implemented, but this part is trivial)
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-16util: try harder to increase the send/recv buffers of socketsLennart Poettering
If we have the priviliges we will try SO_SNDBUFFORCE/SO_RCVBUFFORCE and only fall back to SO_SNDBUF/SO_RCVBUF if that fails.
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-14util: when joining a namespace make sure to reset all uids to 0 afterLennart Poettering
the transition
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-10util: check for overflow in greedy_realloc()Lennart Poettering
2013-12-06Get rid of our reimplementation of basenameZbigniew Jędrzejewski-Szmek
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-05util: fix misuse of memcmpYuxuan Shui
2013-12-03trivial coding style clean upsThomas Hindoe Paaboel Andersen
- Add space between if/for and the opening parentheses - Place the opening brace on same line as the function (not for udev) From the CODING_STYLE Try to use this: void foo() { } instead of this: void foo() { }
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-30systemctl: add "systemctl cat"Shawn Landden
2013-12-01util.c: check if return value from ttyname_r is > 0 instead of != 0Thomas Hindoe Paaboel Andersen
We must return a negative error code from getttyname_malloc but that would not be the case if ttyname_r returned a negative value. ttyname_r should only return EBADF, ENOTTY, or ERANGE so it should be safe to change.
2013-11-28bus: add new sd_bus_creds object to encapsulate process credentialsLennart Poettering
This way we can unify handling of credentials that are attached to messages, or can be queried for bus name owners or connection peers. This also adds the ability to extend incomplete credential information with data from /proc, Also, provide a convenience call that will automatically determine the most appropriate credential object for an incoming message, by using the the attached information if possible, the sending name information if available and otherwise the peer's credentials.
2013-11-28util: fix handling of trailing whitespace in split_quoted()Lennart Poettering
Inspired by a patch by Lukas Nykryn.
2013-11-27service: add the ability for units to join other unit's PrivateNetwork= and ↵Lennart Poettering
PrivateTmp= namespaces
2013-11-25shutdown: during final killing spree also send SIGHUP in addition to SIGTERM ↵Lennart Poettering
to deal with shells This makes shutdown a bit faster if debug-shell.service is enabled.
2013-11-21bus: add API calls to escape string components of objects pathsLennart Poettering
2013-11-18Remove duplicate includesKarel Zak
2013-11-13Resolve /dev/console to the active tty instead of just "tty0"Olivier Brunel
When resolving /dev/console one would often get "tty0" meaning the active VT. Resolving to the actual tty (e.g. "tty1") will notably help on boot when determining whether or not PID1 can output to the console.
2013-11-08shutdown: unify handling of reboot() syscall a bitLennart Poettering
2013-11-08Remove dead code and unexport some callsLennart Poettering
"make check-api-unused" informs us about code that is not used anymore or that is exported but only used internally. Fix these all over the place.
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-28udev: link-config - move naming policy from udev rulesTom Gundersen
This introduces a new key NamePolicy, which takes an ordered list of naming policies. The first successful one is applide. If all fail the value of Name (if any) is used. The possible policies are 'onboard', 'slot', 'path' and 'mac'. This patch introduces a default link file, which replaces the equivalent udev rule.
2013-10-26typo fix in commentThomas Hindoe Paaboel Andersen
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-14shared/util: Fix glob_extend() argumentBastien Nocera
glob_extend() would completely fail to work, or return incorrect data if it wasn't being passed the current getopt "optarg" variable as it used the global variable, instead of the passed parameters.
2013-10-13ModernizationZbigniew Jędrzejewski-Szmek
Fixes minor leak in error path in device.c.
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-06shared/util: fix off-by-one error in tag_to_udev_nodeDave Reisner
Triggered false negatives when encoding a string which needed every character to be escaped, e.g. "LABEL=/".
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-10-01util.c: ignore pollfd.revent for loop_read/loop_writeChen Jie
Let read()/write() report any error/EOF.
2013-09-29Fix buffer overrun when enumerating filesZbigniew Jędrzejewski-Szmek
https://bugs.freedesktop.org/show_bug.cgi?id=69887 Based-on-a-patch-by: Hans Petter Jansson <hpj@copyleft.no>
2013-09-19device-nodes: move device node specific code to own fileDave Reisner
In the process, rename udev_encode_string which is poorly named for what it does. It deals specifically with encoding names that udev creates and has its own rules: utf8 is valid but some ascii is not (e.g. path separators), and everything else is simply escaped. Rename it to encode_devnode_name.
2013-09-17Use udev_encode_string in fstab_node_to_udev_nodeDave Reisner
Resolves a longstanding bug which caused this function to wrongly handle (escape) valid utf8 characters.
2013-09-13Advertise hibernation only if there's enough free swapZbigniew Jędrzejewski-Szmek
Condition that is checked is taken from upower: active(anon) < free swap * 0.98 This is really stupid, because the kernel knows the situation better, e.g. there could be two swap files, and then hibernation would be impossible despite passing this check, or the kernel could start supporting compressed swap and/or compressed hibernation images, and then this this check would be too stringent. Nevertheless, until we have something better, this should at least return a true negative if there's no swap. Logging of capabilities in the journal is changed to not strip leading zeros. I consider this more readable anyway. http://cgit.freedesktop.org/upower/tree/src/up-daemon.c#n613 https://bugzilla.redhat.com/show_bug.cgi?id=1007059
2013-09-12Actually allow tabs in environment filesZbigniew Jędrzejewski-Szmek
Fixup for ac4c8d6da8b5e.