Merge pull request #23908 from qosmio/ngtcp2-fix-release-number
[feed/packages.git] / utils / tini / patches / 002-Support-POSIX-basename-from-musl-libc.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sun, 14 Apr 2024 15:33:51 +0200
4 Subject: Support POSIX basename() from musl libc
5
6 Musl libc 1.2.5 removed the definition of the basename() function from
7 string.h and only provides it in libgen.h as the POSIX standard
8 defines it.
9
10 This change fixes compilation with musl libc 1.2.5.
11 ````
12 build_dir/target-mips_24kc_musl/tini-0.19.0/src/tini.c:227:36: error: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
13 227 | fprintf(file, "%s (%s)\n", basename(name), TINI_VERSION_STRING);
14 build_dir/target-mips_24kc_musl/tini-0.19.0/src/tini.c:227:25: error: format '%s' expects argument of type 'char *', but argument 3 has type 'int' [-Werror=format=]
15 227 | fprintf(file, "%s (%s)\n", basename(name), TINI_VERSION_STRING);
16 | ~^ ~~~~~~~~~~~~~~
17 | | |
18 | char * int
19 | %d
20
21 ````
22
23 basename() modifies the input string, copy it first with strdup(), If
24 strdup() returns NULL the code will handle it.
25
26 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
27 ---
28 src/tini.c | 15 +++++++++++----
29 1 file changed, 11 insertions(+), 4 deletions(-)
30
31 --- a/src/tini.c
32 +++ b/src/tini.c
33 @@ -14,6 +14,7 @@
34 #include <stdlib.h>
35 #include <unistd.h>
36 #include <stdbool.h>
37 +#include <libgen.h>
38
39 #include "tiniConfig.h"
40 #include "tiniLicense.h"
41 @@ -224,14 +225,19 @@ int spawn(const signal_configuration_t*
42 }
43
44 void print_usage(char* const name, FILE* const file) {
45 - fprintf(file, "%s (%s)\n", basename(name), TINI_VERSION_STRING);
46 + char *dirc, *bname;
47 +
48 + dirc = strdup(name);
49 + bname = basename(dirc);
50 +
51 + fprintf(file, "%s (%s)\n", bname, TINI_VERSION_STRING);
52
53 #if TINI_MINIMAL
54 - fprintf(file, "Usage: %s PROGRAM [ARGS] | --version\n\n", basename(name));
55 + fprintf(file, "Usage: %s PROGRAM [ARGS] | --version\n\n", bname);
56 #else
57 - fprintf(file, "Usage: %s [OPTIONS] PROGRAM -- [ARGS] | --version\n\n", basename(name));
58 + fprintf(file, "Usage: %s [OPTIONS] PROGRAM -- [ARGS] | --version\n\n", bname);
59 #endif
60 - fprintf(file, "Execute a program under the supervision of a valid init process (%s)\n\n", basename(name));
61 + fprintf(file, "Execute a program under the supervision of a valid init process (%s)\n\n", bname);
62
63 fprintf(file, "Command line options:\n\n");
64
65 @@ -261,6 +267,7 @@ void print_usage(char* const name, FILE*
66 fprintf(file, " %s: Send signals to the child's process group.\n", KILL_PROCESS_GROUP_GROUP_ENV_VAR);
67
68 fprintf(file, "\n");
69 + free(dirc);
70 }
71
72 void print_license(FILE* const file) {