Skip to content

Commit

Permalink
core/kmod: fix basename issue due to musl change
Browse files Browse the repository at this point in the history
[ commit e794d41d834c0d2b5a69c42f4ae5946156f26a01 ]

Upstream PR #32

musl has removed the non-prototype declaration of basename from
string.h [1] which now results in build errors with clang-17+
compiler.

kmod-project/kmod#32
  • Loading branch information
dermotbradley authored and akodanev committed Feb 22, 2024
1 parent c9256e6 commit e14a212
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/kmod/APKBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Compatible with module-init-tools
pkgname=kmod
pkgver=31
pkgrel=3
pkgrel=4
pkgdesc="Linux kernel module management tools"
url="http://git.kernel.org/?p=utils/kernel/kmod/kmod.git;a=summary"
arch="all"
Expand All @@ -23,6 +23,7 @@ subpackages="
source="https://kernel.org/pub/linux/utils/kernel/kmod/kmod-$pkgver.tar.xz
strndupa.patch
kmod-static-nodes.initd
portable-basename.patch
"

build() {
Expand Down Expand Up @@ -65,4 +66,5 @@ sha512sums="
05ca70381808bec5f262b94db625662c385408988178a35e4aaf4960ee0716dc0cbfc327160ea4b61098d0c2130ab1b5142ea8156bea8e06ded7f4d288b6d085 kmod-31.tar.xz
f2ea3527bfba182c5e15557c224a5bba8c7e2ea3d21cf604e6eb2277226dcf983c3aeb9ac44a322c7f2b4942b35135da999d63a5b946b829d3f3b09c050a0f17 strndupa.patch
d36af5bc51856c61da206758776796f5e8012fa54f0133a6deb0a2a79ae5740daca6b6b6ce44bf94bb174cd5b972229c40e5e682886e6b71c6c104206378b6eb kmod-static-nodes.initd
5fc41a7c4ea3ad3e33516ebdf8d19ac7ce0223d75a3e99f185e8a7fd71007b9d2e2d850e319b122d470cd95f45098a5a39faa21a17c0fb82124138f97db9d85c portable-basename.patch
"
106 changes: 106 additions & 0 deletions core/kmod/portable-basename.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
Upstream PR #32

musl has removed the non-prototype declaration of basename from
string.h [1] which now results in build errors with clang-17+
compiler.

https://github.com/kmod-project/kmod/pull/32

---

diff -aur a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
--- a/libkmod/libkmod-config.c
+++ b/libkmod/libkmod-config.c
@@ -794,7 +794,7 @@
bool is_single = false;

if (name == NULL) {
- name = basename(path);
+ name = gnu_basename(path);
is_single = true;
}

diff -aur a/shared/util.c b/shared/util.c
--- a/shared/util.c
+++ b/shared/util.c
@@ -172,9 +172,9 @@

char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len)
{
- char *modname;
+ const char *modname;

- modname = basename(path);
+ modname = gnu_basename(path);
if (modname == NULL || modname[0] == '\0')
return NULL;

diff -aur a/shared/util.h b/shared/util.h
--- a/shared/util.h
+++ b/shared/util.h
@@ -5,6 +5,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
@@ -76,6 +77,12 @@
__p->__v = (val); \
} while(0)

+static _always_inline_ const char *gnu_basename(const char *s)
+{
+ const char *p = strrchr(s, '/');
+ return p ? p+1 : s;
+}
+
static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u)
{
return 1 << ((sizeof(u) * 8) - __builtin_clz(u - 1));
diff -aur a/testsuite/testsuite.c b/testsuite/testsuite.c
--- a/testsuite/testsuite.c
+++ b/testsuite/testsuite.c
@@ -70,7 +70,7 @@

printf("Usage:\n"
"\t%s [options] <test>\n"
- "Options:\n", basename(progname));
+ "Options:\n", gnu_basename(progname));

for (itr = options, itr_short = options_short;
itr->name != NULL; itr++, itr_short++)
diff -aur a/tools/depmod.c b/tools/depmod.c
--- a/tools/depmod.c
+++ b/tools/depmod.c
@@ -761,7 +761,7 @@
if (name != NULL)
namelen = strlen(name);
else {
- name = basename(dir);
+ name = gnu_basename(dir);
namelen = strlen(name);
dirlen -= namelen + 1;
}
diff -aur a/tools/kmod.c b/tools/kmod.c
--- a/tools/kmod.c
+++ b/tools/kmod.c
@@ -68,7 +68,7 @@
"Options:\n"
"\t-V, --version show version\n"
"\t-h, --help show this help\n\n"
- "Commands:\n", basename(argv[0]));
+ "Commands:\n", gnu_basename(argv[0]));

for (i = 0; i < ARRAY_SIZE(kmod_cmds); i++) {
if (kmod_cmds[i]->help != NULL) {
@@ -156,7 +156,7 @@
const char *cmd;
size_t i;

- cmd = basename(argv[0]);
+ cmd = gnu_basename(argv[0]);

for (i = 0; i < ARRAY_SIZE(kmod_compat_cmds); i++) {
if (streq(kmod_compat_cmds[i]->name, cmd))

0 comments on commit e14a212

Please sign in to comment.