diff options
Diffstat (limited to 'meta/recipes-core/systemd/systemd/0002-add-fallback-parse_printf_format-implementation.patch')
-rw-r--r-- | meta/recipes-core/systemd/systemd/0002-add-fallback-parse_printf_format-implementation.patch | 434 |
1 files changed, 434 insertions, 0 deletions
diff --git a/meta/recipes-core/systemd/systemd/0002-add-fallback-parse_printf_format-implementation.patch b/meta/recipes-core/systemd/systemd/0002-add-fallback-parse_printf_format-implementation.patch new file mode 100644 index 0000000000..900a931632 --- /dev/null +++ b/meta/recipes-core/systemd/systemd/0002-add-fallback-parse_printf_format-implementation.patch | |||
@@ -0,0 +1,434 @@ | |||
1 | From 872b72739e62123867ce6c4f82aa37de24cc3f75 Mon Sep 17 00:00:00 2001 | ||
2 | From: Alexander Kanavin <alex.kanavin@gmail.com> | ||
3 | Date: Sat, 22 May 2021 20:26:24 +0200 | ||
4 | Subject: [PATCH 02/22] add fallback parse_printf_format implementation | ||
5 | |||
6 | Upstream-Status: Inappropriate [musl specific] | ||
7 | |||
8 | Signed-off-by: Emil Renner Berthing <systemd@esmil.dk> | ||
9 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
10 | Signed-off-by: Chen Qi <Qi.Chen@windriver.com> | ||
11 | [rebased for systemd 243] | ||
12 | Signed-off-by: Scott Murray <scott.murray@konsulko.com> | ||
13 | --- | ||
14 | meson.build | 1 + | ||
15 | src/basic/meson.build | 5 + | ||
16 | src/basic/parse-printf-format.c | 273 +++++++++++++++++++++++ | ||
17 | src/basic/parse-printf-format.h | 57 +++++ | ||
18 | src/basic/stdio-util.h | 2 +- | ||
19 | src/libsystemd/sd-journal/journal-send.c | 2 +- | ||
20 | 6 files changed, 338 insertions(+), 2 deletions(-) | ||
21 | create mode 100644 src/basic/parse-printf-format.c | ||
22 | create mode 100644 src/basic/parse-printf-format.h | ||
23 | |||
24 | diff --git a/meson.build b/meson.build | ||
25 | index 7419e2b0b0..01fd3ffc19 100644 | ||
26 | --- a/meson.build | ||
27 | +++ b/meson.build | ||
28 | @@ -725,6 +725,7 @@ endif | ||
29 | foreach header : ['crypt.h', | ||
30 | 'linux/memfd.h', | ||
31 | 'linux/vm_sockets.h', | ||
32 | + 'printf.h', | ||
33 | 'sys/auxv.h', | ||
34 | 'threads.h', | ||
35 | 'valgrind/memcheck.h', | ||
36 | diff --git a/src/basic/meson.build b/src/basic/meson.build | ||
37 | index d7450d8b44..c3e3daf4bd 100644 | ||
38 | --- a/src/basic/meson.build | ||
39 | +++ b/src/basic/meson.build | ||
40 | @@ -183,6 +183,11 @@ endforeach | ||
41 | |||
42 | basic_sources += generated_gperf_headers | ||
43 | |||
44 | +if conf.get('HAVE_PRINTF_H') != 1 | ||
45 | + basic_sources += [files('parse-printf-format.c')] | ||
46 | +endif | ||
47 | + | ||
48 | + | ||
49 | ############################################################ | ||
50 | |||
51 | arch_list = [ | ||
52 | diff --git a/src/basic/parse-printf-format.c b/src/basic/parse-printf-format.c | ||
53 | new file mode 100644 | ||
54 | index 0000000000..49437e5445 | ||
55 | --- /dev/null | ||
56 | +++ b/src/basic/parse-printf-format.c | ||
57 | @@ -0,0 +1,273 @@ | ||
58 | +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ | ||
59 | + | ||
60 | +/*** | ||
61 | + This file is part of systemd. | ||
62 | + | ||
63 | + Copyright 2014 Emil Renner Berthing <systemd@esmil.dk> | ||
64 | + | ||
65 | + With parts from the musl C library | ||
66 | + Copyright 2005-2014 Rich Felker, et al. | ||
67 | + | ||
68 | + systemd is free software; you can redistribute it and/or modify it | ||
69 | + under the terms of the GNU Lesser General Public License as published by | ||
70 | + the Free Software Foundation; either version 2.1 of the License, or | ||
71 | + (at your option) any later version. | ||
72 | + | ||
73 | + systemd is distributed in the hope that it will be useful, but | ||
74 | + WITHOUT ANY WARRANTY; without even the implied warranty of | ||
75 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
76 | + Lesser General Public License for more details. | ||
77 | + | ||
78 | + You should have received a copy of the GNU Lesser General Public License | ||
79 | + along with systemd; If not, see <http://www.gnu.org/licenses/>. | ||
80 | +***/ | ||
81 | + | ||
82 | +#include <stddef.h> | ||
83 | +#include <string.h> | ||
84 | + | ||
85 | +#include "parse-printf-format.h" | ||
86 | + | ||
87 | +static const char *consume_nonarg(const char *fmt) | ||
88 | +{ | ||
89 | + do { | ||
90 | + if (*fmt == '\0') | ||
91 | + return fmt; | ||
92 | + } while (*fmt++ != '%'); | ||
93 | + return fmt; | ||
94 | +} | ||
95 | + | ||
96 | +static const char *consume_num(const char *fmt) | ||
97 | +{ | ||
98 | + for (;*fmt >= '0' && *fmt <= '9'; fmt++) | ||
99 | + /* do nothing */; | ||
100 | + return fmt; | ||
101 | +} | ||
102 | + | ||
103 | +static const char *consume_argn(const char *fmt, size_t *arg) | ||
104 | +{ | ||
105 | + const char *p = fmt; | ||
106 | + size_t val = 0; | ||
107 | + | ||
108 | + if (*p < '1' || *p > '9') | ||
109 | + return fmt; | ||
110 | + do { | ||
111 | + val = 10*val + (*p++ - '0'); | ||
112 | + } while (*p >= '0' && *p <= '9'); | ||
113 | + | ||
114 | + if (*p != '$') | ||
115 | + return fmt; | ||
116 | + *arg = val; | ||
117 | + return p+1; | ||
118 | +} | ||
119 | + | ||
120 | +static const char *consume_flags(const char *fmt) | ||
121 | +{ | ||
122 | + while (1) { | ||
123 | + switch (*fmt) { | ||
124 | + case '#': | ||
125 | + case '0': | ||
126 | + case '-': | ||
127 | + case ' ': | ||
128 | + case '+': | ||
129 | + case '\'': | ||
130 | + case 'I': | ||
131 | + fmt++; | ||
132 | + continue; | ||
133 | + } | ||
134 | + return fmt; | ||
135 | + } | ||
136 | +} | ||
137 | + | ||
138 | +enum state { | ||
139 | + BARE, | ||
140 | + LPRE, | ||
141 | + LLPRE, | ||
142 | + HPRE, | ||
143 | + HHPRE, | ||
144 | + BIGLPRE, | ||
145 | + ZTPRE, | ||
146 | + JPRE, | ||
147 | + STOP | ||
148 | +}; | ||
149 | + | ||
150 | +enum type { | ||
151 | + NONE, | ||
152 | + PTR, | ||
153 | + INT, | ||
154 | + UINT, | ||
155 | + ULLONG, | ||
156 | + LONG, | ||
157 | + ULONG, | ||
158 | + SHORT, | ||
159 | + USHORT, | ||
160 | + CHAR, | ||
161 | + UCHAR, | ||
162 | + LLONG, | ||
163 | + SIZET, | ||
164 | + IMAX, | ||
165 | + UMAX, | ||
166 | + PDIFF, | ||
167 | + UIPTR, | ||
168 | + DBL, | ||
169 | + LDBL, | ||
170 | + MAXTYPE | ||
171 | +}; | ||
172 | + | ||
173 | +static const short pa_types[MAXTYPE] = { | ||
174 | + [NONE] = PA_INT, | ||
175 | + [PTR] = PA_POINTER, | ||
176 | + [INT] = PA_INT, | ||
177 | + [UINT] = PA_INT, | ||
178 | + [ULLONG] = PA_INT | PA_FLAG_LONG_LONG, | ||
179 | + [LONG] = PA_INT | PA_FLAG_LONG, | ||
180 | + [ULONG] = PA_INT | PA_FLAG_LONG, | ||
181 | + [SHORT] = PA_INT | PA_FLAG_SHORT, | ||
182 | + [USHORT] = PA_INT | PA_FLAG_SHORT, | ||
183 | + [CHAR] = PA_CHAR, | ||
184 | + [UCHAR] = PA_CHAR, | ||
185 | + [LLONG] = PA_INT | PA_FLAG_LONG_LONG, | ||
186 | + [SIZET] = PA_INT | PA_FLAG_LONG, | ||
187 | + [IMAX] = PA_INT | PA_FLAG_LONG_LONG, | ||
188 | + [UMAX] = PA_INT | PA_FLAG_LONG_LONG, | ||
189 | + [PDIFF] = PA_INT | PA_FLAG_LONG_LONG, | ||
190 | + [UIPTR] = PA_INT | PA_FLAG_LONG, | ||
191 | + [DBL] = PA_DOUBLE, | ||
192 | + [LDBL] = PA_DOUBLE | PA_FLAG_LONG_DOUBLE | ||
193 | +}; | ||
194 | + | ||
195 | +#define S(x) [(x)-'A'] | ||
196 | +#define E(x) (STOP + (x)) | ||
197 | + | ||
198 | +static const unsigned char states[]['z'-'A'+1] = { | ||
199 | + { /* 0: bare types */ | ||
200 | + S('d') = E(INT), S('i') = E(INT), | ||
201 | + S('o') = E(UINT),S('u') = E(UINT),S('x') = E(UINT), S('X') = E(UINT), | ||
202 | + S('e') = E(DBL), S('f') = E(DBL), S('g') = E(DBL), S('a') = E(DBL), | ||
203 | + S('E') = E(DBL), S('F') = E(DBL), S('G') = E(DBL), S('A') = E(DBL), | ||
204 | + S('c') = E(CHAR),S('C') = E(INT), | ||
205 | + S('s') = E(PTR), S('S') = E(PTR), S('p') = E(UIPTR),S('n') = E(PTR), | ||
206 | + S('m') = E(NONE), | ||
207 | + S('l') = LPRE, S('h') = HPRE, S('L') = BIGLPRE, | ||
208 | + S('z') = ZTPRE, S('j') = JPRE, S('t') = ZTPRE | ||
209 | + }, { /* 1: l-prefixed */ | ||
210 | + S('d') = E(LONG), S('i') = E(LONG), | ||
211 | + S('o') = E(ULONG),S('u') = E(ULONG),S('x') = E(ULONG),S('X') = E(ULONG), | ||
212 | + S('e') = E(DBL), S('f') = E(DBL), S('g') = E(DBL), S('a') = E(DBL), | ||
213 | + S('E') = E(DBL), S('F') = E(DBL), S('G') = E(DBL), S('A') = E(DBL), | ||
214 | + S('c') = E(INT), S('s') = E(PTR), S('n') = E(PTR), | ||
215 | + S('l') = LLPRE | ||
216 | + }, { /* 2: ll-prefixed */ | ||
217 | + S('d') = E(LLONG), S('i') = E(LLONG), | ||
218 | + S('o') = E(ULLONG),S('u') = E(ULLONG), | ||
219 | + S('x') = E(ULLONG),S('X') = E(ULLONG), | ||
220 | + S('n') = E(PTR) | ||
221 | + }, { /* 3: h-prefixed */ | ||
222 | + S('d') = E(SHORT), S('i') = E(SHORT), | ||
223 | + S('o') = E(USHORT),S('u') = E(USHORT), | ||
224 | + S('x') = E(USHORT),S('X') = E(USHORT), | ||
225 | + S('n') = E(PTR), | ||
226 | + S('h') = HHPRE | ||
227 | + }, { /* 4: hh-prefixed */ | ||
228 | + S('d') = E(CHAR), S('i') = E(CHAR), | ||
229 | + S('o') = E(UCHAR),S('u') = E(UCHAR), | ||
230 | + S('x') = E(UCHAR),S('X') = E(UCHAR), | ||
231 | + S('n') = E(PTR) | ||
232 | + }, { /* 5: L-prefixed */ | ||
233 | + S('e') = E(LDBL),S('f') = E(LDBL),S('g') = E(LDBL), S('a') = E(LDBL), | ||
234 | + S('E') = E(LDBL),S('F') = E(LDBL),S('G') = E(LDBL), S('A') = E(LDBL), | ||
235 | + S('n') = E(PTR) | ||
236 | + }, { /* 6: z- or t-prefixed (assumed to be same size) */ | ||
237 | + S('d') = E(PDIFF),S('i') = E(PDIFF), | ||
238 | + S('o') = E(SIZET),S('u') = E(SIZET), | ||
239 | + S('x') = E(SIZET),S('X') = E(SIZET), | ||
240 | + S('n') = E(PTR) | ||
241 | + }, { /* 7: j-prefixed */ | ||
242 | + S('d') = E(IMAX), S('i') = E(IMAX), | ||
243 | + S('o') = E(UMAX), S('u') = E(UMAX), | ||
244 | + S('x') = E(UMAX), S('X') = E(UMAX), | ||
245 | + S('n') = E(PTR) | ||
246 | + } | ||
247 | +}; | ||
248 | + | ||
249 | +size_t parse_printf_format(const char *fmt, size_t n, int *types) | ||
250 | +{ | ||
251 | + size_t i = 0; | ||
252 | + size_t last = 0; | ||
253 | + | ||
254 | + memset(types, 0, n); | ||
255 | + | ||
256 | + while (1) { | ||
257 | + size_t arg; | ||
258 | + unsigned int state; | ||
259 | + | ||
260 | + fmt = consume_nonarg(fmt); | ||
261 | + if (*fmt == '\0') | ||
262 | + break; | ||
263 | + if (*fmt == '%') { | ||
264 | + fmt++; | ||
265 | + continue; | ||
266 | + } | ||
267 | + arg = 0; | ||
268 | + fmt = consume_argn(fmt, &arg); | ||
269 | + /* flags */ | ||
270 | + fmt = consume_flags(fmt); | ||
271 | + /* width */ | ||
272 | + if (*fmt == '*') { | ||
273 | + size_t warg = 0; | ||
274 | + fmt = consume_argn(fmt+1, &warg); | ||
275 | + if (warg == 0) | ||
276 | + warg = ++i; | ||
277 | + if (warg > last) | ||
278 | + last = warg; | ||
279 | + if (warg <= n && types[warg-1] == NONE) | ||
280 | + types[warg-1] = INT; | ||
281 | + } else | ||
282 | + fmt = consume_num(fmt); | ||
283 | + /* precision */ | ||
284 | + if (*fmt == '.') { | ||
285 | + fmt++; | ||
286 | + if (*fmt == '*') { | ||
287 | + size_t parg = 0; | ||
288 | + fmt = consume_argn(fmt+1, &parg); | ||
289 | + if (parg == 0) | ||
290 | + parg = ++i; | ||
291 | + if (parg > last) | ||
292 | + last = parg; | ||
293 | + if (parg <= n && types[parg-1] == NONE) | ||
294 | + types[parg-1] = INT; | ||
295 | + } else { | ||
296 | + if (*fmt == '-') | ||
297 | + fmt++; | ||
298 | + fmt = consume_num(fmt); | ||
299 | + } | ||
300 | + } | ||
301 | + /* length modifier and conversion specifier */ | ||
302 | + state = BARE; | ||
303 | + do { | ||
304 | + unsigned char c = *fmt++; | ||
305 | + | ||
306 | + if (c < 'A' || c > 'z') | ||
307 | + continue; | ||
308 | + state = states[state]S(c); | ||
309 | + if (state == 0) | ||
310 | + continue; | ||
311 | + } while (state < STOP); | ||
312 | + | ||
313 | + if (state == E(NONE)) | ||
314 | + continue; | ||
315 | + | ||
316 | + if (arg == 0) | ||
317 | + arg = ++i; | ||
318 | + if (arg > last) | ||
319 | + last = arg; | ||
320 | + if (arg <= n) | ||
321 | + types[arg-1] = state - STOP; | ||
322 | + } | ||
323 | + | ||
324 | + if (last > n) | ||
325 | + last = n; | ||
326 | + for (i = 0; i < last; i++) | ||
327 | + types[i] = pa_types[types[i]]; | ||
328 | + | ||
329 | + return last; | ||
330 | +} | ||
331 | diff --git a/src/basic/parse-printf-format.h b/src/basic/parse-printf-format.h | ||
332 | new file mode 100644 | ||
333 | index 0000000000..47be7522d7 | ||
334 | --- /dev/null | ||
335 | +++ b/src/basic/parse-printf-format.h | ||
336 | @@ -0,0 +1,57 @@ | ||
337 | +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ | ||
338 | + | ||
339 | +/*** | ||
340 | + This file is part of systemd. | ||
341 | + | ||
342 | + Copyright 2014 Emil Renner Berthing <systemd@esmil.dk> | ||
343 | + | ||
344 | + With parts from the GNU C Library | ||
345 | + Copyright 1991-2014 Free Software Foundation, Inc. | ||
346 | + | ||
347 | + systemd is free software; you can redistribute it and/or modify it | ||
348 | + under the terms of the GNU Lesser General Public License as published by | ||
349 | + the Free Software Foundation; either version 2.1 of the License, or | ||
350 | + (at your option) any later version. | ||
351 | + | ||
352 | + systemd is distributed in the hope that it will be useful, but | ||
353 | + WITHOUT ANY WARRANTY; without even the implied warranty of | ||
354 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
355 | + Lesser General Public License for more details. | ||
356 | + | ||
357 | + You should have received a copy of the GNU Lesser General Public License | ||
358 | + along with systemd; If not, see <http://www.gnu.org/licenses/>. | ||
359 | +***/ | ||
360 | + | ||
361 | +#pragma once | ||
362 | + | ||
363 | +#include "config.h" | ||
364 | + | ||
365 | +#if HAVE_PRINTF_H | ||
366 | +#include <printf.h> | ||
367 | +#else | ||
368 | + | ||
369 | +#include <stddef.h> | ||
370 | + | ||
371 | +enum { /* C type: */ | ||
372 | + PA_INT, /* int */ | ||
373 | + PA_CHAR, /* int, cast to char */ | ||
374 | + PA_WCHAR, /* wide char */ | ||
375 | + PA_STRING, /* const char *, a '\0'-terminated string */ | ||
376 | + PA_WSTRING, /* const wchar_t *, wide character string */ | ||
377 | + PA_POINTER, /* void * */ | ||
378 | + PA_FLOAT, /* float */ | ||
379 | + PA_DOUBLE, /* double */ | ||
380 | + PA_LAST | ||
381 | +}; | ||
382 | + | ||
383 | +/* Flag bits that can be set in a type returned by `parse_printf_format'. */ | ||
384 | +#define PA_FLAG_MASK 0xff00 | ||
385 | +#define PA_FLAG_LONG_LONG (1 << 8) | ||
386 | +#define PA_FLAG_LONG_DOUBLE PA_FLAG_LONG_LONG | ||
387 | +#define PA_FLAG_LONG (1 << 9) | ||
388 | +#define PA_FLAG_SHORT (1 << 10) | ||
389 | +#define PA_FLAG_PTR (1 << 11) | ||
390 | + | ||
391 | +size_t parse_printf_format(const char *fmt, size_t n, int *types); | ||
392 | + | ||
393 | +#endif /* HAVE_PRINTF_H */ | ||
394 | diff --git a/src/basic/stdio-util.h b/src/basic/stdio-util.h | ||
395 | index 4e93ac90c9..f9deb6f662 100644 | ||
396 | --- a/src/basic/stdio-util.h | ||
397 | +++ b/src/basic/stdio-util.h | ||
398 | @@ -1,12 +1,12 @@ | ||
399 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ | ||
400 | #pragma once | ||
401 | |||
402 | -#include <printf.h> | ||
403 | #include <stdarg.h> | ||
404 | #include <stdio.h> | ||
405 | #include <sys/types.h> | ||
406 | |||
407 | #include "macro.h" | ||
408 | +#include "parse-printf-format.h" | ||
409 | |||
410 | _printf_(3, 4) | ||
411 | static inline char *snprintf_ok(char *buf, size_t len, const char *format, ...) { | ||
412 | diff --git a/src/libsystemd/sd-journal/journal-send.c b/src/libsystemd/sd-journal/journal-send.c | ||
413 | index be23b2fe75..69a2eb6404 100644 | ||
414 | --- a/src/libsystemd/sd-journal/journal-send.c | ||
415 | +++ b/src/libsystemd/sd-journal/journal-send.c | ||
416 | @@ -2,7 +2,6 @@ | ||
417 | |||
418 | #include <errno.h> | ||
419 | #include <fcntl.h> | ||
420 | -#include <printf.h> | ||
421 | #include <stddef.h> | ||
422 | #include <sys/un.h> | ||
423 | #include <unistd.h> | ||
424 | @@ -28,6 +27,7 @@ | ||
425 | #include "stdio-util.h" | ||
426 | #include "string-util.h" | ||
427 | #include "tmpfile-util.h" | ||
428 | +#include "parse-printf-format.h" | ||
429 | |||
430 | #define SNDBUF_SIZE (8*1024*1024) | ||
431 | |||
432 | -- | ||
433 | 2.34.1 | ||
434 | |||