Skip to content
Snippets Groups Projects
Commit 17957dde authored by Daniel Salzman's avatar Daniel Salzman
Browse files

xdp-gun: import popenve from contrib to remove libcap-ng dependency for all utilities

parent c1207aaf
No related branches found
No related tags found
1 merge request!1149Xdp gun popen fix
Pipeline #65802 passed
......@@ -73,8 +73,6 @@ src/contrib/openbsd/strlcat.c
src/contrib/openbsd/strlcat.h
src/contrib/openbsd/strlcpy.c
src/contrib/openbsd/strlcpy.h
src/contrib/popenve.c
src/contrib/popenve.h
src/contrib/qp-trie/trie.c
src/contrib/qp-trie/trie.h
src/contrib/semaphore.c
......@@ -471,6 +469,11 @@ src/utils/khost/khost_main.c
src/utils/khost/khost_params.c
src/utils/khost/khost_params.h
src/utils/kjournalprint/main.c
src/utils/knot-xdp-gun/load_queries.c
src/utils/knot-xdp-gun/load_queries.h
src/utils/knot-xdp-gun/main.c
src/utils/knot-xdp-gun/popenve.c
src/utils/knot-xdp-gun/popenve.h
src/utils/knotc/commands.c
src/utils/knotc/commands.h
src/utils/knotc/interactive.c
......@@ -488,9 +491,6 @@ src/utils/knsupdate/knsupdate_params.h
src/utils/kzonecheck/main.c
src/utils/kzonecheck/zone_check.c
src/utils/kzonecheck/zone_check.h
src/utils/knot-xdp-gun/load_queries.c
src/utils/knot-xdp-gun/load_queries.h
src/utils/knot-xdp-gun/main.c
tests-fuzz/fuzz_dname_from_str.c
tests-fuzz/fuzz_dname_to_str.c
tests-fuzz/fuzz_packet.c
......
noinst_LTLIBRARIES += libcontrib.la
libcontrib_la_CPPFLAGS = $(AM_CPPFLAGS) $(CFLAG_VISIBILITY)
libcontrib_la_LDFLAGS = $(AM_LDFLAGS) $(LDFLAG_EXCLUDE_LIBS) $(cap_ng_LIBS)
libcontrib_la_LDFLAGS = $(AM_LDFLAGS) $(LDFLAG_EXCLUDE_LIBS)
libcontrib_la_LIBADD = $(pthread_LIBS)
if USE_GNUTLS_MEMSET
libcontrib_la_CPPFLAGS += $(gnutls_CFLAGS)
......@@ -43,8 +43,6 @@ libcontrib_la_SOURCES = \
contrib/mempattern.h \
contrib/net.c \
contrib/net.h \
contrib/popenve.c \
contrib/popenve.h \
contrib/qp-trie/trie.c \
contrib/qp-trie/trie.h \
contrib/semaphore.c \
......
......@@ -88,10 +88,12 @@ sbin_PROGRAMS += knot-xdp-gun
knot_xdp_gun_SOURCES = \
utils/knot-xdp-gun/load_queries.c \
utils/knot-xdp-gun/load_queries.h \
utils/knot-xdp-gun/main.c
utils/knot-xdp-gun/main.c \
utils/knot-xdp-gun/popenve.c \
utils/knot-xdp-gun/popenve.h
knot_xdp_gun_CPPFLAGS = $(AM_CPPFLAGS)
knot_xdp_gun_LDADD = libcontrib.la libknot.la $(pthread_LIBS)
knot_xdp_gun_LDADD = libcontrib.la libknot.la $(pthread_LIBS) $(cap_ng_LIBS)
endif ENABLE_XDP
endif HAVE_UTILS
......
......@@ -37,10 +37,9 @@
#include "libknot/libknot.h"
#include "contrib/openbsd/strlcpy.h"
#include "contrib/popenve.h"
#include "utils/common/params.h"
#include "load_queries.h"
#include "utils/knot-xdp-gun/load_queries.h"
#include "utils/knot-xdp-gun/popenve.h"
#define PROGRAM_NAME "knot-xdp-gun"
......
......@@ -16,11 +16,10 @@
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "popenve.h"
#include "utils/knot-xdp-gun/popenve.h"
#ifdef ENABLE_CAP_NG
#include <cap-ng.h>
......@@ -39,26 +38,26 @@ static void drop_capabilities(void) { }
int kpopenvef(const char *binfile, char *const args[], char *const env[], bool drop_cap)
{
int pipefds[2];
if (pipe(pipefds) < 0) {
return -errno;
}
if (fcntl(pipefds[0], F_SETFD, FD_CLOEXEC) < 0) {
int fcntlerrno = errno;
close(pipefds[0]);
close(pipefds[1]);
return -fcntlerrno;
}
int pipefds[2];
if (pipe(pipefds) < 0) {
return -errno;
}
if (fcntl(pipefds[0], F_SETFD, FD_CLOEXEC) < 0) {
int fcntlerrno = errno;
close(pipefds[0]);
close(pipefds[1]);
return -fcntlerrno;
}
pid_t forkpid = fork();
if (forkpid < 0) {
int forkerrno = errno;
close(pipefds[0]);
close(pipefds[1]);
return -forkerrno;
}
pid_t forkpid = fork();
if (forkpid < 0) {
int forkerrno = errno;
close(pipefds[0]);
close(pipefds[1]);
return -forkerrno;
}
if (forkpid == 0) {
if (forkpid == 0) {
dup_stdout:
if (dup2(pipefds[1], STDOUT_FILENO) < 0) {
if (errno == EINTR) {
......@@ -69,19 +68,19 @@ dup_stdout:
close(pipefds[1]);
exit(EXIT_FAILURE);
}
close(pipefds[1]);
close(pipefds[1]);
if (drop_cap) {
drop_capabilities();
}
execve(binfile, args, env);
perror("execve");
exit(EXIT_FAILURE);
}
execve(binfile, args, env);
perror("execve");
exit(EXIT_FAILURE);
}
close(pipefds[1]);
return pipefds[0];
close(pipefds[1]);
return pipefds[0];
}
FILE *kpopenve(const char *binfile, char *const args[], char *const env[], bool drop_cap)
......
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment