summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-daemon
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: unsetenv cannot failZbigniew Jędrzejewski-Szmek2020-11-101-7/+6
| | | | | | ... when called with a valid environment variable name. This means that any time we call it with a fixed string, it is guaranteed to return 0. (Also when the variable is not present in the environment block.)
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* Rename strv_split_extract() to strv_split_full()Zbigniew Jędrzejewski-Szmek2020-09-091-1/+1
| | | | | Now that _full() is gone, we can rename _extract() to have the usual suffix we use for the more featureful version.
* tree-wide: port to fd_wait_for_event()Lennart Poettering2020-06-101-10/+2
| | | | | | | | Prompted by the discussion on #16110, let's migrate more code to fd_wait_for_event(). This only leaves 7 places where we call into poll()/poll() directly in our entire codebase. (one of which is fd_wait_for_event() itself)
* tree-wide: check POLLNVAL everywhereLennart Poettering2020-06-101-0/+2
| | | | | | | | | | | | | poll() sets POLLNVAL inside of the poll structures if an invalid fd is passed. So far we generally didn't check for that, thus not taking notice of the error. Given that this specific kind of error is generally indication of a programming error, and given that our code is embedded into our projects via NSS or because people link against our library, let's explicitly check for this and convert it to EBADF. (I ran into a busy loop because of this missing check when some of my test code accidentally closed an fd it shouldn't close, so this is a real thing)
* Introduce sd_notify_barrierKumar Kartikeya Dwivedi2020-05-011-0/+30
| | | | | | | | | | | | | | | This adds the sd_notify_barrier function, to allow users to synchronize against the reception of sd_notify(3) status messages. It acts as a synchronization point, and a successful return gurantees that all previous messages have been consumed by the manager. This can be used to eliminate race conditions where the sending process exits too early for systemd to associate its PID to a cgroup and attribute the status message to a unit correctly. systemd-notify now uses this function for proper notification delivery and be useful for NotifyAccess=all units again in user mode, or in cases where it doesn't have a control process as parent. Fixes: #2739
* tree-wide: use the return value from sockaddr_un_set_path()Zbigniew Jędrzejewski-Szmek2020-03-021-7/+5
| | | | | | | | | It fully initializes the address structure, so no need for pre-initialization, and also returns the length of the address, so no need to recalculate using SOCKADDR_UN_LEN(). socklen_t is unsigned, so let's not use an int for it. (It doesn't matter, but seems cleaner and more portable to not assume anything about the type.)
* tree-wide: drop socket.h when socket-util.h is includedYu Watanabe2019-11-041-1/+0
|
* tree-wide: drop string.h when string-util.h or friends are includedYu Watanabe2019-11-041-1/+0
|
* sd-daemon: make sd_booted() return negative errno on unexpected errorYu Watanabe2019-02-071-1/+7
|
* tree-wide: more IOVEC_MAKE() conversionsLennart Poettering2018-11-281-4/+3
|
* tree-wide: port various users over to sockaddr_un_set_path()Lennart Poettering2018-10-151-18/+6
| | | | | CID 1396140 CID 1396141
* tree-wide: drop empty commentsYu Watanabe2018-06-291-2/+0
|
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-1/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* macro: introduce TAKE_PTR() macroLennart Poettering2018-03-221-2/+1
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* Merge pull request #7816 from poettering/chase-pidZbigniew Jędrzejewski-Szmek2018-01-151-10/+19
|\ | | | | Make MAINPID= and PIDFile= handling more restrictive (and other stuff)
| * sd-dameon: also sent ucred when our UID differs from EUIDLennart Poettering2018-01-111-10/+19
| | | | | | | | | | | | Let's be explicit, and always send the messages from our UID and never our EUID. Previously this behaviour was conditionalized only on whether the PID was specified, which made this non-obvious.
* | log: minimize includes in log.hLennart Poettering2018-01-111-0/+1
|/ | | | | | | | | | | | | | | | | | | | | | | | | | log.h really should only include the bare minimum of other headers, as it is really pulled into pretty much everything else and already in itself one of the most basic pieces of code we have. Let's hence drop inclusion of: 1. sd-id128.h because it's entirely unneeded in current log.h 2. errno.h, dito. 3. sys/signalfd.h which we can replace by a simple struct forward declaration 4. process-util.h which was needed for getpid_cached() which we now hide in a funciton log_emergency_level() instead, which nicely abstracts the details away. 5. sys/socket.h which was needed for struct iovec, but a simple struct forward declaration suffices for that too. Ultimately this actually makes our source tree larger (since users of the functionality above must now include it themselves, log.h won't do that for them), but I think it helps to untangle our web of includes a tiny bit. (Background: I'd like to isolate the generic bits of src/basic/ enough so that we can do a git submodule import into casync for it)
* sd-daemon: use sockaddr_port() helperLennart Poettering2017-12-261-9/+5
|
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* libsystemd: use IN_SET macroYu Watanabe2017-09-281-5/+4
|
* tree-wide: make use of getpid_cached() wherever we canLennart Poettering2017-07-201-3/+3
| | | | | | | This moves pretty much all uses of getpid() over to getpid_raw(). I didn't specifically check whether the optimization is worth it for each replacement, but in order to keep things simple and systematic I switched over everything at once.
* build-sys: drop automake supportZbigniew Jędrzejewski-Szmek2017-07-181-1/+0
| | | | | v2: - also mention m4
* Add sd_is_socket_sockaddr (#4885)Zbigniew Jędrzejewski-Szmek2016-12-141-0/+58
| | | Fixes #1188.
* tree-wide: htonl() is weird, let's use htobe32() instead (#3538)Lennart Poettering2016-06-151-2/+2
| | | Super-important change, yeah!
* tree-wide: introduce new SOCKADDR_UN_LEN() macro, and use it everywhereLennart Poettering2016-05-051-3/+1
| | | | | | | | | | The macro determines the right length of a AF_UNIX "struct sockaddr_un" to pass to connect() or bind(). It automatically figures out if the socket refers to an abstract namespace socket, or a socket in the file system, and properly handles the full length of the path field. This macro is not only safer, but also simpler to use, than the usual offsetof() + strlen() logic.
* treewide: fix typos and then/that useTorstein Husebø2016-02-241-1/+1
|
* tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* Merge pull request #1768 from vcaputo/sd-daemon-listen-fds-overflow-bisLennart Poettering2015-11-041-5/+10
|\ | | | | sd-daemon: fix potential LISTEN_FDS overflow in sd_listen_fds()
| * sd-daemon: fix potential LISTEN_FDS overflow in sd_listen_fds()Vito Caputo2015-11-031-5/+10
| |
* | sd-daemon: explicitly filter out -1 when parsing watchdog timeoutLennart Poettering2015-11-031-1/+1
|/ | | | | | We already filter out 0, and as -1 is usually special (meaning infinity, as in USEC_INFINITY) we should better not accept it either. Better safe than sorry...
* sd-daemon: verify NOTIFY_SOCKET path lengthLennart Poettering2015-11-011-0/+5
| | | | Better generate a real error then simply connect to the wrong socket.
* sd-daemon: increase sd_notify() socket buffer sizeLennart Poettering2015-10-311-0/+4
| | | | | | | | Let's make sure we don't start blocking on sd_notify() earlier than necessary, let's bump the socket buffer sizes to 8M. We already do something similar for our logging socket buffers, hence apply a similar bump here.
* util-lib: split out allocation calls into alloc-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: move a number of fs operations into fs-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: split string parsing related calls from util.[ch] into parse-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: split out fd-related operations into fd-util.[ch]Lennart Poettering2015-10-251-0/+1
| | | | | There are more than enough to deserve their own .c file, hence move them over.
* util-lib: split our string related calls from util.[ch] into its own file ↵Lennart Poettering2015-10-241-2/+2
| | | | | | | | | | | | | | string-util.[ch] There are more than enough calls doing string manipulations to deserve its own files, hence do something about it. This patch also sorts the #include blocks of all files that needed to be updated, according to the sorting suggestions from CODING_STYLE. Since pretty much every file needs our string manipulation functions this effectively means that most files have sorted #include blocks now. Also touches a few unrelated include files.
* sd-daemon: wipe out memory before using CMSG_NXTHDR()Daniel Mack2015-10-121-1/+1
| | | | | | | | CMSG_NXTHDR() checks for cmsg->cmsg_len *after* it increased the pointer. While this makes sense for parsing received messages, that's a pitfall for code crafting messages with this macro. Wipe out the allocated memory to fix this.
* sd-daemon: simply code simplificationLennart Poettering2015-10-091-2/+4
| | | | No change in behaviour, just make the code more obvious.
* core: add support for naming file descriptors passed using socket activationLennart Poettering2015-10-061-15/+64
| | | | | | | | | | | | | | | | | | | | | | | This adds support for naming file descriptors passed using socket activation. The names are passed in a new $LISTEN_FDNAMES= environment variable, that matches the existign $LISTEN_FDS= one and contains a colon-separated list of names. This also adds support for naming fds submitted to the per-service fd store using FDNAME= in the sd_notify() message. This also adds a new FileDescriptorName= setting for socket unit files to set the name for fds created by socket units. This also adds a new call sd_listen_fds_with_names(), that is similar to sd_listen_fds(), but also returns the names of the fds. systemd-activate gained the new --fdname= switch to specify a name for testing socket activation. This is based on #1247 by Maciej Wereski. Fixes #1247.
* sd-daemon: fix sd_is_mq for non-mq fdsZbigniew Jędrzejewski-Szmek2015-09-301-2/+7
| | | | | | | | | mq_getattr returns -1/EBADF for file descriptors which are not mq. But we should return 0 in this case. We first check that fd is a valid fd, so we can assume that if mq_getattr returns EBADF, it is simply a non-mq fd. There is a slight race, but there doesn't seem to be a nice way to fix it.
* sd-daemon: Simplify sd_booted() checkLennart Poettering2015-09-291-6/+1
| | | | | | We can just use access() to check whether /run/system/system/ is a directory, no need to involve stat(). The trick is to suffix the path name with a dash.
* sd_pid_notify_with_fds: fix computing msg_controllenMaciej Wereski2015-09-091-2/+3
| | | | | CMSG_SPACE(0) may return value other than 0. This caused sendmsg to fail with EINVAL, when have_pid or n_fds was 0.
* sd-daemon: return EBADF for invalid fd numbersZbigniew Jędrzejewski-Szmek2015-08-071-7/+7
| | | | This matches what open(2) and other system functions do.
* sd-daemon: simplify sd_pid_notify_with_fdsZbigniew Jędrzejewski-Szmek2015-03-131-34/+27
| | | | | | | | Coverity was complaining that CMSG_NXTHDR is used without checking the return value. In this case it cannot fail, but it is a good excuse to simplify the function a bit. CID #1261726.
* sd-daemon: replace VLA with alloca(), to make llvm happyLennart Poettering2015-03-021-7/+5
| | | | https://bugs.freedesktop.org/show_bug.cgi?id=89379
* remove unused includesThomas Hindoe Paaboel Andersen2015-02-231-2/+0
| | | | | | This patch removes includes that are not used. The removals were found with include-what-you-use which checks if any of the symbols from a header is in use.