Merge pull request #390 from Stargirl-chan/master

Fix compilation on musl by implementing a custom basename

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg authored and GitHub committed 2023-12-29 14:57:10 +01:00
commit 9130af1c77
7 files changed
+25 -10

No files matched your search

+2 -3
View File
@@ -132,11 +132,10 @@ static FILE *maybe_fopen_alias(const char *file, const char *path)
{ {
const char *basename; const char *basename;
basename = rindex(path, '/'); basename = basenm(path);
if (!basename) if (!strcmp(basename, path))
return NULL; return NULL;
basename++;
if (strcmp(file, basename)) if (strcmp(file, basename))
return NULL; return NULL;
+1 -1
View File
@@ -1311,7 +1311,7 @@ int conf_reload(void)
if (strncmp(path, FINIT_SYSPATH_, strlen(FINIT_SYSPATH_)) && if (strncmp(path, FINIT_SYSPATH_, strlen(FINIT_SYSPATH_)) &&
strncmp(path, FINIT_RUNPATH_, strlen(FINIT_RUNPATH_))) strncmp(path, FINIT_RUNPATH_, strlen(FINIT_RUNPATH_)))
continue; continue;
if (strcmp(basename(path), basename(gl.gl_pathv[j]))) if (strcmp(basenm(path), basenm(gl.gl_pathv[j])))
continue; continue;
path = NULL; /* replacement later in list, skip this */ path = NULL; /* replacement later in list, skip this */
break; break;
+2 -1
View File
@@ -28,6 +28,7 @@
#include <string.h> #include <string.h>
#include "helpers.h" #include "helpers.h"
#include "util.h"
static glob_t *get_arrays(void) static glob_t *get_arrays(void)
@@ -58,7 +59,7 @@ void mdadm_wait(void)
for (i = 0; i < gl->gl_pathc; i++) { for (i = 0; i < gl->gl_pathc; i++) {
char *array; char *array;
array = basename(gl->gl_pathv[i]); array = basenm(gl->gl_pathv[i]);
snprintf(cmd, sizeof(cmd), "mdadm --wait-clean /dev/%s >/dev/null", array); snprintf(cmd, sizeof(cmd), "mdadm --wait-clean /dev/%s >/dev/null", array);
run_interactive(cmd, "Marking MD array %s as clean", array); run_interactive(cmd, "Marking MD array %s as clean", array);
} }
+5 -4
View File
@@ -43,6 +43,7 @@
#include "private.h" #include "private.h"
#include "service.h" #include "service.h"
#include "sig.h" #include "sig.h"
#include "util.h"
#define is_io_plugin(p) ((p)->io.cb && (p)->io.fd > 0) #define is_io_plugin(p) ((p)->io.cb && (p)->io.fd > 0)
#define SEARCH_PLUGIN(str) \ #define SEARCH_PLUGIN(str) \
@@ -88,7 +89,7 @@ int plugin_register(plugin_t *plugin)
Dl_info info; Dl_info info;
if (dladdr(plugin, &info) && info.dli_fname) if (dladdr(plugin, &info) && info.dli_fname)
plugin->name = basename(info.dli_fname); plugin->name = basenm(info.dli_fname);
#endif #endif
if (!plugin->name) if (!plugin->name)
plugin->name = "unknown"; plugin->name = "unknown";
@@ -253,7 +254,7 @@ void plugin_run_hook(hook_point_t no, void *arg)
PLUGIN_ITERATOR(p, tmp) { PLUGIN_ITERATOR(p, tmp) {
if (p->hook[no].cb) { if (p->hook[no].cb) {
dbg("Calling %s hook n:o %d (arg: %p) ...", basename(p->name), no, arg ?: "NIL"); dbg("Calling %s hook n:o %d (arg: %p) ...", basenm(p->name), no, arg ?: "NIL");
p->hook[no].cb(arg ? arg : p->hook[no].arg); p->hook[no].cb(arg ? arg : p->hook[no].arg);
} }
} }
@@ -301,9 +302,9 @@ int plugin_io_init(plugin_t *p)
if (!is_io_plugin(p)) if (!is_io_plugin(p))
return 0; return 0;
dbg("Initializing plugin %s for I/O", basename(p->name)); dbg("Initializing plugin %s for I/O", basenm(p->name));
if (uev_io_init(ctx, &p->watcher, generic_io_cb, p, p->io.fd, p->io.flags)) { if (uev_io_init(ctx, &p->watcher, generic_io_cb, p, p->io.fd, p->io.flags)) {
warn("Failed setting up I/O plugin %s", basename(p->name)); warn("Failed setting up I/O plugin %s", basenm(p->name));
return 1; return 1;
} }
+1 -1
View File
@@ -492,7 +492,7 @@ void tmpfilesd(void)
/* check for overrides */ /* check for overrides */
for (j = i + 1; j < gl.gl_pathc; j++) { for (j = i + 1; j < gl.gl_pathc; j++) {
if (strcmp(basename(fn), basename(gl.gl_pathv[j]))) if (strcmp(basenm(fn), basenm(gl.gl_pathv[j])))
continue; continue;
fn = NULL; fn = NULL;
break; break;
+13
View File
@@ -151,6 +151,19 @@ char *progname(char *arg0)
return prognm; return prognm;
} }
/* basename(3) replacement that does not modify its argument */
char *basenm(const char *path)
{
char *basename;
basename = rindex(path, '/');
if (!basename)
return (char *) path;
basename++;
return basename;
}
char *str(char *fmt, ...) char *str(char *fmt, ...)
{ {
static char buf[32]; static char buf[32];
+1
View File
@@ -55,6 +55,7 @@ extern char *prognm;
#endif #endif
char *progname (char *arg0); char *progname (char *arg0);
char *basenm (const char *path);
char *str (char *fmt, ...) __attribute__ ((format (printf, 1, 2))); char *str (char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
int fnread (char *buf, size_t len, char *fmt, ...) __attribute__ ((format (printf, 3, 4))); int fnread (char *buf, size_t len, char *fmt, ...) __attribute__ ((format (printf, 3, 4)));