Commit Graph

206 Commits

Author SHA1 Message Date
Lennart Poettering 463f9ce3bc test: add test that validates that PTR_TO_INT(INT_TO_PTR()) covers whole int range 2020-10-07 09:40:09 +02:00
Lennart Poettering 1146b664e6 macro: add new FOREACH_POINTER() macro magic
This allows us to iterate through a series of specified pointers. It's a
bit like FOREACH_STRING(), but for all kinds of pointers.
2020-07-01 11:17:28 +02:00
Lennart Poettering 47ac31f792 test-util: add more tests for ALIGN_POWER2 2019-12-09 18:36:00 +01:00
Yu Watanabe 455fa9610c tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
Lennart Poettering cfb4a84942 util: don't include util.h from def.h
Nothing it defines is used in it.
2019-03-14 13:25:51 +01:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +01:00
Lennart Poettering eefc66aa8f util: split out some stuff into a new file limits-util.[ch] 2019-03-13 12:16:43 +01:00
Lennart Poettering 840f606d88 util.h: add new UNPROTECT_ERRNO macro
THis is inspired by #11395, but much simpler.
2019-02-08 10:34:47 +01:00
Zbigniew Jędrzejewski-Szmek 6b68c26824 test-util: drop _packed_ attribute
gcc-9 warns:
../src/test/test-util.c:147:19: note: in expansion of macro ‘container_of’
  147 |         assert_se(container_of(&myval.v1, struct mytype, v1) == &myval);
      |                   ^~~~~~~~~~~~

I don't think packing matters here for the test of container_of(), so let's
just remove it.
2019-02-04 20:32:44 +01:00
Zbigniew Jędrzejewski-Szmek 0192cbdb2c Revert "nss: prevent PROTECT_ERRNO from squashing changes to *errnop"
This reverts commit b26c904113.

I don't see anythign wrong, but Ubuntu autopkgtest CI started failing fairly
consistently since this was merged. Let's see if reverting fixes things.
2019-01-10 21:23:14 +01:00
Sam Morris b26c904113 nss: prevent PROTECT_ERRNO from squashing changes to *errnop
glibc passes in &errno for errnop, which means PROTECT_ERRNO ends up
squashing our intentional changes to *errnop.

Fixes #11321.
2019-01-10 11:08:42 +01:00
Yu Watanabe 36dd5ffd5d util: drop missing.h from util.h 2018-12-04 10:00:34 +01:00
Zbigniew Jędrzejewski-Szmek 7f6bfc561f basic/util: import memeqzero from casync 2018-11-18 16:12:53 +01:00
Zbigniew Jędrzejewski-Szmek 09c984c6f7 test-util: modernize 2018-11-18 10:47:16 +01:00
Yu Watanabe ef6e83f02b test: cast values in proper type to suppress warnings
Follow-up for #9789.
2018-08-07 15:40:16 +02:00
Filipe Brandenburger 84fb2131d0 macros: add CMP(a, b) macro.
Macro returns -1, 0, 1 depending on whether a < b, a == b or a > b.

It's safe to use on unsigned types.

Add tests to confirm corner cases are properly covered.
2018-08-06 19:19:05 -07:00
Zbigniew Jędrzejewski-Szmek d9b02e1697 tree-wide: drop copyright headers from frequent contributors
Fixes #9320.

for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do
  git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms'
done
2018-06-20 11:58:53 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
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.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
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.
2018-06-14 10:20:20 +02:00
Mike Gilbert 96f64eb574 basic: set errno in raw_clone() on sparc
sparc sets the carry bit when a syscall fails. Use this information to
set errno and return -1 as appropriate.

The added test case calls raw_clone() with flags known to be invalid
according to the clone(2) manpage.
2018-06-02 09:48:19 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
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.
2018-04-06 18:58:55 +02:00
Lennart Poettering dccca82b1a log: minimize includes in log.h
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)
2018-01-11 14:44:31 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Zbigniew Jędrzejewski-Szmek 09571e3ffc test-util: silence clang warning about unaligned access 2017-11-01 23:10:25 +01:00
Zbigniew Jędrzejewski-Szmek 89711996b3 basic/util: move execute_directory() to separate file
It's a fairly specialized function. Let's make new files for it and the tests.
2017-02-11 18:21:06 -05:00
Lennart Poettering 83f8e80857 core: support percentage specifications on TasksMax=
This adds support for a TasksMax=40% syntax for specifying values relative to
the system's configured maximum number of processes. This is useful in order to
neatly subdivide the available room for tasks within containers.
2016-07-22 15:33:12 +02:00
Lennart Poettering d8cf2ac79b util: introduce physical_memory_scale() to unify how we scale by physical memory
The various bits of code did the scaling all different, let's unify this,
given that the code is not trivial.
2016-06-14 20:01:45 +02:00
Lennart Poettering d9ab2bcf05 util: when determining the amount of memory on this system, take cgroup limit into account
When determining the amount of RAM in the system, let's make sure we also read
the root-level cgroup memory limit into account. This isn't particularly useful
on the host, but in containers it makes sure that whatever memory the container
got assigned is actually used for RAM size calculations.
2016-06-14 19:50:38 +02: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
Ronny Chevalier 31b5d98981 test-util: remove now unused includes 2016-03-03 19:04:07 +01:00
Ronny Chevalier ac229ed890 tests: move xattr-util related tests to test-xattr-util.c 2016-03-03 19:04:07 +01:00
Ronny Chevalier 6a4f4a0fa0 tests: move glob-util related tests to test-glob-util.c 2016-03-03 19:04:07 +01:00
Ronny Chevalier ac933e8ec4 tests: move io-util related tests to test-io-util 2016-03-03 19:04:06 +01:00
Ronny Chevalier d376cbb7b0 tests: move proc-cmdline related tests to test-proc-cmdline.c 2016-03-03 19:04:06 +01:00
Ronny Chevalier 09c303ce5b tests: move fstab-util related tests to test-fstab-util.c 2016-03-03 19:04:06 +01:00
Ronny Chevalier c270684afd tests: move fs-util related tests to test-fs-util.c 2016-03-03 19:04:06 +01:00
Ronny Chevalier f55211dbce tests: move conf-parser related tests to test-conf-parser.c 2016-03-03 19:04:06 +01:00
Ronny Chevalier 0999c8ade8 tests: move fd-util related tests to test-fd-util.c 2016-03-03 19:04:06 +01:00
Ronny Chevalier d5b29bb5d9 tests: move user-util related tests to test-user-util.c 2016-03-03 19:04:06 +01:00
Ronny Chevalier 6329266386 tests: move path-util related tests to test-path-util.c 2016-03-03 19:04:06 +01:00
Ronny Chevalier 897891f02e tests: move fileio related tests to test-fileio.c 2016-03-03 19:04:06 +01:00
Ronny Chevalier f4c13ad76f tests: move stat-util related tests to test-stat-util.c 2016-03-03 19:04:06 +01:00
Ronny Chevalier ede4edd31e tests: move signal-util related tests to test-signal-util.c 2016-03-03 18:46:58 +01:00
Ronny Chevalier 7ba365a9b2 tests: move cpu-set-util related tests to test-cpu-set-util.c 2016-03-03 18:46:58 +01:00
Ronny Chevalier cd3510707a tests: move web-util related tests to test-web-util.c 2016-03-03 18:46:58 +01:00
Ronny Chevalier b66de1f9d4 tests: move alloc related tests to test-alloc-util.c 2016-03-03 18:46:58 +01:00
Ronny Chevalier 45e0b1f68c tests: move escape related tests to test-escape.c 2016-03-03 18:46:58 +01:00
Ronny Chevalier ebde5cb261 tests: move strv related tests to test-strv.c 2016-03-03 18:46:58 +01:00
Ronny Chevalier 6571a64ec9 tests: move string related tests to test-string-util.c 2016-03-03 18:46:58 +01:00