Commit Graph

55 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Andreas Rammhold 3742095b27
tree-wide: use IN_SET where possible
In addition to the changes from #6933 this handles cases that could be
matched with the included cocci file.
2017-10-02 13:09:54 +02:00
Zbigniew Jędrzejewski-Szmek a4041e4f68 Link to the right glibc commit in comment (#6884)
Reported by Marcos Mello.

Fixes #6882.
2017-09-21 20:54:16 +02:00
Lennart Poettering 21022b9dde util-lib: wrap personality() to fix up broken glibc error handling (#6766)
glibc appears to propagate different errors in different ways, let's fix
this up, so that our own code doesn't get confused by this.

See #6752 + #6737 for details.

Fixes: #6755
2017-09-08 17:16:29 +03:00
Lennart Poettering ee043777be tree-wide: use pid_is_valid() at more places 2017-08-31 15:45:04 +02:00
Lennart Poettering e8132d63fe seccomp: default to something resembling the current personality when locking it
Let's lock the personality to the currently set one, if nothing is
specifically specified. But do so with a grain of salt, and never
default to any exotic personality here, but only PER_LINUX or
PER_LINUX32.
2017-08-29 15:56:57 +02:00
Jouke Witteveen 01f989c662 process-util: update the end pointer of the process name on rename (#6492)
We only updated the end pointer when allocating new memory, i.e. on the first
call to rename_process.
2017-08-04 11:25:49 +02:00
Lennart Poettering 6f8cbcdb27 process-util: slightly optimize querying of our own process metadata
When we are checking our own data, we can optimize things a bit.
2017-07-31 18:20:28 +02:00
Lennart Poettering df0ff12775 tree-wide: make use of getpid_cached() wherever we can
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.
2017-07-20 20:27:24 +02:00
Lennart Poettering 5c30a6d2b8 process-util: add getpid_cached() as a caching wrapper for getpid()
Let's make getpid() fast again.
2017-07-20 20:27:24 +02:00
Lennart Poettering 7f452159b8 core: make IOSchedulingClass= and IOSchedulingPriority= settable for transient units
This patch is a bit more complex thant I hoped. In particular the single
IOScheduling= property exposed on the bus is split up into
IOSchedulingClass= and IOSchedulingPriority= (though compat is
retained). Otherwise the asymmetry between setting props and getting
them is a bit too nasty.

Fixes #5613
2017-06-26 17:43:18 +02:00
Zbigniew Jędrzejewski-Szmek e3f791a2b3 basic/path-util: allow flags for path_equal_or_files_same
No functional change, just a new parameters and the tests that
AT_SYMLINK_NOFOLLOW works as expected.
2017-06-17 12:37:16 -04:00
AsciiWolf 13e785f7a0 Fix missing space in comments (#5439) 2017-02-24 18:14:02 +01:00
stuart-mclaren a3d8d68cc1 Fix check for signal in set (#5416)
IN_SET(SIGCONT, SIGKILL) will always evaluate to false.
The signal needs to be included as the first argument.

Fixup for 26f417d3e8.
2017-02-21 15:39:52 -05:00
Zbigniew Jędrzejewski-Szmek c05347807f process-util: rename char *r to ans and add comment
Add a comment about the return value and rename r to ans. r is
nowadays reserved for the integer return value, and char *r is confusing.
2017-01-15 12:41:34 -05:00
Lennart Poettering 9bfaffd5a9 util-lib: rework rename_process() to be able to make use of PR_SET_MM_ARG_START
PR_SET_MM_ARG_START allows us to relatively cleanly implement process renaming.
However, it's only available with privileges. Hence, let's try to make use of
it, and if we can't fall back to the traditional way of overriding argv[0].

This removes size restrictions on the process name shown in argv[] at least for
privileged processes.
2016-12-14 18:29:30 +01:00
Zbigniew Jędrzejewski-Szmek 041b5ae170 basic/process-util: we need to take the shorter of two strings
==30496== Conditional jump or move depends on uninitialised value(s)
==30496==    at 0x489F654: memcmp (vg_replace_strmem.c:1091)
==30496==    by 0x49BF203: getenv_for_pid (process-util.c:678)
==30496==    by 0x4993ACB: detect_container (virt.c:442)
==30496==    by 0x182DFF: test_get_process_comm (test-process-util.c:98)
==30496==    by 0x185847: main (test-process-util.c:368)
==30496==
2016-11-17 20:57:22 -05:00
Zbigniew Jędrzejewski-Szmek 605405c6cc tree-wide: drop NULL sentinel from strjoin
This makes strjoin and strjoina more similar and avoids the useless final
argument.

spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c)

git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/'

This might have missed a few cases (spatch has a really hard time dealing
with _cleanup_ macros), but that's no big issue, they can always be fixed
later.
2016-10-23 11:43:27 -04:00
Lennart Poettering 26f417d3e8 util: don't send SIGCONT following a SIGCONT or SIGKILL in kill_and_sigcont() 2016-07-20 11:14:48 +02:00
Thomas Hindoe Paaboel Andersen 65a6195e76 basic: fix whitespace 2016-07-18 22:14:23 +02:00
Lennart Poettering 3f0083a264 tree-wide: some work-arounds for gcc false positives regarding uninitialized variables 2016-06-21 14:15:23 +02:00
Lennart Poettering b09df4e21d process-util: fix two bugs in get_process_cmdline() (#3555)
See:

https://github.com/systemd/systemd/pull/3529#issuecomment-226421007
2016-06-16 16:46:44 -04:00
Lennart Poettering 69281c49eb util-lib: rework get_process_cmdline() (#3529)
This reworks get_process_cmdline() quite substantially, fixing the following:

- Fixes:
  a4e3bf4d7a (r66837630)

- The passed max_length is also applied to the "comm" name, if comm_fallback is
  set.

- The right thing happens if max_length == 1 is specified

- when the cmdline "foobar" is abbreviated to 6 characters the result is not
  "foobar" instead of "foo...".

- trailing whitespace are removed before the ... suffix is appended. The 7
  character abbreviation of "foo barz" is hence "foo..." instead of "foo ...".

- leading whitespace are suppressed from the cmdline

- a comprehensive test case is added
2016-06-14 17:52:29 -04:00
Zbigniew Jędrzejewski-Szmek 4201ce672a process-util: remove broken support for pid==0
Our functions that query /proc/pid/ support using pid==0 to mean
self. get_process_id also seemed to support that, but it was not implemented
correctly: the result should be in *uid, not returned, and also it gave
completely bogus result when called from get_process_gid(). But afaict,
get_process_{uid,gid} were never called with pid==0, so it's not an actual
bug. Remove the broken code to avoid confusion.
2016-06-12 21:15:53 -04:00
Max Prokhorov ba4cd7e257 util-lib: drop trailing non-printable characters from cmdline (#3512)
If max_length is equal or greater than cmdline length all trailing non-printable
characters are dropped. If max_length is 0 it should do the same.

This should also fix cmdline truncation if the last character is not '\0'.

Fixes #3469.
2016-06-12 21:13:42 -04:00
Michael Karcher 8869a0b40b util-lib: Add sparc64 support for process creation (#3348)
The current raw_clone function takes two arguments, the cloning flags and
a pointer to the stack for the cloned child. The raw cloning without
passing a "thread main" function does not make sense if a new stack is
specified, as it returns in both the parent and the child, which will fail
in the child as the stack is virgin. All uses of raw_clone indeed pass NULL
for the stack pointer which indicates that both processes should share the
stack address (so you better don't pass CLONE_VM).

This commit refactors the code to not require the caller to pass the stack
address, as NULL is the only sensible option. It also adds the magic code
needed to make raw_clone work on sparc64, which does not return 0 in %o0
for the child, but indicates the child process by setting %o1 to non-zero.
This refactoring is not plain aesthetic, because non-NULL stack addresses
need to get mangled before being passed to the clone syscall (you have to
apply STACK_BIAS), whereas NULL must not be mangled. Implementing the
conditional mangling of the stack address would needlessly complicate the
code.

raw_clone is moved to a separete header, because the burden of including
the assert machinery and sched.h shouldn't be applied to every user of
missing_syscalls.h
2016-05-29 20:03:51 -04:00
Evgeny Vereshchagin 3da48d7aa9 core: set all log fds to -1 when freezing (#3314)
Fixes:
-bash-4.3# echo core >/proc/sys/kernel/core_pattern
-bash-4.3# kill -ABRT 1
-bash-4.3# kill -ABRT 1
[   61.373922] systemd[1]: segfault at 7fff1d0a8f48 ip 00007fc9ca91b1c3 sp 00007fff1d0a8f50 error 6 in libc-2.23.so[7fc9ca8ce000+1c0000]
[   61.768017] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000008b
[   61.768017]
...

Recursive ABRT and segfault:
PID 1 - core
TID 1:
...
 #153905 0x00005575fc3f829d log_dispatch
 #153906 0x00005575fc3f8aa3 log_assert
 #153907 0x00005575fc3f8ae9 log_assert_failed
 #153908 0x00005575fc3e7eb1 safe_close
 #153909 0x00005575fc3f6d5e log_close_journal
 #153910 0x00005575fc3f829d log_dispatch
 #153911 0x00005575fc3f85a1 log_internalv
 #153912 0x00005575fc3f86a1 log_internal
 #153913 0x00005575fc31c4c1 crash
 #153914 0x00007fb26f2cf3d0 __restore_rt
 #153915 0x00007fb26f2ced00 pause
 #153916 0x00005575fc403944 freeze
 #153917 0x00005575fc31bf7b freeze_or_reboot
...
2016-05-21 12:40:34 -04:00
Lennart Poettering 89c9030d31 util: rework sigkill_wait() to not require pid_t pointer
Let's make sigkill_wait() take a normal pid_t, and add sigkill_waitp() that
takes a pointer (which is useful for usage in _cleanup_), following the usual
logic we have for this.
2016-05-02 11:15:30 +02:00
Lennart Poettering 291d565a04 core,systemctl: add bus API to retrieve processes of a unit
This adds a new GetProcesses() bus call to the Unit object which returns an
array consisting of all PIDs, their process names, as well as their full cgroup
paths. This is then used by "systemctl status" to show the per-unit process
tree.

This has the benefit that the client-side no longer needs to access the
cgroupfs directly to show the process tree of a unit. Instead, it now uses this
new API, which means it also works if -H or -M are used correctly, as the
information from the specific host is used, and not the one from the local
system.

Fixes: #2945
2016-04-22 16:06:20 +02:00
Lennart Poettering 0c0fea07b8 util-lib: simplify personality() string matching 2016-02-22 23:23:06 +01:00
Lennart Poettering f2d1736c60 util-lib: support various ppc archs in personality logic 2016-02-22 23:23:06 +01:00
Lennart Poettering 6e5f1b5742 util-lib: use the architecture ids from architecture.h for personalities
We have this ids, hence let's use them universally.
2016-02-22 23:23:06 +01:00
Zbigniew Jędrzejewski-Szmek 79d6297252 Use (void) to silenc coverity on proc title changes
This is a cosmetic best-effort thing anyway.
2016-02-19 07:35:35 -05:00
Michal Sekletar 1359fffa57 shutdown: complain if process excluded from killing spree runs of the same rootfs as PID1 2016-01-26 14:13:13 +01:00
Evgeny Vereshchagin dcadc9671c core: add valgrind helper for daemon-reexec
Inspired by https://github.com/systemd/systemd/issues/2187#issuecomment-165587140
2016-01-21 01:32:05 +00:00
Thomas Hindoe Paaboel Andersen 93cc7779e0 basic: re-sort includes
My previous patch to only include what we use accidentially placed
the added inlcudes in non-sorted order.
2015-12-01 23:40:17 +01:00
Thomas Hindoe Paaboel Andersen 11c3a36649 basic: include only what we use
This is a cleaned up result of running iwyu but without forward
declarations on src/basic.
2015-11-30 21:51:03 +01:00
Lennart Poettering 7b3e062cb6 process-util: move a couple of process-related calls over 2015-10-27 14:24:58 +01:00
Lennart Poettering 5fd9b2c546 process-util: make some minor corrections to PID live detection 2015-10-27 14:02:45 +01:00
Lennart Poettering 6bc73acb01 process-util: rename get_parent_of_pid() → get_process_ppid()
In order to match the other get_process_xyz() calls.
2015-10-27 14:01:48 +01:00
Lennart Poettering 405f8907b9 process-util: actually move rename_process() over
The prototype was moved long ago, actually move the definition over now,
too.
2015-10-27 13:56:40 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering d4510856a0 util-lib: move is_main_thread() to process-util.[ch] 2015-10-27 13:25:57 +01:00
Lennart Poettering f4f15635ec util-lib: move a number of fs operations into fs-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 4d0d3d41d2 process-util: move more process related calls to process-util.[ch] 2015-10-26 01:24:39 +01:00
Lennart Poettering b1d4f8e154 util-lib: split out user/group/uid/gid calls into user-util.[ch] 2015-10-26 01:24:38 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file 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.
2015-10-24 23:05:02 +02:00
Lennart Poettering 4f5dd3943b util: split out escaping code into escape.[ch]
This really deserves its own file, given how much code this is now.
2015-10-24 23:04:42 +02:00
Aaro Koskinen c4cd1d4d93 fileio: make get_status_field() more generic
All users of get_status_field() expect the field pattern to occur in
the beginning of a line, and the delimiter is ':'.

Hardcode this into the function, and also skip any whitespace before ':'
to support fields in files like /proc/cpuinfo. Add support for returning
the full field value (currently stops on first whitespace).

Rename the function so it's easier to ensure all callers switch to new
semantics.
2015-09-30 15:57:55 +03:00