1 commit 0e50bfaefde2a01792f4e4bcad7e0d822c74835b
2 Author: Yu Watanabe <watanabe.yu+github@gmail.com>
3 Date: Mon Dec 25 19:42:42 2017 +0900
5 meson: define _GNU_SOURCE to detect copy_file_range() (#7734)
7 Follow-up for bad7a0c81f501fbbcc79af9eaa4b8254441c4a1f of git
10 Recently glibc added `copy_file_range()`, but to use it,
11 `_GNU_SOURCE` needs to be defined. This adds the flag in
12 meson.build to detect the function by meson correctly.
14 diff --git a/meson.build b/meson.build
15 index be8e61045..f3a65b389 100644
18 @@ -468,7 +468,8 @@ foreach ident : [
19 ['kcmp', '''#include <linux/kcmp.h>'''],
20 ['keyctl', '''#include <sys/types.h>
21 #include <keyutils.h>'''],
22 - ['copy_file_range', '''#include <sys/syscall.h>
23 + ['copy_file_range', '''#define _GNU_SOURCE
24 + #include <sys/syscall.h>
25 #include <unistd.h>'''],
26 ['bpf', '''#include <sys/syscall.h>
27 #include <unistd.h>'''],
28 commit 85db59b794d1ca7f16ea816c916bb4472958cc1b
29 Author: Lennart Poettering <lennart@poettering.net>
30 Date: Mon Dec 25 12:01:14 2017 +0100
32 meson: use "args" for setting _GNU_SOURCE when checking for functions
34 This reworks how we set _GNU_SOURCE when checking for the availability
37 1. We set it for most of the functions we look for. After all we set it
38 for our entire built anyway, and it's usually how Linux-specific
39 definitions in glibc are protected these days. Given that we usually
40 have checks for such modern stuff only anyway, let's just blanket enable
43 2. Use "args" instead of "prefix" to set the macro. This is what is
44 suggested in the meson docs, hence let's do it.
46 diff --git a/meson.build b/meson.build
47 index f3a65b389..eda9e382b 100644
50 @@ -431,29 +431,26 @@ foreach ident : [
51 ['memfd_create', '''#include <sys/memfd.h>'''],
52 ['gettid', '''#include <sys/types.h>'''],
53 ['pivot_root', '''#include <stdlib.h>'''], # no known header declares pivot_root
54 - ['name_to_handle_at', '''#define _GNU_SOURCE
55 - #include <sys/types.h>
56 + ['name_to_handle_at', '''#include <sys/types.h>
58 #include <fcntl.h>'''],
59 - ['setns', '''#define _GNU_SOURCE
60 - #include <sched.h>'''],
61 + ['setns', '''#include <sched.h>'''],
62 ['renameat2', '''#include <stdio.h>'''],
63 ['kcmp', '''#include <linux/kcmp.h>'''],
64 ['keyctl', '''#include <sys/types.h>
65 #include <keyutils.h>'''],
66 - ['copy_file_range', '''#define _GNU_SOURCE
67 - #include <sys/syscall.h>
68 + ['copy_file_range', '''#include <sys/syscall.h>
69 #include <unistd.h>'''],
70 ['bpf', '''#include <sys/syscall.h>
71 #include <unistd.h>'''],
72 ['explicit_bzero' , '''#include <string.h>'''],
75 - have = cc.has_function(ident[0], prefix : ident[1])
76 + have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE')
77 conf.set10('HAVE_' + ident[0].to_upper(), have)
80 -if cc.has_function('getrandom', prefix : '''#include <sys/random.h>''')
81 +if cc.has_function('getrandom', prefix : '''#include <sys/random.h>''', args : '-D_GNU_SOURCE')
82 conf.set10('USE_SYS_RANDOM_H', true)
83 conf.set10('HAVE_GETRANDOM', true)
86 missing_syscall: when adding syscall replacements, use different names (
90 In meson.build we check that functions are available using:
91 meson.get_compiler('c').has_function('foo')
92 which checks the following:
93 - if __stub_foo or __stub___foo are defined, return false
94 - if foo is declared (a pointer to the function can be taken), return true
95 - otherwise check for __builtin_memfd_create
97 _stub is documented by glibc as
98 It defines a symbol '__stub_FUNCTION' for each function
99 in the C library which is a stub, meaning it will fail
100 every time called, usually setting errno to ENOSYS.
102 So if __stub is defined, we know we don't want to use the glibc version, but
103 this doesn't tell us if the name itself is defined or not. If it _is_ defined,
104 and we define our replacement as an inline static function, we get an error:
106 In file included from ../src/basic/missing.h:1358:0,
107 from ../src/basic/util.h:47,
108 from ../src/basic/calendarspec.h:29,
109 from ../src/basic/calendarspec.c:34:
110 ../src/basic/missing_syscall.h:65:19: error: static declaration of 'memfd_create' follows non-static declaration
111 static inline int memfd_create(const char *name, unsigned int flags) {
113 .../usr/include/bits/mman-shared.h:46:5: note: previous declaration of 'memfd_create' was here
114 int memfd_create (const char *__name, unsigned int __flags) __THROW;
117 To avoid this problem, call our inline functions different than glibc,
118 and use a #define to map the official name to our replacement.
123 - use "missing_" as the prefix instead of "_"
126 - rebase and update for statx()
128 Unfortunately "statx" is also present in "struct statx", so the define
129 causes issues. Work around this by using a typedef.
131 I checked that systemd compiles with current glibc
132 (glibc-devel-2.26-24.fc27.x86_64) if HAVE_MEMFD_CREATE, HAVE_GETTID,
133 HAVE_PIVOT_ROOT, HAVE_SETNS, HAVE_RENAMEAT2, HAVE_KCMP, HAVE_KEYCTL,
134 HAVE_COPY_FILE_RANGE, HAVE_BPF, HAVE_STATX are forced to 0.
136 Setting HAVE_NAME_TO_HANDLE_AT to 0 causes an issue, but it's not because of
137 the define, but because of struct file_handle.
140 backport https://github.com/systemd/systemd/commit/5187dd2c403caf92d09f3491e41f1ceb3f10491f
142 Signed-off-by: Khem Raj <raj.khem@gmail.com>
143 Upstream-Status: Backport [https://github.com/systemd/systemd/issues/8099]
144 Index: git/src/basic/missing_syscall.h
145 ===================================================================
146 --- git.orig/src/basic/missing_syscall.h
147 +++ git/src/basic/missing_syscall.h
149 #include <sys/types.h>
152 -static inline int pivot_root(const char *new_root, const char *put_old) {
153 +static inline int missing_pivot_root(const char *new_root, const char *put_old) {
154 return syscall(SYS_pivot_root, new_root, put_old);
157 +# define pivot_root missing_pivot_root
160 #if !HAVE_CANONICALIZE_FILE_NAME
161 @@ -68,7 +70,7 @@ static inline char *canonicalize_file_na
165 -static inline int memfd_create(const char *name, unsigned int flags) {
166 +static inline int missing_memfd_create(const char *name, unsigned int flags) {
167 # ifdef __NR_memfd_create
168 return syscall(__NR_memfd_create, name, flags);
170 @@ -76,6 +78,8 @@ static inline int memfd_create(const cha
175 +# define memfd_create missing_memfd_create
178 /* ======================================================================= */
179 @@ -115,7 +119,7 @@ static inline int memfd_create(const cha
183 -static inline int getrandom(void *buffer, size_t count, unsigned flags) {
184 +static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) {
185 # ifdef __NR_getrandom
186 return syscall(__NR_getrandom, buffer, count, flags);
188 @@ -123,14 +127,18 @@ static inline int getrandom(void *buffer
193 +# define getrandom missing_getrandom
196 /* ======================================================================= */
199 -static inline pid_t gettid(void) {
200 +static inline pid_t missing_gettid(void) {
201 return (pid_t) syscall(SYS_gettid);
204 +# define gettid missing_gettid
207 /* ======================================================================= */
208 @@ -158,7 +166,7 @@ struct file_handle {
209 unsigned char f_handle[0];
212 -static inline int name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
213 +static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
214 # ifdef __NR_name_to_handle_at
215 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
217 @@ -166,6 +174,8 @@ static inline int name_to_handle_at(int
222 +# define name_to_handle_at missing_name_to_handle_at
225 /* ======================================================================= */
226 @@ -183,7 +193,7 @@ static inline int name_to_handle_at(int
230 -static inline int setns(int fd, int nstype) {
231 +static inline int missing_setns(int fd, int nstype) {
233 return syscall(__NR_setns, fd, nstype);
235 @@ -191,6 +201,8 @@ static inline int setns(int fd, int nsty
240 +# define setns missing_setns
243 /* ======================================================================= */
244 @@ -236,7 +248,7 @@ static inline pid_t raw_getpid(void) {
248 -static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
249 +static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
250 # ifdef __NR_renameat2
251 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
253 @@ -244,12 +256,14 @@ static inline int renameat2(int oldfd, c
258 +# define renameat2 missing_renameat2
261 /* ======================================================================= */
264 -static inline int kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
265 +static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
267 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
269 @@ -257,36 +271,44 @@ static inline int kcmp(pid_t pid1, pid_t
274 +# define kcmp missing_kcmp
277 /* ======================================================================= */
280 -static inline long keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
281 +static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
283 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
289 +# define keyctl missing_keyctl
292 -static inline key_serial_t add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
293 +static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
295 return syscall(__NR_add_key, type, description, payload, plen, ringid);
301 +# define add_key missing_add_key
304 -static inline key_serial_t request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
305 +static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
306 # ifdef __NR_request_key
307 return syscall(__NR_request_key, type, description, callout_info, destringid);
313 +# define request_key missing_request_key
317 @@ -313,10 +335,10 @@ static inline key_serial_t request_key(c
321 -static inline ssize_t copy_file_range(int fd_in, loff_t *off_in,
322 - int fd_out, loff_t *off_out,
324 - unsigned int flags) {
325 +static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in,
326 + int fd_out, loff_t *off_out,
328 + unsigned int flags) {
329 # ifdef __NR_copy_file_range
330 return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
332 @@ -324,6 +346,8 @@ static inline ssize_t copy_file_range(in
337 +# define copy_file_range missing_copy_file_range
340 /* ======================================================================= */
341 @@ -351,7 +375,7 @@ static inline ssize_t copy_file_range(in
345 -static inline int bpf(int cmd, union bpf_attr *attr, size_t size) {
346 +static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
348 return (int) syscall(__NR_bpf, cmd, attr, size);
350 @@ -360,6 +384,7 @@ static inline int bpf(int cmd, union bpf
354 +# define bpf missing_bpf
357 /* ======================================================================= */
358 commit 848e863acc51ecfb0f3955c498874588201d9130
359 Author: Franck Bui <fbui@suse.com>
360 Date: Thu Mar 15 06:23:46 2018 +0100
362 basic/macros: rename noreturn into _noreturn_ (#8456)
364 "noreturn" is reserved and can be used in other header files we include:
366 [ 16s] In file included from /usr/include/gcrypt.h:30:0,
367 [ 16s] from ../src/journal/journal-file.h:26,
368 [ 16s] from ../src/journal/journal-vacuum.c:31:
369 [ 16s] /usr/include/gpg-error.h:1544:46: error: expected ‘,’ or ‘;’ before ‘)’ token
370 [ 16s] void gpgrt_log_bug (const char *fmt, ...) GPGRT_ATTR_NR_PRINTF(1,2);
372 Here we include grcrypt.h (which in turns include gpg-error.h) *after* we
373 "noreturn" was defined in macro.h.
375 diff --git a/src/basic/log.c b/src/basic/log.c
376 index 7a7f2cbec..16a2431c5 100644
377 --- a/src/basic/log.c
378 +++ b/src/basic/log.c
379 @@ -814,7 +814,7 @@ static void log_assert(
380 log_dispatch_internal(level, 0, file, line, func, NULL, NULL, NULL, NULL, buffer);
383 -noreturn void log_assert_failed_realm(
384 +_noreturn_ void log_assert_failed_realm(
388 @@ -826,7 +826,7 @@ noreturn void log_assert_failed_realm(
392 -noreturn void log_assert_failed_unreachable_realm(
393 +_noreturn_ void log_assert_failed_unreachable_realm(
397 diff --git a/src/basic/log.h b/src/basic/log.h
398 index efcf0f1bf..314be128a 100644
399 --- a/src/basic/log.h
400 +++ b/src/basic/log.h
401 @@ -186,7 +186,7 @@ int log_dump_internal(
404 /* Logging for various assertions */
405 -noreturn void log_assert_failed_realm(
406 +_noreturn_ void log_assert_failed_realm(
410 @@ -195,7 +195,7 @@ noreturn void log_assert_failed_realm(
411 #define log_assert_failed(text, ...) \
412 log_assert_failed_realm(LOG_REALM, (text), __VA_ARGS__)
414 -noreturn void log_assert_failed_unreachable_realm(
415 +_noreturn_ void log_assert_failed_unreachable_realm(
419 diff --git a/src/basic/macro.h b/src/basic/macro.h
420 index 95be63a20..8911edfc4 100644
421 --- a/src/basic/macro.h
422 +++ b/src/basic/macro.h
425 #define _fallthrough_
427 +/* Define C11 noreturn without <stdnoreturn.h> and even on older gcc
428 + * compiler versions */
430 +#if __STDC_VERSION__ >= 201112L
431 +#define _noreturn_ _Noreturn
433 +#define _noreturn_ __attribute__((noreturn))
437 /* Temporarily disable some warnings */
438 #define DISABLE_WARNING_DECLARATION_AFTER_STATEMENT \
439 @@ -414,16 +423,6 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
443 -/* Define C11 noreturn without <stdnoreturn.h> and even on older gcc
444 - * compiler versions */
446 -#if __STDC_VERSION__ >= 201112L
447 -#define noreturn _Noreturn
449 -#define noreturn __attribute__((noreturn))
453 #define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \
454 static inline void func##p(type *p) { \
456 diff --git a/src/basic/process-util.c b/src/basic/process-util.c
457 index aa9846db5..e6120af5b 100644
458 --- a/src/basic/process-util.c
459 +++ b/src/basic/process-util.c
460 @@ -987,7 +987,7 @@ bool is_main_thread(void) {
464 -noreturn void freeze(void) {
465 +_noreturn_ void freeze(void) {
469 diff --git a/src/basic/process-util.h b/src/basic/process-util.h
470 index 93029e36e..5170adec7 100644
471 --- a/src/basic/process-util.h
472 +++ b/src/basic/process-util.h
473 @@ -91,7 +91,7 @@ int pid_from_same_root_fs(pid_t pid);
475 bool is_main_thread(void);
477 -noreturn void freeze(void);
478 +_noreturn_ void freeze(void);
480 bool oom_score_adjust_is_valid(int oa);
482 diff --git a/src/core/main.c b/src/core/main.c
483 index 076846a41..4b2d14923 100644
484 --- a/src/core/main.c
485 +++ b/src/core/main.c
486 @@ -141,7 +141,7 @@ static uint64_t arg_default_tasks_max = UINT64_MAX;
487 static sd_id128_t arg_machine_id = {};
488 static EmergencyAction arg_cad_burst_action = EMERGENCY_ACTION_REBOOT_FORCE;
490 -noreturn static void freeze_or_reboot(void) {
491 +_noreturn_ static void freeze_or_reboot(void) {
493 if (arg_crash_reboot) {
494 log_notice("Rebooting in 10s...");
495 @@ -156,7 +156,7 @@ noreturn static void freeze_or_reboot(void) {
499 -noreturn static void crash(int sig) {
500 +_noreturn_ static void crash(int sig) {
504 diff --git a/src/journal/test-journal-interleaving.c b/src/journal/test-journal-interleaving.c
505 index 5a88b2774..d87bdbdd3 100644
506 --- a/src/journal/test-journal-interleaving.c
507 +++ b/src/journal/test-journal-interleaving.c
510 static bool arg_keep = false;
512 -noreturn static void log_assert_errno(const char *text, int error, const char *file, int line, const char *func) {
513 +_noreturn_ static void log_assert_errno(const char *text, int error, const char *file, int line, const char *func) {
514 log_internal(LOG_CRIT, error, file, line, func,
515 "'%s' failed at %s:%u (%s): %m", text, file, line, func);
517 diff --git a/src/shared/pager.c b/src/shared/pager.c
518 index 75db3c985..681af9c40 100644
519 --- a/src/shared/pager.c
520 +++ b/src/shared/pager.c
521 @@ -47,7 +47,7 @@ static int stored_stderr = -1;
522 static bool stdout_redirected = false;
523 static bool stderr_redirected = false;
525 -noreturn static void pager_fallback(void) {
526 +_noreturn_ static void pager_fallback(void) {
529 r = copy_bytes(STDIN_FILENO, STDOUT_FILENO, (uint64_t) -1, 0);
530 diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c
531 index 2821640e9..c8fa47b3d 100644
532 --- a/src/udev/collect/collect.c
533 +++ b/src/udev/collect/collect.c
534 @@ -58,7 +58,7 @@ static inline struct _mate *node_to_mate(struct udev_list_node *node)
535 return container_of(node, struct _mate, node);
538 -noreturn static void sig_alrm(int signo)
539 +_noreturn_ static void sig_alrm(int signo)
543 From eb50b6d936c474f5bc2974c059f6432222af4de4 Mon Sep 17 00:00:00 2001
544 From: Karel Zak <kzak@redhat.com>
545 Date: Thu, 22 Mar 2018 12:50:45 +0100
546 Subject: [PATCH] Fix linux/fs.h and sys/mount.h collisions
548 * (kernel-headers) linux/fs.h and (glibc) sys/mount.h contains MS_* constants
549 and because it's without #ifdefs you cannot include the both files together
552 * (systemd) src/basic/missing.h contains another copy of MS_* constants
554 The patch removes local systemd MS_* fallbacks, cleanup fs.h and
557 Signed-off-by: Karel Zak <kzak@redhat.com>
559 src/basic/missing.h | 40 ----------------------------------------
560 src/core/load-fragment.c | 1 -
561 src/shared/bus-unit-util.c | 2 ++
562 3 files changed, 2 insertions(+), 41 deletions(-)
564 diff --git a/src/basic/missing.h b/src/basic/missing.h
565 index 567aea8da9c..6802dd27c7b 100644
566 --- a/src/basic/missing.h
567 +++ b/src/basic/missing.h
568 @@ -524,46 +524,6 @@ struct btrfs_ioctl_quota_ctl_args {
569 #define OCFS2_SUPER_MAGIC 0x7461636f
573 -#define MS_MOVE 8192
577 -#define MS_REC 16384
581 -#define MS_PRIVATE (1<<18)
585 -#define MS_REC (1<<19)
589 -#define MS_SHARED (1<<20)
593 -#define MS_RELATIME (1<<21)
596 -#ifndef MS_KERNMOUNT
597 -#define MS_KERNMOUNT (1<<22)
600 -#ifndef MS_I_VERSION
601 -#define MS_I_VERSION (1<<23)
604 -#ifndef MS_STRICTATIME
605 -#define MS_STRICTATIME (1<<24)
609 -#define MS_LAZYTIME (1<<25)
613 #define SCM_SECURITY 0x03
615 diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
616 index 94605ab0d02..49f8a8c6da1 100644
617 --- a/src/core/load-fragment.c
618 +++ b/src/core/load-fragment.c
623 -#include <linux/fs.h>
624 #include <linux/oom.h>
627 diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
628 index 23e05daf48c..6e7ea10e714 100644
629 --- a/src/shared/bus-unit-util.c
630 +++ b/src/shared/bus-unit-util.c
635 +#include <sys/mount.h>
637 int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u) {