summaryrefslogtreecommitdiffstats
path: root/src/basic/process-util.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* Get rid of ioprio.h and add a minimalistic reimplementation of the apiZbigniew Jędrzejewski-Szmek2021-09-221-1/+1
|
* Revert "Make oom_score_adjust_is_valid() static"Lennart Poettering2021-07-281-0/+2
| | | | This reverts commit 6bf3c6c9007ca87376d5dff1e029186a38736cdc.
* Move freeze() into shared/Zbigniew Jędrzejewski-Szmek2021-07-231-2/+0
| | | | | | | | Library code should not call freeze(), this is something that should only be done by "application code", so moving it into shared/ is appropriate. The fallback to call _exit() is dropped: let's trust that the infinite loop is infinite.
* Move fork_agent() into shared/Zbigniew Jędrzejewski-Szmek2021-07-231-2/+0
| | | | | | | Currently it's only used in two places in src/shared/, so the function was already included just once in compiled code. But it seems appropriate to move it there anyway, because library code should have no need to fork agents, so it doesn't belong in basic/.
* Make oom_score_adjust_is_valid() staticZbigniew Jędrzejewski-Szmek2021-07-231-2/+0
| | | | It has only one user and we don't need to put it in basic/.
* basic/fd-util: sort the 'except' array in placeZbigniew Jędrzejewski-Szmek2021-07-231-3/+3
| | | | | | | | | | | | | | We need a sorted list of fds to skip over when closing. We would allocate a copy of the passed array to do the sort. But all callers construct a temporary array to pass to us, so it is pointless to copy it again. close_all_fds/safe_fork_full/namespace_fork/fork_agent are changed to pass a non-const int array. I checked all users, and all callers are fine with the array being sorted. The function was returning some number (sometimes 1, sometimes the extent of the range passed over to close_range(), ???). Anyway, all callers only check for error, so let's return 0 on success.
* process-util: add option for cloning with CLONE_NEWUSERLennart Poettering2021-05-071-0/+1
| | | | | This is useful for allocating a userns fd later on for use in idmapped mounts.
* basic/process-util: add mode where posix shell escape is used for quotingZbigniew Jędrzejewski-Szmek2021-05-051-0/+1
| | | | | | | | The new flag is not used, except in tests, so no functional change yet. This way, the command as shown can be copied-and-pasted into the shell in more cases. For simple cases, shell quoting with "" is enough. But $'' is needed when there are control characters in the command.
* basic/process-util: allow quoting of commandlinesZbigniew Jędrzejewski-Szmek2021-05-051-0/+1
| | | | | | | | | | | Since the new functionality is controlled by an option, this causes no change in output yet, except tests. The login in the old branch of !(flags & PROCESS_CMDLINE_QUOTE) is essentially unmodified. But there is an important difference in behaviour: instead of unconditionally reading the whole virtual file, we now read only 'max_columns' bytes. This makes out code to write process lists quite a bit more efficient when there are processes with long command lines.
* coredumpctl: fflush() stdout before invoking gdbLennart Poettering2021-03-111-0/+1
| | | | Fixes: #18936
* systemctl: don't search in the full argv[0] for the invocation nameLennart Poettering2021-02-201-0/+2
| | | | | | | | | | | | argv[0] might be prefixed by a path, and we shouldn't get confused by that. Hence provide a simple helper call that abstracts the checking away, which we can use everywhere, and expose the same behaviour, even if argv[0] is not set. (While we are at it, port all other multi-call binaries over to the new helper, too) Follow-up for: d41a9e4fc1e1bcdefc8d358da2744a97aac5820a
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* process-util: make sure procfs_file_alloca() works for non-literal field ↵Lennart Poettering2020-07-141-5/+7
| | | | names too
* pager: set PR_DEATHSIG for pager to SIGINT rather than SIGTERMLennart Poettering2020-06-101-9/+10
| | | | | | | | | | | | "less" doesn't properly reset its terminal on SIGTERM, it does so only on SIGINT. Let's thus configure SIGINT instead of SIGTERM. I think this is something less should fix too, and clean up things correctly on SIGTERM, too. However, given that we explicitly enable SIGINT behaviour by passing "K" to $LESS I figure it makes sense if we also send SIGINT instead of SIGTERM to match it. Fixes: #16084
* pid1: by default make user units inherit their umask from the user managerFranck Bui2020-04-091-0/+1
| | | | | | | | | | | | | | | | | | | | This patch changes the way user managers set the default umask for the units it manages. Indeed one can expect that if user manager's umask is redefined through PAM (via /etc/login.defs or pam_umask), all its children including the units it spawns have their umask set to the new value. Hence make user units inherit their umask value from their parent instead of the hard coded value 0022 but allow them to override this value via their unit file. Note that reexecuting managers with 'systemctl daemon-reexec' after changing UMask= has no effect. To take effect managers need to be restarted with 'systemct restart' instead. This behavior was already present before this patch. Fixes #6077.
* util: uid_t, gid_t, and pid_t must be 32bitYu Watanabe2020-02-021-7/+0
| | | | | We already have assert_cc(sizeof(uid_t) == sizeof(uint32_t)) or friends at various places.
* core: in execute, Never fail setting Nice priorityDimitri John Ledkov2020-01-021-0/+2
| | | | | | Instead, push to the closest possible Nice priority setting. Replaces: #11397
* Merge pull request #14218 from poettering/homed-preparatory-small-stuffLennart Poettering2019-12-041-10/+11
|\ | | | | Assorted smaller stuff split out from homed PR
| * process-util: add new safe_fork() flag for connecting stdout to stderrLennart Poettering2019-12-041-10/+11
| | | | | | | | | | | | | | This adds a new safe_fork() flag. If set the child process' fd 1 becomes fd 2 of the caller. This is useful for invoking tools (such as various mkfs/fsck implementations) that output status messages to stdout, but which we invoke and don't want to pollute stdout with their output.
* | process-util: add helper pidfd_get_pid()Lennart Poettering2019-12-041-0/+2
|/ | | | It returns the pid_t a pidfd refers to.
* tree-wide: drop alloca.h when alloc-util.h is includedYu Watanabe2019-11-031-1/+0
|
* Drop trailing slash from assert_cc() definitionZbigniew Jędrzejewski-Szmek2019-07-171-1/+1
| | | | | | We use assert_cc(...); almost everywhere. Let's always require that. https://github.com/systemd/systemd/issues/12997#issuecomment-510103988
* Merge pull request #12628 from keszybz/dbus-executeMichal Sekletar2019-05-301-2/+0
|\ | | | | Rework cpu affinity parsing
| * Move cpus_in_affinity_mask() to cpu-set-util.[ch]Zbigniew Jędrzejewski-Szmek2019-05-291-2/+0
| | | | | | | | | | It just seems to fit better there and it's always better to have things in shared/ rather than basic/.
* | Add 8bit-version of get_process_cmdline() and use in cgroup-show.cZbigniew Jędrzejewski-Szmek2019-05-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | This restores show_pid_array() output in legacy locales on the console. Only one call to get_process_cmdline() is changed, all others retain utf8-only mode. This affects systemd-cgls, systemctl status, etc, when working locally. Calls to get_process_cmdline() that cross a process boundary always use utf8. It's the callers responsibility to convert this to some encoding that they use. This means that we always pass utf8 over the bus.
* | basic/process-util: convert bool arg to flagsZbigniew Jędrzejewski-Szmek2019-05-221-1/+5
| | | | | | | | In preparation for the next commit…
* | Rework cmdline printing to use unicodeZbigniew Jędrzejewski-Szmek2019-05-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The functions to retrieve and print process cmdlines were based on the assumption that they contain printable ASCII, and everything else should be filtered out. That assumption doesn't hold in today's world, where people are free to use unicode everywhere. This replaces the custom cmdline reading code with a more generic approach using utf8_escape_non_printable_full(). For kernel threads, truncation is done on the parenthesized name, so we'll get "[worker]", "[worker…]", …, "[w…]", "[…", "…" as we reduce the number of available columns. This implementation is most likely slower for very long cmdlines, but I don't think this is very important. The common case is to have short commandlines, and should print those properly. Absurdly long cmdlines are the exception, which needs to be handled correctly and safely, but speed is not too important. Fixes #12532. v2: - use size_t for the number of columns. This change propagates into various other functions that call get_process_cmdline(), increasing the size of the patch, but the changes are rather trivial.
* | small fixes: make get_process_state() static and fix typoTopi Miettinen2019-05-201-1/+0
|/
* Merge pull request #12030 from poettering/condition-memoryYu Watanabe2019-04-021-0/+2
|\ | | | | add ConditionCPUs= + ConditionMemory=
| * process-util: add new helper cpus_in_affinity_mask()Lennart Poettering2019-03-191-0/+2
| | | | | | | | | | Let's add a new helper for determining how many CPUs are configured for us
* | process-util: introduce pid_is_my_child() helperFranck Bui2019-03-201-0/+1
|/ | | | No functional changes.
* util: split out namespace related stuff into a new namespace-util.[ch] pairLennart Poettering2019-03-131-0/+1
| | | | Just some minor reorganiztion.
* tree-wide: use newa() instead of alloca() wherever we canLennart Poettering2019-01-261-2/+2
| | | | | Typesafety is nice. And this way we can take benefit of the new size assert() the previous commit added.
* process-util: add new FORK_RLIMIT_NOFILE_SAFE flag for safe_fork()Lennart Poettering2018-12-011-9/+10
| | | | | The new flag simply means rlimit_nofile_safe() is called in the child after all fds are rearranged.
* core: add namespace_fork() helper, that forks, joins a set of namespaces and ↵Lennart Poettering2018-11-131-0/+2
| | | | | | | | | forks again This helper is useful to ensure pidns/userns joining is properly executed (as that requires a fork after the setns()). This is particularly important when it comes to /proc/self/ access or SCM_CREDENTIALS, but is generally the safer mode of operation.
* tree-wide: add a few missing _sentinel_ decoratorsLennart Poettering2018-10-261-1/+1
|
* core/dbus-execute: fix parsing CPUScheduling* and Nice for transient servicesYu Watanabe2018-10-051-7/+0
| | | | Fixes #10290.
* tree-wide: use typesafe_qsort()Yu Watanabe2018-09-191-1/+1
|
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-4/+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: unify how we define bit mak enumsLennart Poettering2018-06-121-11/+11
| | | | | | Let's always write "1 << 0", "1 << 1" and so on, except where we need more than 31 flag bits, where we write "UINT64(1) << 0", and so on to force 64bit values.
* process-util: add a new FORK_MOUNTNS_SLAVE flag for safe_fork()Lennart Poettering2018-05-241-0/+1
| | | | | | | | We already have a flag for creating a new mount namespace for the child. Let's add an extension to that: a new FORK_MOUNTNFS_SLAVE flag. When used in combination will mark all mounts in the child namespace as MS_SLAVE so that the child can freely mount or unmount stuff but it won't leak into the parent.
* process-util: add new helper call for adjusting the OOM scoreLennart Poettering2018-05-171-0/+2
| | | | And let's make use of it in execute.c