diff options
| author | Khem Raj <raj.khem@gmail.com> | 2016-01-20 05:03:08 +0000 |
|---|---|---|
| committer | Martin Jansa <Martin.Jansa@gmail.com> | 2016-02-01 15:51:19 +0100 |
| commit | 9cf9d864d57d2b431ad9c0a78c72e335451abe5b (patch) | |
| tree | 33dfdc8bb311ab655bb8440d11304d29e6831d72 | |
| parent | a6b22d2d575c2de3bc9f5743523a8e1d9ed3ea05 (diff) | |
| download | meta-openembedded-9cf9d864d57d2b431ad9c0a78c72e335451abe5b.tar.gz | |
lvm2: Portable fixes for fixing compile with musl
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
5 files changed, 247 insertions, 1 deletions
diff --git a/meta-oe/recipes-support/lvm2/lvm2.inc b/meta-oe/recipes-support/lvm2/lvm2.inc index c4d1b19d94..a891950d5a 100644 --- a/meta-oe/recipes-support/lvm2/lvm2.inc +++ b/meta-oe/recipes-support/lvm2/lvm2.inc | |||
| @@ -8,7 +8,11 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=94d55d512a9ba36caa9b7df079bae19f \ | |||
| 8 | S = "${WORKDIR}/LVM2.${PV}" | 8 | S = "${WORKDIR}/LVM2.${PV}" |
| 9 | SRC_URI = "ftp://sources.redhat.com/pub/lvm2/old/LVM2.${PV}.tgz \ | 9 | SRC_URI = "ftp://sources.redhat.com/pub/lvm2/old/LVM2.${PV}.tgz \ |
| 10 | file://lvm.conf \ | 10 | file://lvm.conf \ |
| 11 | " | 11 | file://0001-implement-libc-specific-_reopen_stream.patch \ |
| 12 | file://0002-use-PTHREAD_MUTEX_RECURSIVE-instead-of-PTHREAD_MUTEX.patch \ | ||
| 13 | file://0003-Guard-use-of-mallinfo-with-__GLIBC__.patch \ | ||
| 14 | file://0004-include-fcntl.h-for-O_-defines-and-fcntl-signature.patch \ | ||
| 15 | " | ||
| 12 | 16 | ||
| 13 | PACKAGECONFIG ??= "readline" | 17 | PACKAGECONFIG ??= "readline" |
| 14 | PACKAGECONFIG[readline] = "--enable-readline,--disable-readline,readline" | 18 | PACKAGECONFIG[readline] = "--enable-readline,--disable-readline,readline" |
diff --git a/meta-oe/recipes-support/lvm2/lvm2/0001-implement-libc-specific-_reopen_stream.patch b/meta-oe/recipes-support/lvm2/lvm2/0001-implement-libc-specific-_reopen_stream.patch new file mode 100644 index 0000000000..f0b4e71da7 --- /dev/null +++ b/meta-oe/recipes-support/lvm2/lvm2/0001-implement-libc-specific-_reopen_stream.patch | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | From 089c9c701a1b68b721f479dfc0c58c35b9dd4175 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Khem Raj <raj.khem@gmail.com> | ||
| 3 | Date: Wed, 20 Jan 2016 04:39:53 +0000 | ||
| 4 | Subject: [PATCH 1/4] implement libc specific _reopen_stream | ||
| 5 | |||
| 6 | musl defines stdin/stdio/stderr as constant types which means | ||
| 7 | we can not assign to them as we are doing here but works ok with glibc | ||
| 8 | therefore abstract out the _reopen_stream definition depending upon if | ||
| 9 | we are using glibc or otherwise | ||
| 10 | |||
| 11 | Origin: | ||
| 12 | http://git.alpinelinux.org/cgit/aports/tree/main/lvm2/fix-stdio-usage.patch | ||
| 13 | |||
| 14 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
| 15 | --- | ||
| 16 | Upstream-Status: Pending | ||
| 17 | |||
| 18 | lib/commands/toolcontext.c | 22 +++++++++++----------- | ||
| 19 | tools/lvmcmdline.c | 6 +++--- | ||
| 20 | 2 files changed, 14 insertions(+), 14 deletions(-) | ||
| 21 | |||
| 22 | diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c | ||
| 23 | index a2f21b8..7f796e4 100644 | ||
| 24 | --- a/lib/commands/toolcontext.c | ||
| 25 | +++ b/lib/commands/toolcontext.c | ||
| 26 | @@ -1637,7 +1637,10 @@ static void _init_globals(struct cmd_context *cmd) | ||
| 27 | /* | ||
| 28 | * Close and reopen stream on file descriptor fd. | ||
| 29 | */ | ||
| 30 | -static int _reopen_stream(FILE *stream, int fd, const char *mode, const char *name, FILE **new_stream) | ||
| 31 | +#ifdef __GLIBC__ | ||
| 32 | +#define _reopen_stream(stream, fd, mode, name) __reopen_stream(stream, fd, mode, name, &stream) | ||
| 33 | + | ||
| 34 | +static int __reopen_stream(FILE *stream, int fd, const char *mode, const char *name, FILE **new_stream) | ||
| 35 | { | ||
| 36 | int fd_copy, new_fd; | ||
| 37 | |||
| 38 | @@ -1664,6 +1667,9 @@ static int _reopen_stream(FILE *stream, int fd, const char *mode, const char *na | ||
| 39 | |||
| 40 | return 1; | ||
| 41 | } | ||
| 42 | +#else | ||
| 43 | +#define _reopen_stream(stream, fd, mode, name) (freopen(NULL, mode, stream) != NULL) | ||
| 44 | +#endif | ||
| 45 | |||
| 46 | static int _init_lvmetad(struct cmd_context *cmd) | ||
| 47 | { | ||
| 48 | @@ -1741,7 +1747,6 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived, | ||
| 49 | unsigned set_filters) | ||
| 50 | { | ||
| 51 | struct cmd_context *cmd; | ||
| 52 | - FILE *new_stream; | ||
| 53 | int flags; | ||
| 54 | |||
| 55 | #ifdef M_MMAP_MAX | ||
| 56 | @@ -1791,9 +1796,8 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived, | ||
| 57 | if (is_valid_fd(STDIN_FILENO) && | ||
| 58 | ((flags = fcntl(STDIN_FILENO, F_GETFL)) > 0) && | ||
| 59 | (flags & O_ACCMODE) != O_WRONLY) { | ||
| 60 | - if (!_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream)) | ||
| 61 | + if (!_reopen_stream(stdin, STDIN_FILENO, "r", "stdin")) | ||
| 62 | goto_out; | ||
| 63 | - stdin = new_stream; | ||
| 64 | if (setvbuf(stdin, cmd->linebuffer, _IOLBF, linebuffer_size)) { | ||
| 65 | log_sys_error("setvbuf", ""); | ||
| 66 | goto out; | ||
| 67 | @@ -1803,9 +1807,8 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived, | ||
| 68 | if (is_valid_fd(STDOUT_FILENO) && | ||
| 69 | ((flags = fcntl(STDOUT_FILENO, F_GETFL)) > 0) && | ||
| 70 | (flags & O_ACCMODE) != O_RDONLY) { | ||
| 71 | - if (!_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream)) | ||
| 72 | + if (!_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout")) | ||
| 73 | goto_out; | ||
| 74 | - stdout = new_stream; | ||
| 75 | if (setvbuf(stdout, cmd->linebuffer + linebuffer_size, | ||
| 76 | _IOLBF, linebuffer_size)) { | ||
| 77 | log_sys_error("setvbuf", ""); | ||
| 78 | @@ -2131,7 +2134,6 @@ int refresh_toolcontext(struct cmd_context *cmd) | ||
| 79 | void destroy_toolcontext(struct cmd_context *cmd) | ||
| 80 | { | ||
| 81 | struct dm_config_tree *cft_cmdline; | ||
| 82 | - FILE *new_stream; | ||
| 83 | int flags; | ||
| 84 | |||
| 85 | if (cmd->dump_filter && cmd->filter && cmd->filter->dump && | ||
| 86 | @@ -2167,8 +2169,7 @@ void destroy_toolcontext(struct cmd_context *cmd) | ||
| 87 | if (is_valid_fd(STDIN_FILENO) && | ||
| 88 | ((flags = fcntl(STDIN_FILENO, F_GETFL)) > 0) && | ||
| 89 | (flags & O_ACCMODE) != O_WRONLY) { | ||
| 90 | - if (_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream)) { | ||
| 91 | - stdin = new_stream; | ||
| 92 | + if (_reopen_stream(stdin, STDIN_FILENO, "r", "stdin")) { | ||
| 93 | setlinebuf(stdin); | ||
| 94 | } else | ||
| 95 | cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */ | ||
| 96 | @@ -2177,8 +2178,7 @@ void destroy_toolcontext(struct cmd_context *cmd) | ||
| 97 | if (is_valid_fd(STDOUT_FILENO) && | ||
| 98 | ((flags = fcntl(STDOUT_FILENO, F_GETFL)) > 0) && | ||
| 99 | (flags & O_ACCMODE) != O_RDONLY) { | ||
| 100 | - if (_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream)) { | ||
| 101 | - stdout = new_stream; | ||
| 102 | + if (_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout")) { | ||
| 103 | setlinebuf(stdout); | ||
| 104 | } else | ||
| 105 | cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */ | ||
| 106 | diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c | ||
| 107 | index 6577977..a33258a 100644 | ||
| 108 | --- a/tools/lvmcmdline.c | ||
| 109 | +++ b/tools/lvmcmdline.c | ||
| 110 | @@ -1744,7 +1744,7 @@ static int _check_standard_fds(void) | ||
| 111 | int err = is_valid_fd(STDERR_FILENO); | ||
| 112 | |||
| 113 | if (!is_valid_fd(STDIN_FILENO) && | ||
| 114 | - !(stdin = fopen(_PATH_DEVNULL, "r"))) { | ||
| 115 | + !freopen(_PATH_DEVNULL, "r", stdin)) { | ||
| 116 | if (err) | ||
| 117 | perror("stdin stream open"); | ||
| 118 | else | ||
| 119 | @@ -1754,7 +1754,7 @@ static int _check_standard_fds(void) | ||
| 120 | } | ||
| 121 | |||
| 122 | if (!is_valid_fd(STDOUT_FILENO) && | ||
| 123 | - !(stdout = fopen(_PATH_DEVNULL, "w"))) { | ||
| 124 | + !freopen(_PATH_DEVNULL, "w", stdout)) { | ||
| 125 | if (err) | ||
| 126 | perror("stdout stream open"); | ||
| 127 | /* else no stdout */ | ||
| 128 | @@ -1762,7 +1762,7 @@ static int _check_standard_fds(void) | ||
| 129 | } | ||
| 130 | |||
| 131 | if (!is_valid_fd(STDERR_FILENO) && | ||
| 132 | - !(stderr = fopen(_PATH_DEVNULL, "w"))) { | ||
| 133 | + !freopen(_PATH_DEVNULL, "w", stderr)) { | ||
| 134 | printf("stderr stream open: %s\n", | ||
| 135 | strerror(errno)); | ||
| 136 | return 0; | ||
| 137 | -- | ||
| 138 | 2.7.0 | ||
| 139 | |||
diff --git a/meta-oe/recipes-support/lvm2/lvm2/0002-use-PTHREAD_MUTEX_RECURSIVE-instead-of-PTHREAD_MUTEX.patch b/meta-oe/recipes-support/lvm2/lvm2/0002-use-PTHREAD_MUTEX_RECURSIVE-instead-of-PTHREAD_MUTEX.patch new file mode 100644 index 0000000000..969a15287e --- /dev/null +++ b/meta-oe/recipes-support/lvm2/lvm2/0002-use-PTHREAD_MUTEX_RECURSIVE-instead-of-PTHREAD_MUTEX.patch | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | From c8a1b669cbff3eee367fd4db3389e337bc4c98ba Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Khem Raj <raj.khem@gmail.com> | ||
| 3 | Date: Wed, 20 Jan 2016 04:46:26 +0000 | ||
| 4 | Subject: [PATCH 2/4] use PTHREAD_MUTEX_RECURSIVE instead of | ||
| 5 | PTHREAD_MUTEX_RECURSIVE_NP | ||
| 6 | |||
| 7 | PTHREAD_MUTEX_RECURSIVE_NP was used for compatibility with old glibc. | ||
| 8 | Although due to the_GNU_SOURCES define the portable, | ||
| 9 | PTHREAD_MUTEX_RECURSIVE will be available for Linuxes since at least | ||
| 10 | 1998. Simplify things giving us compatibility with musl which | ||
| 11 | apparently does not provide the non-portable define. | ||
| 12 | |||
| 13 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
| 14 | --- | ||
| 15 | Upstream-Status: Pending | ||
| 16 | |||
| 17 | daemons/lvmetad/lvmetad-core.c | 4 ++-- | ||
| 18 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
| 19 | |||
| 20 | diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c | ||
| 21 | index 7af9bde..63707c2 100644 | ||
| 22 | --- a/daemons/lvmetad/lvmetad-core.c | ||
| 23 | +++ b/daemons/lvmetad/lvmetad-core.c | ||
| 24 | @@ -300,7 +300,7 @@ static struct dm_config_tree *lock_vg(lvmetad_state *s, const char *id) { | ||
| 25 | if (!(vg = dm_hash_lookup(s->lock.vg, id))) { | ||
| 26 | if (!(vg = malloc(sizeof(pthread_mutex_t))) || | ||
| 27 | pthread_mutexattr_init(&rec) || | ||
| 28 | - pthread_mutexattr_settype(&rec, PTHREAD_MUTEX_RECURSIVE_NP) || | ||
| 29 | + pthread_mutexattr_settype(&rec, PTHREAD_MUTEX_RECURSIVE) || | ||
| 30 | pthread_mutex_init(vg, &rec)) | ||
| 31 | goto bad; | ||
| 32 | if (!dm_hash_insert(s->lock.vg, id, vg)) { | ||
| 33 | @@ -2890,7 +2890,7 @@ static int init(daemon_state *s) | ||
| 34 | ls->log = s->log; | ||
| 35 | |||
| 36 | pthread_mutexattr_init(&rec); | ||
| 37 | - pthread_mutexattr_settype(&rec, PTHREAD_MUTEX_RECURSIVE_NP); | ||
| 38 | + pthread_mutexattr_settype(&rec, PTHREAD_MUTEX_RECURSIVE); | ||
| 39 | pthread_mutex_init(&ls->lock.pvid_to_pvmeta, &rec); | ||
| 40 | pthread_mutex_init(&ls->lock.vgid_to_metadata, &rec); | ||
| 41 | pthread_mutex_init(&ls->lock.pvid_to_vgid, NULL); | ||
| 42 | -- | ||
| 43 | 2.7.0 | ||
| 44 | |||
diff --git a/meta-oe/recipes-support/lvm2/lvm2/0003-Guard-use-of-mallinfo-with-__GLIBC__.patch b/meta-oe/recipes-support/lvm2/lvm2/0003-Guard-use-of-mallinfo-with-__GLIBC__.patch new file mode 100644 index 0000000000..3d71767292 --- /dev/null +++ b/meta-oe/recipes-support/lvm2/lvm2/0003-Guard-use-of-mallinfo-with-__GLIBC__.patch | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | From e018d055603389b22cbc3bd68b1525f3048ebee7 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Khem Raj <raj.khem@gmail.com> | ||
| 3 | Date: Wed, 20 Jan 2016 04:50:26 +0000 | ||
| 4 | Subject: [PATCH 3/4] Guard use of mallinfo() with __GLIBC__ | ||
| 5 | |||
| 6 | This API is glibc-only | ||
| 7 | |||
| 8 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
| 9 | --- | ||
| 10 | Upstream-Status: Pending | ||
| 11 | |||
| 12 | lib/mm/memlock.c | 2 +- | ||
| 13 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
| 14 | |||
| 15 | diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c | ||
| 16 | index 969f1d7..405a7c0 100644 | ||
| 17 | --- a/lib/mm/memlock.c | ||
| 18 | +++ b/lib/mm/memlock.c | ||
| 19 | @@ -145,7 +145,7 @@ static void _touch_memory(void *mem, size_t size) | ||
| 20 | |||
| 21 | static void _allocate_memory(void) | ||
| 22 | { | ||
| 23 | -#ifndef VALGRIND_POOL | ||
| 24 | +#if !defined(VALGRIND_POOL) && defined(__GLIBC__) | ||
| 25 | void *stack_mem; | ||
| 26 | struct rlimit limit; | ||
| 27 | int i, area = 0, missing = _size_malloc_tmp, max_areas = 32, hblks; | ||
| 28 | -- | ||
| 29 | 2.7.0 | ||
| 30 | |||
diff --git a/meta-oe/recipes-support/lvm2/lvm2/0004-include-fcntl.h-for-O_-defines-and-fcntl-signature.patch b/meta-oe/recipes-support/lvm2/lvm2/0004-include-fcntl.h-for-O_-defines-and-fcntl-signature.patch new file mode 100644 index 0000000000..2a3b843646 --- /dev/null +++ b/meta-oe/recipes-support/lvm2/lvm2/0004-include-fcntl.h-for-O_-defines-and-fcntl-signature.patch | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | From 9b793d5b4adc5d8b3684e7f66943e236eae7c2db Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Khem Raj <raj.khem@gmail.com> | ||
| 3 | Date: Wed, 20 Jan 2016 04:52:59 +0000 | ||
| 4 | Subject: [PATCH 4/4] include fcntl.h for O_* defines and fcntl() signature | ||
| 5 | |||
| 6 | On glibc _somehow_ this header gets pulled in indirectly | ||
| 7 | |||
| 8 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
| 9 | --- | ||
| 10 | Upstream-Status: Pending | ||
| 11 | |||
| 12 | libdaemon/server/daemon-server.c | 1 + | ||
| 13 | 1 file changed, 1 insertion(+) | ||
| 14 | |||
| 15 | diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c | ||
| 16 | index d9d60d1..433d100 100644 | ||
| 17 | --- a/libdaemon/server/daemon-server.c | ||
| 18 | +++ b/libdaemon/server/daemon-server.c | ||
| 19 | @@ -18,6 +18,7 @@ | ||
| 20 | #include "daemon-server.h" | ||
| 21 | #include "daemon-log.h" | ||
| 22 | |||
| 23 | +#include <fcntl.h> | ||
| 24 | #include <dlfcn.h> | ||
| 25 | #include <errno.h> | ||
| 26 | #include <pthread.h> | ||
| 27 | -- | ||
| 28 | 2.7.0 | ||
| 29 | |||
