summaryrefslogtreecommitdiffstats
path: root/src/basic/process-util.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* sd-json: drop sd_json_dispatch_pid() again, as we prefer ↵Lennart Poettering2024-10-141-5/+0
| | | | | | | | json_dispatch_pidref() now The calls are now unused, and we generally prefer if people send a PID triplet rather than a single PID, hence stop supporting a high-level dispacher for pid_t.
* pidref: hookup PID_AUTOMATIC special pid_t value with PidRefLennart Poettering2024-10-141-1/+2
| | | | | | The PID_AUTOMATIC value is now properly recognized by the PidRef logic too. This needed some massaging of header includes, to ensure pidref.h can access process-util.h's definitions and vice versa.
* sd-json: add sd_json_dispatch_pid()Ivan Kruglov2024-10-101-0/+11
|
* various: move const ptr indicator to return valueZbigniew Jędrzejewski-Szmek2024-06-191-2/+2
|
* process-util: make pid*_get_start_time return usec_tMike Yuan2024-05-221-2/+2
|
* fd-util: Expose helper to pack fds into 3,4,5,...Adrian Vovk2024-02-191-3/+15
| | | | | | | This is useful for situations where an array of FDs is to be passed into a child process (i.e. by passing it through safe_fork). This function can be called in the child (before calling exec) to pack the FDs to all be next to each-other starting from SD_LISTEN_FDS_START (i.e. 3)
* process-util: unify the hex value format a bitFrantisek Sumsal2024-02-071-2/+2
| | | | And fix the man page reference as well.
* process-util: use only the least significant byte from personality()Frantisek Sumsal2024-02-071-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | The personality() syscall returns a 32-bit value where the top three bytes are reserved for flags that emulate historical or architectural quirks, and only the least significant byte reflects the actual personality we're interested in (in opinionated_personality()). Use the newly defined mask in the corresponding test as well, otherwise the test fails on some more "exotic" architectures that set some of the "quirk" flags: ~# uname -m armv7l ~# build/test-seccomp ... /* test_lock_personality */ current personality=0x0 safe_personality(PERSONALITY_INVALID)=0x800000 Assertion '(unsigned long) safe_personality(current) == current' failed at src/test/test-seccomp.c:970, function test_lock_personality(). Aborting. lockpersonalityseccomp terminated by signal ABRT. Assertion 'wait_for_terminate_and_check("lockpersonalityseccomp", pid, WAIT_LOG) == EXIT_SUCCESS' failed at src/test/test-seccomp.c:996, function test_lock_personality(). Aborting. Aborted (core dumped) See: personality(2) and comments in sys/personality.h
* process-util: minor follow-up for pidfd_spawnMike Yuan2024-02-061-1/+6
|
* core: add support for pidfd_spawnLuca Boccassi2024-02-051-1/+1
| | | | | | | | | | Added in glibc 2.39, allows cloning into a cgroup and to get a pid fd back instead of a pid. Removes race conditions for both changing cgroups and getting a reliable reference for the child process. Fixes https://github.com/systemd/systemd/pull/18843 Replaces https://github.com/systemd/systemd/pull/16706
* core: use PidRef in exec_spawnLuca Boccassi2024-02-011-1/+1
|
* process-util: introduce FORK_NEW_NETNS for safe_fork()Yu Watanabe2024-01-191-5/+6
| | | | Similar to FORK_NEW_MOUNTNS or FORK_NEW_USERNS.
* process-util: add new pid{ref,}_get_start_time() helperLennart Poettering2024-01-021-0/+2
| | | | | This also adds a test case that test pidref_safe_fork(), pidref_wait() and related calls.
* process-util: add pidref_safe_fork() helperLennart Poettering2024-01-021-0/+12
| | | | | | | | | | | This combines safe_fork() with pidref_set_pid(). Eventually we really should switch this to use CLONE_PIDFD, but as that is not wrapped by glibc yet, it's hard. But this is not crucial anyway, as a child we just forked off can always safely be referenced also by PID, given the reaping is under our own control. A simple test case is added in a follow-up commit.
* process-util: add new FORK_DEATHSIG_SIGKILL flag, rename FORK_DEATHSIG → ↵Lennart Poettering2023-11-021-15/+16
| | | | | | | | | | | | | | | | | | FORK_DEATHSIG_SIGTERM Sometimes it makes sense to hard kill a client if we die. Let's hence add a third FORK_DEATHSIG flag for this purpose: FORK_DEATHSIG_SIGKILL. To make things less confusing this also renames FORK_DEATHSIG to FORK_DEATHSIG_SIGTERM to make clear it sends SIGTERM. We already had FORK_DEATHSIG_SIGINT, hence this makes things nicely symmetric. A bunch of users are switched over for FORK_DEATHSIG_SIGKILL where we know it's safe to abort things abruptly. This should make some kernel cases more robust, since we cannot get confused by signal masks or such. While we are at it, also fix a bunch of bugs where we didn't take FORK_DEATHSIG_SIGINT into account in safe_fork()
* process-util: add API for enumerating processes in /proc/ and pinning them ↵Lennart Poettering2023-10-181-0/+4
| | | | via PidRef
* process-util: add pidref_is_unwaited() and make pid_is_unwaited() return errorsLennart Poettering2023-10-181-1/+2
|
* process-util: add pidref_is_my_child()Lennart Poettering2023-10-181-0/+1
|
* process-util: change pid_is_alive() to not eat up errors, and add ↵Lennart Poettering2023-10-181-1/+2
| | | | | | pidref_is_alive() Let's no eat up errors, but propagate unexpected ones.
* process-util: add pidref_get_uid() and rename get_process_uid() → ↵Lennart Poettering2023-10-181-1/+2
| | | | pidref_get_uid()
* process-util: add pidref_get_comm() and rename get_process_comm() to ↵Lennart Poettering2023-10-181-1/+2
| | | | pid_get_comm()
* process-util: add pidref_is_kernel_thread()Lennart Poettering2023-10-181-1/+2
|
* process-util: add pidref_get_cmdline()Lennart Poettering2023-10-181-2/+4
|
* Merge pull request #29272 from enr0n/coredump-containerLennart Poettering2023-10-161-0/+3
|\ | | | | coredump: support forwarding coredumps to containers
| * process-util: introduce namespace_get_leader helperNick Rosbrook2023-10-131-0/+3
| | | | | | | | | | | | | | | | For a given PID and namespace type, this helper function gives the PID of the leader of the namespace containing the given PID. Use this in systemd-coredump instead of using the existing get_mount_namespace_leader. This helper will be used again in a later commit.
* | process-util: add posix_spawn helperLuca Boccassi2023-10-121-0/+2
|/ | | | | | This provides CLONE_VM + CLONE_VFORK semantics, so it is useful to avoid CoW traps and other issues around doing work between fork() and exec().
* process-util: add simple wrapper around PR_SET_CHILD_SUBREAPERLennart Poettering2023-06-231-0/+1
| | | | Let's a simple helper that knows how to deal with PID == 1.
* process-util: add FORK_DETACH flag for forking of detached childLennart Poettering2023-06-231-0/+1
| | | | | A test for this is later added indirectly, via aynchronous_rm_rf() that uses this and comes with a suitable test.
* basic: add comments about raw_clone() calls not supporting threads/malloc in ↵Lennart Poettering2023-06-231-2/+7
| | | | child
* process-util: add clone_with_nested_stack() helperLennart Poettering2023-06-231-0/+2
| | | | | | This wraps glibc's clone() but deals with the 'stack' parameter in a sensible way. Only supports invocations without CLONE_VM, i.e. when child is a CoW copy of parent.
* process-util: add helper that detects if we are a reaper processLennart Poettering2023-06-231-0/+2
|
* process-util: make safe_fork() unset $NOTIFY_SOCKETYu Watanabe2023-04-161-0/+1
| | | | | | | | Propagating $NOTIFY_SOCKET is typically dangerous. Let's unset it unless explicitly requested to keep it. Fixes #27288. Replaces #27291.
* process-util: introduce get_process_cmdline_strv()Yu Watanabe2023-03-281-0/+1
| | | | | | | | | | | | The reason why get_process_cmdline() is so complicated is that we need to escape and quote arguments for building a single result string. That's necessary when we want to log or print the command line. However, when we want to parse the command line, it is not necessary that the result is a single string, but can be strv. This will be used when we parse the command line.
* process-util: rename FORK_NULL_STDIO -> FORK_REARRANGE_STDIOYu Watanabe2023-02-201-3/+9
| | | | And make safe_fork_full() takes fds to be assigned to stdio.
* process-util: add helper get_process_threads()Lennart Poettering2023-02-171-0/+2
| | | | | Let's add a proper helper for querying the number of threads in a process.
* Consolidate various TAKE_* into TAKE_GENERIC(), add TAKE_STRUCT()Dan Streetman2023-01-241-8/+2
|
* process-util: add helper to verify a pid via its pidfdLuca Boccassi2023-01-201-0/+1
|
* shutdown: propagate mount() failures from child to parentLennart Poettering2023-01-091-0/+2
| | | | | | Let's propagate the actual error code up, as we usual do. Inspired by: #25168
* shared: add new safe_fork flag FORK_PRIVATE_TMPZbigniew Jędrzejewski-Szmek2022-12-141-5/+6
| | | | | | | | | | | | | If the flag is set, we mount /tmp/ in a way that is suitable for generators and other quick jobs. Unfortunately I had to move some code from shared/mount-util.c to basic/mountpoint-util.c. The functions that are moved are very thin wrappers around mount(2), so this doesn't actually change much in the code split between libbasic and libshared. Implications for the host would be weird if a private mount namespace is not used, so assert on FORK_NEW_MOUNTNS when the flag is used.
* basic: move a bunch of cmdline-related funcs to new argv-util.c+hZbigniew Jędrzejewski-Szmek2022-11-081-7/+0
| | | | | | | | | | | | | I wanted to move saved_arg[cv] to process-util.c+h, but this causes problems: process-util.h includes format-util.h which includes net/if.h, which conflicts with linux/if.h. So we can't include process-util.h in some files. But process-util.c is very long anyway, so it seems nice to create a new file. rename_process(), invoked_as(), invoked_by_systemd(), and argv_looks_like_help() which lived in process-util.c refer to saved_argc and saved_argv, so it seems reasonable to move them to the new file too. util.c is now empty, so it is removed. util.h remains.
* basic: move container_get_leader() to process-util.[ch]Zbigniew Jędrzejewski-Szmek2022-11-081-0/+2
| | | | | basic/util.[ch] is a grab-bag of unrelated functions. Let's move a few of the remaning functions to better locations.
* process-util: add new FORK_CLOEXEC_OFF flag for disabling O_CLOEXEC on ↵Lennart Poettering2022-11-041-0/+1
| | | | | | | | remaining fds Often the fds that shall stay around in the child shall be passed to a process over execve(), hence add an option to explicitly disable O_CLOEXEC on them in the child.
* basic/log: split out invoked_by_systemd() utility functionZbigniew Jędrzejewski-Szmek2022-07-151-0/+2
|
* tree-wide: unify some code that looks for --help in the command lineLennart Poettering2022-03-311-0/+2
|
* process-util: rename function arguments for storing resultsYu Watanabe2021-12-061-11/+11
|
* shared: split out ioprio related stuff into ioprio-util.[ch]Lennart Poettering2021-11-241-14/+0
| | | | No actual code changes, just some splitting out.
* process-util: rework TAKE_PID() to be side-effect freeLennart Poettering2021-11-031-2/+3
|
* Revert "basic/fd-util: sort the 'except' array in place"Lennart Poettering2021-10-271-2/+2
| | | | This reverts commit 9c46228b7deb53d6384545535b37b2844a102b2b.
* basic: move freeze() from shared/exec-util.h to basic/process-util.hLennart Poettering2021-10-221-0/+2
| | | | | That way we can use it in other code from basic/. It fits into both headers equally well or badly, hence let's just move this one function.
* process-util: add helper for querying oom score adjustment valueLennart Poettering2021-10-041-0/+1
|