summaryrefslogtreecommitdiffstats
path: root/zebra/zebra_netns_notify.c
diff options
context:
space:
mode:
authorGeorgi Valkov <gvalkov@gmail.com>2024-06-04 12:35:54 +0200
committerGeorgi Valkov <gvalkov@gmail.com>2024-06-04 12:35:57 +0200
commitf7242fbf73b9142456bedad9dc59c80d46f3d004 (patch)
treea464bda88071e4dda16ba3b62c267b55a7498bce /zebra/zebra_netns_notify.c
parentMerge pull request #16142 from LabNConsulting/chopps/fix-conflict-workflow (diff)
downloadfrr-f7242fbf73b9142456bedad9dc59c80d46f3d004.tar.xz
frr-f7242fbf73b9142456bedad9dc59c80d46f3d004.zip
zebra: fix compilation with GCC14
Fixes: zebra/zebra_netns_notify.c: In function 'zebra_ns_ready_read': zebra/zebra_netns_notify.c:266:40: error: implicit declaration of function 'basename' [-Wimplicit-function-declaration] 266 | if (strmatch(VRF_DEFAULT_NAME, basename(netnspath))) { | ^~~~~~~~ Fixed by including libgen.h, then since basename may modify its parameter, allocate a copy on the stack, using strdupa, and pass the temporary string to basename. According to the man page for basename: With glibc, one gets the POSIX version of basename() when <libgen.h> is included, and the GNU version otherwise. The POSIX version of basename may modify the contents of path, so we should to pass a copy when calling this function. [1] https://man7.org/linux/man-pages/man3/basename.3.html Signed-off-by: Georgi Valkov <gvalkov@gmail.com>
Diffstat (limited to 'zebra/zebra_netns_notify.c')
-rw-r--r--zebra/zebra_netns_notify.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c
index 617a2225f..fb326b0dd 100644
--- a/zebra/zebra_netns_notify.c
+++ b/zebra/zebra_netns_notify.c
@@ -15,6 +15,7 @@
#include <sched.h>
#endif
#include <dirent.h>
+#include <libgen.h>
#include <sys/inotify.h>
#include <sys/stat.h>
@@ -234,6 +235,7 @@ static void zebra_ns_ready_read(struct event *t)
{
struct zebra_netns_info *zns_info = EVENT_ARG(t);
const char *netnspath;
+ const char *netnspath_basename;
int err, stop_retry = 0;
if (!zns_info)
@@ -261,23 +263,24 @@ static void zebra_ns_ready_read(struct event *t)
zebra_ns_continue_read(zns_info, stop_retry);
return;
}
+ netnspath_basename = basename(strdupa(netnspath));
/* check default name is not already set */
- if (strmatch(VRF_DEFAULT_NAME, basename(netnspath))) {
- zlog_warn("NS notify : NS %s is already default VRF.Cancel VRF Creation", basename(netnspath));
+ if (strmatch(VRF_DEFAULT_NAME, netnspath_basename)) {
+ zlog_warn("NS notify : NS %s is already default VRF.Cancel VRF Creation", netnspath_basename);
zebra_ns_continue_read(zns_info, 1);
return;
}
- if (zebra_ns_notify_is_default_netns(basename(netnspath))) {
+ if (zebra_ns_notify_is_default_netns(netnspath_basename)) {
zlog_warn(
"NS notify : NS %s is default VRF. Ignore VRF creation",
- basename(netnspath));
+ netnspath_basename);
zebra_ns_continue_read(zns_info, 1);
return;
}
/* success : close fd and create zns context */
- zebra_ns_notify_create_context_from_entry_name(basename(netnspath));
+ zebra_ns_notify_create_context_from_entry_name(netnspath_basename);
zebra_ns_continue_read(zns_info, 1);
}
@@ -396,7 +399,7 @@ void zebra_ns_notify_parse(void)
continue;
}
/* check default name is not already set */
- if (strmatch(VRF_DEFAULT_NAME, basename(dent->d_name))) {
+ if (strmatch(VRF_DEFAULT_NAME, basename(strdupa(dent->d_name)))) {
zlog_warn("NS notify : NS %s is already default VRF.Cancel VRF Creation", dent->d_name);
continue;
}