summaryrefslogtreecommitdiffstats
path: root/meta-filesystems/recipes-utils/xfsprogs/files/xfsprogs-4.12.0-fix_musl.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-filesystems/recipes-utils/xfsprogs/files/xfsprogs-4.12.0-fix_musl.patch')
-rw-r--r--meta-filesystems/recipes-utils/xfsprogs/files/xfsprogs-4.12.0-fix_musl.patch117
1 files changed, 117 insertions, 0 deletions
diff --git a/meta-filesystems/recipes-utils/xfsprogs/files/xfsprogs-4.12.0-fix_musl.patch b/meta-filesystems/recipes-utils/xfsprogs/files/xfsprogs-4.12.0-fix_musl.patch
new file mode 100644
index 000000000..efc57e4f6
--- /dev/null
+++ b/meta-filesystems/recipes-utils/xfsprogs/files/xfsprogs-4.12.0-fix_musl.patch
@@ -0,0 +1,117 @@
1From 21253610f9ef87db8e2a75b863b7fcfbd0cdb421 Mon Sep 17 00:00:00 2001
2From: "Darrick J. Wong" <darrick.wong@oracle.com>
3Date: Tue, 25 Jul 2017 13:45:01 -0500
4Subject: [PATCH] In patch 4944defad4 ("xfs_db: redirect printfs when
5 metadumping to stdout"), we solved the problem of xfs_db printfs ending up in
6 the metadump stream by reassigning stdout for the duration of a stdout
7 metadump. Unfortunately, musl doesn't allow stdout to be reassigned (in
8 their view "extern FILE *stdout" means "extern FILE * const stdout"), so we
9 abandon the old approach in favor of playing games with dup() to switch the
10 raw file descriptors.
11
12While we're at it, fix a regression where an unconverted outf test
13allows progress info to end up in the metadump stream.
14
15Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
16---
17 db/metadump.c | 47 ++++++++++++++++++++++++++++++++++++-----------
18 1 file changed, 36 insertions(+), 11 deletions(-)
19
20diff --git a/db/metadump.c b/db/metadump.c
21index 96641e0..4e2f648 100644
22--- a/db/metadump.c
23+++ b/db/metadump.c
24@@ -78,6 +78,7 @@ static int obfuscate = 1;
25 static int zero_stale_data = 1;
26 static int show_warnings = 0;
27 static int progress_since_warning = 0;
28+static bool stdout_metadump;
29
30 void
31 metadump_init(void)
32@@ -137,7 +138,7 @@ print_progress(const char *fmt, ...)
33 va_end(ap);
34 buf[sizeof(buf)-1] = '\0';
35
36- f = (outf == stdout) ? stderr : stdout;
37+ f = stdout_metadump ? stderr : stdout;
38 fprintf(f, "\r%-59s", buf);
39 fflush(f);
40 progress_since_warning = 1;
41@@ -2750,7 +2751,8 @@ metadump_f(
42 xfs_agnumber_t agno;
43 int c;
44 int start_iocur_sp;
45- bool stdout_metadump = false;
46+ int outfd = -1;
47+ int ret;
48 char *p;
49
50 exitcode = 1;
51@@ -2870,16 +2872,35 @@ metadump_f(
52 * metadump operation so that dbprintf and other messages
53 * are sent to the console instead of polluting the
54 * metadump stream.
55+ *
56+ * We get to do this the hard way because musl doesn't
57+ * allow reassignment of stdout.
58 */
59- outf = stdout;
60- stdout = stderr;
61+ fflush(stdout);
62+ outfd = dup(STDOUT_FILENO);
63+ if (outfd < 0) {
64+ perror("opening dump stream");
65+ goto out;
66+ }
67+ ret = dup2(STDERR_FILENO, STDOUT_FILENO);
68+ if (ret < 0) {
69+ perror("redirecting stdout");
70+ close(outfd);
71+ goto out;
72+ }
73+ outf = fdopen(outfd, "a");
74+ if (outf == NULL) {
75+ fprintf(stderr, "cannot create dump stream\n");
76+ dup2(outfd, 1);
77+ close(outfd);
78+ goto out;
79+ }
80 stdout_metadump = true;
81 } else {
82 outf = fopen(argv[optind], "wb");
83 if (outf == NULL) {
84 print_warning("cannot create dump file");
85- free(metablock);
86- return 0;
87+ goto out;
88 }
89 }
90
91@@ -2907,15 +2928,19 @@ metadump_f(
92 if (progress_since_warning)
93 fputc('\n', stdout_metadump ? stderr : stdout);
94
95- if (stdout_metadump)
96- stdout = outf;
97- else
98- fclose(outf);
99+ if (stdout_metadump) {
100+ fflush(outf);
101+ fflush(stdout);
102+ ret = dup2(outfd, STDOUT_FILENO);
103+ if (ret < 0)
104+ perror("un-redirecting stdout");
105+ }
106+ fclose(outf);
107
108 /* cleanup iocur stack */
109 while (iocur_sp > start_iocur_sp)
110 pop_cur();
111-
112+out:
113 free(metablock);
114
115 return 0;
116--
1172.13.3