Commit Graph

68 Commits

Author SHA1 Message Date
Yu Watanabe 666a84eaca macro: include errno.h
As several macros touch errno.
2018-12-06 07:01:29 +01:00
Lennart Poettering 63e688cc3b
Merge pull request #11031 from poettering/gcc-attr-cleanup
various gcc attribute clean-ups
2018-12-03 21:59:00 +01:00
Lennart Poettering 026c2677fc macro: add macro for llvm no_sanitize_address attribute
We want it for global variables, which LLVM supports and GCC currently
does not (GCC does support it for functions, but we care about global
variables here).

Why is this relevant? When asan is used global variables are padded with
hotzones before and after. But we can't have that for the registration
variables we place in special ELF sections: we want them tightly packed
so that we can iterate through them.

Note that for gcc this isn't an issue, as it will pack stuff in
non-standard sections anyway, even if asan is used.
2018-12-03 17:35:50 +01:00
Lennart Poettering be5f77b26e macro: define HAS_FEATURE_ADDRESS_SANITIZER also on gcc
Let's make differences between compilers more minimal.
2018-12-03 17:35:50 +01:00
Evgeny Vereshchagin 289acab951 util-lib: introduce HAS_FEATURE_ADDRESS_SANITIZER
https://clang.llvm.org/docs/AddressSanitizer.html#conditional-compilation-with-has-feature-address-sanitizer
2018-12-03 17:35:42 +01:00
Lennart Poettering 2ee1c55d6c tree-wide: drop redundant space between __attribute__ and ((
We follow no general rule, but in most cases we do not place a space
outside of macro.h. Hence let's stick to that, and adapt macro.h too,
and follow the rule systematically that there shall not be a space
between __attribute__ and ((...

Yes, this does not matter at all, and is purely OCD cosmetics. But then
again, the uses of __attribute__ are very local only, hence the changes
cleaning this up are small and are unlikely to have to be repeated too
often...
2018-12-03 13:28:26 +01:00
Lennart Poettering d752090f3e macro: add macros for a couple of more gcc attributes we use 2018-12-03 13:28:26 +01:00
Yu Watanabe 1e26b1dfc7 macro: introduce DEFINE_TRIVIAL_DESTRUCTOR() macro 2018-12-02 06:21:11 +01:00
Lennart Poettering 8a453c9dfc macro: update DIV_ROUND_UP() so that it can be called nested 2018-11-30 16:46:10 +01:00
Yu Watanabe fd05c424c0 libudev: introduce return_with_errno() and use it where applicable 2018-11-22 23:49:55 +09:00
Lennart Poettering 012c2f761b tree-wide: use __ prefixed gcc attributes (#10843)
As suggest here:

https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax

    "You may optionally specify attribute names with ‘__’ preceding and
    following the name. This allows you to use them in header files without
    being concerned about a possible macro of the same name. For example,
    you may use the attribute name __noreturn__ instead of noreturn. "
2018-11-20 12:34:08 +09:00
Lennart Poettering 5e332028f2 util-lib: move main() definition macros to its own header file
This way, we can extend the macro a bit with stuff pulled in from other
headers without this affecting everything which pulls in macro.h, which
is one of our most basic headers.

This is just refactoring, no change in behaviour, in prepartion for
later changes.
2018-11-19 21:14:34 +01:00
Lennart Poettering 2a44bf5099
Merge pull request #10811 from keszybz/define-main-through-macro
Define main through macro
2018-11-19 15:28:17 +01:00
Zbigniew Jędrzejewski-Szmek 9a5cedc319 ac-power: define main through macro
I decided to use a separate definition for this because it's too easy to return
positive from functions which don't need this distinction and only return
negative on error and success otherwise.
2018-11-17 09:13:35 +01:00
Zbigniew Jędrzejewski-Szmek a974a6569e Introduce main definer and use it in cgtop
This actually fixes one bogus return code in error path.
2018-11-17 09:03:54 +01:00
Lennart Poettering 222c8d4e22 macro: remove double evaluation in FLAGS_SET() 2018-11-17 08:45:24 +01:00
Zbigniew Jędrzejewski-Szmek 05f339267e
Merge pull request #10378 from poettering/json-fuzz-fix
json: a comprehensive fix for oss-fuzz#10908
2018-10-25 16:25:39 +02:00
Yu Watanabe 14cb109d45 tree-wide: replace 'unsigned int' with 'unsigned' 2018-10-19 22:19:12 +02:00
Lennart Poettering 7e61bd0f67 macro.h: include assert.h so that static_assert can be properly checked for
For the definition of assert_cc() we try to use static_assert and check
for it with "#ifdef". But that can only work if assert.h is imported
before. Hence let's do so.
2018-10-18 16:44:51 +02:00
Lennart Poettering 8e2b687957 macro: rework IN_SET a bit
This makes use of assert_cc() to guard against missing CASE macros,
instead of a manual implementation that might result in a static
variable to be allocated.

More importantly though this changes the base type for the array used to
determine the number of arguments for the compile time check from "int"
to "long double". This is done in order to avoid warnings from "ubsan"
that possibly large constants are assigned to small types. "long double"
hopefully isn't vulnerable to that.

Fixes: #10332
2018-10-11 22:07:14 +02:00
Lennart Poettering 696c0b890e macro: drop -Wdeclaration-after-statement exclusion magic, we dropped that warning anyway from our build 2018-10-11 22:05:55 +02:00
Yu Watanabe a6a08596ef macro: introduce DEFINE_TRIVIAL_REF_UNREF_FUNC() macro and friends 2018-08-27 14:01:27 +09: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
Filipe Brandenburger 117efe065a macro: drop __extension__, reformat and reindent
Drop __extension__, since we don't use gcc -Wpedantic or -ansi.

Reformat code for spacing. Add spaces after commas almost everywhere.
Reindent code blocks in macro definitions, for consistency.
2018-08-06 19:15:02 -07:00
Filipe Brandenburger d9fb7afb48 coverity: Add custom assertion macros for Coverity
These custom macros make the expression go through a function, in order
to prevent ASSERT_SIDE_EFFECT false positives on our macros such as
assert_se() and assert_return() that cannot be disabled and will always
evaluate their expressions.

This technique has been described and recommended in:
https://community.synopsys.com/s/question/0D534000046Yuzb/suppressing-assertsideeffect-for-functions-that-allow-for-sideeffects

Tested by doing a local cov-build and uploading the resulting tarball to
scan.coverity.com, confirmed that the ASSERT_SIDE_EFFECT false positives
were gone.
2018-07-19 09:07:25 +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
Zbigniew Jędrzejewski-Szmek d94a24ca2e Add macro for checking if some flags are set
This way we don't need to repeat the argument twice.
I didn't replace all instances. I think it's better to leave out:
- asserts
- comparisons like x & y == x, which are mathematically equivalent, but
  here we aren't checking if flags are set, but if the argument fits in the
  flags.
2018-06-04 11:50:44 +02:00
Lennart Poettering ce2090ab72 macro: don't rely on C's downgrade-to-bool feature for numeric comparisons 2018-04-12 11:02:47 +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
Zbigniew Jędrzejewski-Szmek 989290dbf1 fuzz-unit-file: add __has_feature(memory_sanitizer) when skipping ListenNetlink=
https://clang.llvm.org/docs/MemorySanitizer.html#id5 documents this
check as the way to detect MemorySanitizer at compilation time. We
only need to skip the test if MemorySanitizer is used.

Also, use this condition in cg_slice_to_path(). There, the code that is
conditionalized is not harmful in any way (it's just unnecessary), so remove
the FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION condition.

Fixes #8482.
2018-03-26 15:28:03 +02:00
Franck Bui 848e863acc basic/macros: rename noreturn into _noreturn_ (#8456)
"noreturn" is reserved and can be used in other header files we include:

  [   16s] In file included from /usr/include/gcrypt.h:30:0,
  [   16s]                  from ../src/journal/journal-file.h:26,
  [   16s]                  from ../src/journal/journal-vacuum.c:31:
  [   16s] /usr/include/gpg-error.h:1544:46: error: expected ‘,’ or ‘;’ before ‘)’ token
  [   16s]  void gpgrt_log_bug (const char *fmt, ...)    GPGRT_ATTR_NR_PRINTF(1,2);

Here we include grcrypt.h (which in turns include gpg-error.h) *after* we
"noreturn" was defined in macro.h.
2018-03-15 14:23:46 +09:00
Zbigniew Jędrzejewski-Szmek f6a8265b9a core: drop unnecessary __useless_struct_to_allow_trailing_semicolon__
ISO C does not allow empty statements outside of functions, and gcc
will warn the trailing semicolons when compiling with -pedantic:

  warning: ISO C does not allow extra ‘;’ outside of a function [-Wpedantic]

But our code cannot compile with -pedantic anyway, at least because

  warning: ISO C does not support ‘__PRETTY_FUNCTION__’ predefined identifier [-Wpedantic]

Without -pedatnic, clang and even old gcc (3.4) generate no warnings about
those semicolons, so let's just drop __useless_struct_to_allow_trailing_semicolon__.
2018-03-06 10:41:41 +01:00
Zbigniew Jędrzejewski-Szmek 963c6c90af coverity: don't use (void)0 under coverity
I'm not sure why this is needed, but apparrently coverity doesn't like
(void)0. With this change, coverity can (almost) build systemd:

CFLAGS='-D_Float128="long double"' meson cov-build -Dman=false && \
  CCACHE_DISABLE=1 COVERITY_UNSUPPORTED=1 cov-build --dir cov-int ninja -C cov-build

Patch originially by Marek Cermak <macermak@redhat.com>.
2018-01-04 13:44:39 +01:00
Thomas Haller 6febe75da7 basic/macros: add STRLEN() to get length of string literal as constant expression
While the compiler likely optimizes strlen(x) for string literals,
it is not a constant expression.

Hence,

  char buffer[strlen("OPTION_000") + 1];

declares a variable-length array. STRLEN() can be used instead
when a constant espression is needed.

It's not entirely identical to strlen(), as STRLEN("a\0") counts 2.
Also, it only works with string literals and the macro enforces
that the argument is a literal.
2017-12-13 11:12:07 +01:00
Shawn Landden fb8e74a499 __attribute__((fallthrough)) only when -Wimplicit-fallthrough (#7448)
That is version 7 or greater
https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/

Fix regression of https://github.com/systemd/systemd/pull/7389
82a27ba821
on older gccs

bumping to re-run CI
upstream             FAIL timed out
boot-smoke           FAIL non-zero exit status 1
2017-11-24 10:08:12 +01:00
Shawn Landden 4831981d89 tree-wide: adjust fall through comments so that gcc is happy
Distcc removes comments, making the comment silencing
not work.

I know there was a decision against a macro in commit
ec251fe7d5
2017-11-20 13:06:25 -08: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 afc5fc1ffa tree-wide: drop assert.h includes
We provide an independent reimplementation in macro.h, and that's the one
we want to use. Including the system header is unnecessary and confusing.
2017-05-13 15:44:30 -04:00
Tobias Jungel 13b498f967 networkd: add support to configure VLAN on bridge ports 2016-06-10 09:10:41 +02:00
Daniel Mack c31be17f6b Merge pull request #2848 from keszybz/clang-warnings
Clang warnings
2016-03-17 16:41:20 +01:00
Zbigniew Jędrzejewski-Szmek 26e9e10b39 basic/macros: clang 3.5 doesn't support alloc_size
The attribute was removed in commit c047507 in the clang repository as it
was never properly implemented anyway. Avoid using the attribute with
clang because it generates a ton of annoying warnings.
2016-03-15 19:40:33 -04:00
Mike Frysinger 27d13af71c include sys/sysmacros.h in more places
Since glibc is moving away from implicitly including sys/sysmacros.h
all the time via sys/types.h, include the header directly in more
places.  This seems to cover most makedev/major/minor usage.
2016-03-14 23:29:10 -04:00
Zbigniew Jędrzejewski-Szmek 6014237390 Merge pull request #2702 from poettering/resolved-iterate-fix
resolved iteration fix
2016-02-29 23:18:16 -05:00
Vito Caputo 9ed794a32d tree-wide: minor formatting inconsistency cleanups 2016-02-23 14:20:34 -08:00
Lennart Poettering 35aa04e9ed resolved: fix notification iteration logic when transactions are completed
When a transaction is complete, and we notify its owners, make sure we deal
correctly with the requesters removing themselves from the list of owners while
we continue iterating.

This was previously already dealt with with transactions that require other
transactions for DNSSEC purposes, fix this for other possibly transaction
owners too now.

Since iterating through "Set" objects is not safe regarding removal of entries
from it, rework the logic to use two Sets, and move each entry we notified from
one set to the other set before we dispatch the notification. This move operation
requires no additional memory, and enables us to ensure that we don't notify
any object twice.

Fixes: #2676
2016-02-22 23:24:47 +01:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Daniel Mack d5b26d50fc macro.h: provide a switch-case statement generator for IN_SET
Rather than walking a list of valid values one-by-one, generate a
switch-case statement for the IN_SET() macro. This allows the compiler to
further optimize its code output, possibly by generating jump tables.
This effectively decreases the binary size slightly.

The implementation is based on macro overloading depending on the number of
arguments. h/t to the following post:

  https://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments
2016-01-11 12:02:36 +01:00
Lennart Poettering a0f29c767a util-lib: move CONF_DIRS_NULSTR definition to def.h
After all, this is not some compiler or C magic, but something very
specific to how systemd works, hence let's move it into def.h, and out
of macro.h
2015-11-03 17:45:11 +01:00
Lennart Poettering 7d50b32a12 util-lib: split out globbing related calls into glob-util.[ch] 2015-10-27 13:25:58 +01:00