summaryrefslogtreecommitdiff
path: root/src/shared/macro.h
Commit message (Collapse)AuthorAge
* resolved: add a DNS client stub resolverLennart Poettering2014-07-16
| | | | | | | Let's turn resolved into a something truly useful: a fully asynchronous DNS stub resolver that subscribes to network changes. (More to come: caching, LLMNR, mDNS/DNS-SD, DNSSEC, IDN, NSS module)
* shared: add MIN3 macroDavid Herrmann2014-07-11
| | | | | This is like MIN but evaluates 3 arguments. We already have MAX3, so add the equivalent for MIN.
* macro: add DISABLE_WARNING_SHADOWDavid Herrmann2014-06-16
| | | | | | | | | | | | | | | | | | As it turns out, we cannot use _Pragma in compound-statements. Therefore, constructs like MIN(MAX(a, b), x) will warn due to shadowed variable declarations. The DISABLE_WARNING_SHADOW macro can be used to suppress these. Note that using UNIQUE(_var) does not work either as GCC uses the last line of a macro-expansion for __LINE__, therefore, still causing both macros to have the same variables. We could use different variable-names for MIN and MAX, but that just hides the problem and still fails for MIN(something(MIN(a, b)), c). The only working solution is to use __COUNTER__ and pass it pre-evaluated as extra argument to a macro to use as name-prefix. This, however, makes all these macros much more complicated so I'll go with manual DISABLE_WARNING_SHADOW so far.
* shared: add ALIGN_POWER2 macroDavid Herrmann2014-05-13
| | | | | | Sounds easy, turns out to be horrible to implement: ALIGN_POWER2 returns the next higher power of 2. clz(0) is undefined, same is true for left-shift-overflows, yey, C rocks!
* macro: make sure we can use IN_SET() also with complex function calls as ↵Lennart Poettering2014-03-12
| | | | first argument
* logind: make $XDG_RUNTIME_DIR a per-user tmpfsLennart Poettering2014-03-04
| | | | | | | This way each user allocates from his own pool, with its own size limit. This puts the size limit by default to 10% of the physical RAM size but makes it configurable in logind.conf.
* macro: add nice macro for disabling -Wnonnull temporarilyLennart Poettering2014-02-20
|
* macro: introduce nice macro for disabling -Wmissing-prototypes warnigsLennart Poettering2014-02-20
|
* macro: introduce a nice macro for disabling -Wformat-nonliteral temporarilyLennart Poettering2014-02-20
|
* util: get rid of warnings around assert_cc() macroLennart Poettering2014-02-20
| | | | Suggested by Holger Schurig.
* journald: do not free space when disk space runs lowZbigniew Jędrzejewski-Szmek2014-01-11
| | | | | | | | | | | | | | | | | | | | | | | | | Before, journald would remove journal files until both MaxUse= and KeepFree= settings would be satisfied. The first one depends (if set automatically) on the size of the file system and is constant. But the second one depends on current use of the file system, and a spike in disk usage would cause journald to delete journal files, trying to reach usage which would leave 15% of the disk free. This behaviour is surprising for the user who doesn't expect his logs to be purged when disk usage goes above 85%, which on a large disk could be some gigabytes from being full. In addition attempting to keep 15% free provides an attack vector where filling the disk sufficiently disposes of almost all logs. Instead, obey KeepFree= only as a limit on adding additional files. When replacing old files with new, ignore KeepFree=. This means that if journal disk usage reached some high point that at some later point start to violate the KeepFree= constraint, journald will not add files to go above this point, but it will stay (slightly) below it. When journald is restarted, it forgets the previous maximum usage value, and sets the limit based on the current usage, so if disk remains to be filled, journald might use one journal-file-size less on each restart, if restarts happen just after rotation. This seems like a reasonable compromise between implementation complexity and robustness.
* _noreturn_ --> noreturn for C11 compatShawn Landden2013-12-17
| | | | also define noreturn w/o <stdnoreturn.h>
* __thread --> thread_local for C11 compatShawn Landden2013-12-17
| | | | | Also make thread_local available w/o including <threads.h>. (as the latter hasn't been implemented, but this part is trivial)
* macro: log assertion at debug level in assert_return()Lennart Poettering2013-12-10
|
* macro: better make IN_SET() macro use const arraysLennart Poettering2013-12-03
|
* macro: add a macro to test whether a value is in a specified listLennart Poettering2013-12-02
| | | | | | | | | | | | | | | Introduce IN_SET() macro to nicely check whether a value a is one of a few listed values. This makes writing this: if (a == 1 || a == 7 || a == 8 || a == 9) nicer, by allowing this: if (IN_SET(a, 1, 7, 8, 9)) This is particularly useful for state machine enums.
* macro.h: fix typo in commentThomas Hindoe Paaboel Andersen2013-11-30
|
* swap: split state machine state ACTIVATING into twoLennart Poettering2013-11-25
| | | | | We expect the event on /proc/swaps before we expect the SIGCHILD, reflect this in the state machine.
* macro: fix problem with __LINE__ macro expansionLukasz Skalski2013-11-22
| | | | | | | David: I already applied a fix for that, but this patch definitely looks nicer. I changed CONCATENATE_HELPER() -> XCONCATENATE() similar to XSTRINGIFY and added the UNIQUE() helper.
* macro: fix assert_cc() fallbackDavid Herrmann2013-11-22
| | | | | We need two-level macro-expansion, otherwise __LINE__ will not get evaluated.
* macro: add _unlikely_() to assert_return()Lennart Poettering2013-11-20
| | | | | | | As the name indicates assert_return() is really just for assertions, i.e. where it's a programming error if the assertion does not hold. Hence it is safe to add _unlikely_() decorators for the expression to check.
* macro: change assert_cc() so that it can appear outside of functionsLennart Poettering2013-11-20
|
* util: add circle to special chars we can drawLennart Poettering2013-11-07
|
* bus: remove static introspection file exportKay Sievers2013-10-21
|
* macro: clean up usage of gcc attributesLennart Poettering2013-10-16
| | | | Always use our own macros, and name all our own macros the same style.
* macro: add new assert_return() macro for early parameter checking in functionsLennart Poettering2013-10-11
| | | | | | | | | | | | | | | | | | For the library functions we expose we currently repeatedly use checks like the following: if (!value_is_ok(parameter1)) return -EINVAL; if (!value_is_ok(parameter2)) return -EINVAL; And so on. Let's turn this into a macro: assert_return(value_is_ok(parameter1), -EINVAL); assert_return(value_is_ok(paramater2), -EINVAL); This makes our code a bit shorter and simpler, and also allows us to add a _unlikely_() around the check.
* remove hasprefix(), use startswith()Shawn Landden2013-08-22
|
* Rename F_TYPE_CMP() to F_TYPE_EQUAL()Zbigniew Jędrzejewski-Szmek2013-08-20
|
* Add hasprefix macro to check prefixes of fixed lengthZbigniew Jędrzejewski-Szmek2013-06-20
|
* bus: add APIs for negotiating what is attached to messagesLennart Poettering2013-05-17
|
* bus: add and use UINT64_TO_PTR()Kay Sievers2013-05-14
|
* Make up for attribute malloc with alloc_sizeZbigniew Jędrzejewski-Szmek2013-04-25
| | | | | | It is imperative that open source code be well attributed. Sprinkle attribute((alloc_size)) here and there, telling gcc how much memory we are actually allocating.
* Reintroduce f_type comparison macroHarald Hoyer2013-04-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 4826f0b7b5c0aefa08b8cc7ef64d69027f84da2c. Because statfs.t_type can be int on some architecures, we have to cast the const magic to the type, otherwise the compiler warns about signed/unsigned comparison, because the magic can be 32 bit unsigned. statfs(2) man page is also wrong on some systems, because f_type is not __SWORD_TYPE on some architecures. The following program: int main(int argc, char**argv) { struct statfs s; statfs(argv[1], &s); printf("sizeof(f_type) = %d\n", sizeof(s.f_type)); printf("sizeof(__SWORD_TYPE) = %d\n", sizeof(__SWORD_TYPE)); printf("sizeof(long) = %d\n", sizeof(long)); printf("sizeof(int) = %d\n", sizeof(int)); if (sizeof(s.f_type) == sizeof(int)) { printf("f_type = 0x%x\n", s.f_type); } else { printf("f_type = 0x%lx\n", s.f_type); } return 0; } executed on s390x gives for a btrfs: sizeof(f_type) = 4 sizeof(__SWORD_TYPE) = 8 sizeof(long) = 8 sizeof(int) = 4 f_type = 0x9123683e
* Revert f_type fixupsHarald Hoyer2013-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit a858b64dddf79177e12ed30f5e8c47a1471c8bfe. This reverts commit aea275c43194b6ac519ef907b62c5c995050fde0. This reverts commit fc6e6d245ee3989c222a2a8cc82a33475f9922f3. This reverts commit c4073a27c555aeceac87a3b02a83141cde641a1e. This reverts commit cddf148028f525be8176e7f1cbbf4f862bd287f6. This reverts commit 8c68a70170b31f93c287f29fd06c6c17edaf19ad. The constants are now casted to __SWORD_TYPE, which should resolve the compiler warnings about signed vs unsigned. After talking to Kay, we concluded: This should be fixed in the kernel, not worked around in userspace tools. Architectures cannot use int and expect magic constants lager than INT_MAX to work correctly. The kernel header needs to be fixed. Even coreutils cannot handle it: #define RAMFS_MAGIC 0x858458f6 # stat -f -c%t / ffffffff858458f6 #define BTRFS_SUPER_MAGIC 0x9123683E # stat -f -c%t /mnt ffffffff9123683e Although I found the perfect working macro to fix the thing :) __extension__ ({ \ bool _ret = false; \ switch(f) { case c: _ret=true; }; \ ( _ret ); \ })
* macro.h: let F_TYPE_CMP() macro fail to compile, if second parameter is not ↵Harald Hoyer2013-04-18
| | | | | | | const If the magic parameter is not a const, then the macro does not work, so better fail to compile, than be surprised afterwards.
* rename CMP_F_TYPE to F_TYPE_CMPHarald Hoyer2013-04-18
|
* Add ugly CMP_F_TYPE() macroHarald Hoyer2013-04-18
| | | | | | | | | | | | | | | | | | On some architectures (like s390x) the kernel has the type int for f_type, but long in userspace. Assigning the 32 bit magic constants from linux/magic.h to the 31 bit signed f_type in the kernel, causes f_type to be negative for some constants. glibc extends the int to long for those architecures in 64 bit mode, so the negative int becomes a negative long, which cannot be simply compared to the original magic constant, because the compiler would automatically cast the constant to long. To workaround this issue, we also compare to the (int)MAGIC value in a macro. Of course, we could do #ifdef with the architecure, but it has to be maintained, and the magic constants are 32 bit anyway. Someday, when the int is unsigned or long for all architectures, we can remove this macro again. Until then, keep it as simple as it can be.
* util: make generation of profcs PID paths nicerLennart Poettering2013-04-16
|
* macro: rework how we define cleanup macrosLennart Poettering2013-04-16
| | | | | | | | There's now a generic _cleanup_ macro with an argument. The macros for specific types are now defined using this macro, and in the header files where they belong. All cleanup handlers are now inline functions.
* bus: don't calculate kmsg message too largeLennart Poettering2013-04-12
|
* macro: make sure ALIGN() can be calculated constant by the compilerLennart Poettering2013-04-11
| | | | | | If we pass a constant value to ALIGN() gcc should have the chance to calculate the value during compilation rather than runtime, so let's avoid a static inline call if we can.
* macro: add macro for precisely determining length of decimal string ↵Lennart Poettering2013-04-02
| | | | formatting of a numeric type
* Always use our own MAX/MIN definitionsCristian Rodríguez2013-04-01
| | | | | | | | | | | | | | | | | | code in src/shared/macro.h only defined MAX/MIN in case they were not defined previously. however the MAX/MIN macros implemented in glibc are not of the "safe" kind but defined as: define MIN(a,b) (((a)<(b))?(a):(b)) define MAX(a,b) (((a)>(b))?(a):(b)) Avoid nasty side effects by using our own versions instead. Also fix the warnings derived from this change. [zj: - modify MAX3 macro to fix warning about _a shadowing _a, - do bootchart/svg.c too, - remove unused MIN3.]
* tests: skip bus test if bus cannot be openedZbigniew Jędrzejewski-Szmek2013-03-26
| | | | | | To make the result more visible, special return value is used to tell automake that the test was skipped. While at it, use the same return value in other skipped tests.
* macro: add CHAR_TO_STR macro to make a one character string from a charLennart Poettering2013-03-20
|
* macro: don't redefine CLAMP if it is already defined by glib or some other ↵Lennart Poettering2013-03-20
| | | | library
* journal,shared: add _cleanup_journal_close_Zbigniew Jędrzejewski-Szmek2013-03-18
|
* shared: introduce _cleanup_set_free_free_Zbigniew Jędrzejewski-Szmek2013-01-29
|
* Add _cleanup_pclose_ and fix mismatching pipe close opened by popen()Zbigniew Jędrzejewski-Szmek2013-01-25
| | | | | | | Based-on-patch-by: Thomas Jarosch <thomas.jarosch@intra2net.com> cppcheck reported: [src/bootchart/svg.c:791]: (error) Mismatching allocation and deallocation: f
* localectl: use automatic cleanupZbigniew Jędrzejewski-Szmek2013-01-07
| | | | set_freep() is added to automatize set_free().