Skip to content

Commit 10833f2

Browse files
authored
Merge pull request #94 from CESNET/bsd-support
BSD support
2 parents dd0b57b + 8bf2adc commit 10833f2

File tree

30 files changed

+225
-28
lines changed

30 files changed

+225
-28
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# LIBEPOLLSHIM_FOUND - System has libepoll-shim
2+
# LIBEPOLLSHIM_INCLUDE_DIRS - The libepoll-shim include directories
3+
# LIBEPOLLSHIM_LIBRARIES - The libraries needed to use libepoll-shim
4+
# LIBEPOLLSHIM_DEFINITIONS - Compiler switches required for using libepoll-shim
5+
6+
# use pkg-config to get the directories and then use these values
7+
# in the find_path() and find_library() calls
8+
find_package(PkgConfig)
9+
if (PKG_CONFIG_FOUND)
10+
pkg_check_modules(PC_EPOLLSHIM QUIET epoll-shim)
11+
set(LIBEPOLLSHIM_DEFINITIONS ${PC_EPOLLSHIM_CFLAGS_OTHER})
12+
endif()
13+
14+
find_path(
15+
EPOLLSHIM_INCLUDE_DIR libepoll-shim/sys/epoll.h
16+
HINTS ${PC_EPOLLSHIM_INCLUDEDIR} ${PC_EPOLLSHIM_INCLUDE_DIRS}
17+
PATH_SUFFIXES include
18+
)
19+
find_library(
20+
EPOLLSHIM_LIBRARY NAMES epoll-shim libepoll-shim
21+
HINTS ${PC_EPOLLSHIM_LIBDIR} ${PC_EPOLLSHIM_LIBRARY_DIRS}
22+
PATH_SUFFIXES lib lib64
23+
)
24+
25+
if (PC_EPOLLSHIM_VERSION)
26+
# Version extracted from pkg-config
27+
set(EPOLLSHIM_VERSION_STRING ${PC_EPOLLSHIM_VERSION})
28+
endif()
29+
30+
# handle the QUIETLY and REQUIRED arguments and set LIBEPOLLSHIM_FOUND to TRUE
31+
# if all listed variables are TRUE
32+
include(FindPackageHandleStandardArgs)
33+
find_package_handle_standard_args(LibEpollShim
34+
REQUIRED_VARS EPOLLSHIM_LIBRARY EPOLLSHIM_INCLUDE_DIR
35+
VERSION_VAR EPOLLSHIM_VERSION_STRING
36+
)
37+
38+
set(LIBEPOLLSHIM_LIBRARIES ${EPOLLSHIM_LIBRARY})
39+
set(LIBEPOLLSHIM_INCLUDE_DIRS ${EPOLLSHIM_INCLUDE_DIR}/libepoll-shim)
40+
mark_as_advanced(EPOLLSHIM_INCLUDE_DIR EPOLLSHIM_LIBRARY)

src/core/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ target_link_libraries(ipfixcol2base
7979

8080
# Build IPFIXCOL2 exacutable with all symbols from the base library
8181
set(BASE_LIB -Wl,--whole-archive ipfixcol2base -Wl,--no-whole-archive)
82+
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_HOST_SYSTEM_NAME STREQUAL "OpenBSD")
83+
set(BASE_LIB ${BASE_LIB} -rdynamic)
84+
endif()
85+
8286
add_executable(ipfixcol2 main.cpp)
8387
target_link_libraries(ipfixcol2 ${BASE_LIB})
8488
set_target_properties(ipfixcol2 PROPERTIES # by default, hide all symbols

src/core/configurator/cpipe.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111

12+
#include <assert.h>
1213
#include <unistd.h>
1314
#include <fcntl.h>
1415
#include <errno.h>

src/core/context.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@
4545
#include <pthread.h>
4646
#include <errno.h>
4747
#include <signal.h>
48+
#if defined(__OpenBSD__) || defined(__FreeBSD__)
49+
#include <pthread_np.h>
50+
#else
4851
#include <sys/prctl.h>
52+
#endif
4953

5054
#include "context.h"
5155
#include "extension.h"
@@ -640,13 +644,17 @@ thread_set_name(const char *ident)
640644
strncpy(name, ident, size - 1);
641645
name[size - 1] = '\0';
642646

647+
#if defined(__OpenBSD__) || defined(__FreeBSD__)
648+
pthread_set_name_np(pthread_self(), name);
649+
#else
643650
int rc = prctl(PR_SET_NAME, name, 0, 0, 0);
644651
if (rc == -1) {
645652
const char *err_str;
646653
ipx_strerror(errno, err_str);
647654
IPX_WARNING(comp_str, "Failed to set the name of a thread. prctl() failed: %s",
648655
err_str);
649656
}
657+
#endif
650658
}
651659

652660
/**
@@ -656,6 +664,9 @@ thread_set_name(const char *ident)
656664
static inline void
657665
thread_get_name(char ident[16])
658666
{
667+
#if defined(__OpenBSD__) || defined(__FreeBSD__)
668+
pthread_get_name_np(pthread_self(), ident, 16);
669+
#else
659670
int rc = prctl(PR_GET_NAME, ident, 0, 0, 0);
660671
if (rc == -1) {
661672
const char *err_str;
@@ -664,6 +675,7 @@ thread_get_name(char ident[16])
664675
err_str);
665676
ident[0] = '\0';
666677
}
678+
#endif
667679
}
668680

669681
int

src/core/message_ipfix.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*
4040
*/
4141

42+
#include <assert.h>
4243
#include <ipfixcol2.h>
4344
#include <libfds.h>
4445
#include "message_base.h"
@@ -190,4 +191,4 @@ ipx_msg_ipfix_add_drec_ref(struct ipx_msg_ipfix **msg_ref)
190191
const size_t offset = msg->rec_info.cnt_valid * msg->rec_info.rec_size;
191192
msg->rec_info.cnt_valid++;
192193
return ((struct ipx_ipfix_record *) (((uint8_t *) msg->recs) + offset));
193-
}
194+
}

src/core/message_terminate.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*
4040
*/
4141

42+
#include <assert.h>
4243
#include <stddef.h>
4344
#include <stdlib.h>
4445
#include "message_terminate.h"
@@ -84,4 +85,4 @@ enum ipx_msg_terminate_type
8485
ipx_msg_terminate_get_type(const ipx_msg_terminate_t *msg)
8586
{
8687
return msg->type;
87-
}
88+
}

src/core/netflow2ipfix/netflow5.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* SPDX-License-Identifier: BSD-3-Clause
99
*/
1010

11+
#include <assert.h>
1112
#include <stdbool.h>
1213
#include <stdint.h>
1314
#include <endian.h>
@@ -552,4 +553,4 @@ void
552553
ipx_nf5_conv_verb(ipx_nf5_conv_t *conv, enum ipx_verb_level v_new)
553554
{
554555
conv->conf.vlevel = v_new;
555-
}
556+
}

src/core/netflow2ipfix/netflow9.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* SPDX-License-Identifier: BSD-3-Clause
99
*/
1010

11+
#include <assert.h>
1112
#include <stdint.h>
1213
#include <endian.h>
1314
#include <assert.h>
@@ -1274,4 +1275,4 @@ void
12741275
ipx_nf9_conv_verb(ipx_nf9_conv_t *conv, enum ipx_verb_level v_new)
12751276
{
12761277
conv->vlevel = v_new;
1277-
}
1278+
}

src/core/odid_range.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*
4040
*/
4141

42+
#include <assert.h>
4243
#include <stdint.h>
4344
#include <stddef.h>
4445
#include <stdlib.h>
@@ -433,4 +434,4 @@ ipx_orange_print(const ipx_orange_t *range)
433434
break;
434435
}
435436
}
436-
}
437+
}

src/core/session.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,36 @@
3939
*
4040
*/
4141

42-
// Get GNU specific basename() function
43-
#define _GNU_SOURCE
4442
#include <string.h>
4543

4644
#include <stdint.h>
4745
#include <ipfixcol2.h>
4846
#include <stdlib.h>
4947
#include <inttypes.h>
5048

49+
/**
50+
* \brief Return the name part of a file path, i.e. the part after the last /
51+
* \param path The file path
52+
* \return The name part of the path or NULL if path is NULL
53+
*/
54+
static const char *get_basename(const char *path)
55+
{
56+
if (path == NULL) {
57+
return NULL;
58+
}
59+
60+
const char *res = path;
61+
const char *p = path;
62+
while (*p != '\0') {
63+
if (*p == '/') {
64+
res = p + 1;
65+
}
66+
p++;
67+
}
68+
69+
return res;
70+
}
71+
5172
/**
5273
* \brief Create a source description string from a Network Session structure
5374
*
@@ -166,7 +187,9 @@ ipx_session_new_file(const char *file_path)
166187
return NULL;
167188
}
168189

169-
res->ident = basename(res->file.file_path); // GNU specific basename()
190+
res->ident = res->file.file_path;
191+
192+
res->ident = (char *) get_basename(res->file.file_path);
170193
if (!res->ident) {
171194
free(res);
172195
return NULL;
@@ -190,4 +213,4 @@ ipx_session_destroy(struct ipx_session *session)
190213
}
191214

192215
free(session);
193-
}
216+
}

0 commit comments

Comments
 (0)