blob: 051165e8b2228738d3bcffb19509be636592999d [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From 942ef655237b90909edf53eafd121842cdc07ce1 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Fri, 13 Jan 2023 12:44:07 -0700
4Subject: [PATCH] api: Use GNU strerror_r when available
5
6GNU strerror_r is only available in glibc, musl impelents the XSI
7version which is slightly different, therefore check if GNU version is
8available before using it, otherwise use the XSI compliant version.
9
10Signed-off-by: Khem Raj <raj.khem@gmail.com>
11Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
12Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
13TJH: Minor formatting change so that the line doesn't exceed 100 chars
14---
15 configure.ac | 5 +++++
16 src/api.c | 9 +++++++--
17 2 files changed, 12 insertions(+), 2 deletions(-)
18
19--- a/configure.ac
20+++ b/configure.ac
21@@ -186,6 +186,11 @@ AC_FUNC_REALLOC
22 AC_FUNC_STAT
23 AC_CHECK_FUNCS([getmntent hasmntopt memset mkdir rmdir strdup])
24
25+orig_CFLAGS="$CFLAGS"
26+CFLAGS="$CFLAGS -D_GNU_SOURCE"
27+AC_FUNC_STRERROR_R
28+CFLAGS="$orig_CFLAGS"
29+
30 AC_SEARCH_LIBS(
31 [fts_open],
32 [fts],
33--- a/src/api.c
34+++ b/src/api.c
35@@ -4598,9 +4598,14 @@ const char *cgroup_strerror(int code)
36 {
37 int idx = code % ECGROUPNOTCOMPILED;
38
39- if (code == ECGOTHER)
40+ if (code == ECGOTHER) {
41+#ifdef STRERROR_R_CHAR_P
42 return strerror_r(cgroup_get_last_errno(), errtext, MAXLEN);
43-
44+#else
45+ return strerror_r(cgroup_get_last_errno(), errtext, sizeof (errtext)) ?
46+ "unknown error" : errtext;
47+#endif
48+ }
49 if (idx >= sizeof(cgroup_strerror_codes)/sizeof(cgroup_strerror_codes[0]))
50 return "Invalid error code";
51