Skip to content

Commit 2defcd9

Browse files
committed
Compatibility: modifications to be compatible with GCC 4.8.x and CMake 2.8.x
1 parent 0dab66a commit 2defcd9

File tree

16 files changed

+160
-82
lines changed

16 files changed

+160
-82
lines changed

include/ipfixcol2/verbose.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,21 @@ enum ipx_verb_level {
146146
IPX_API void
147147
ipx_verb_ctx_print(enum ipx_verb_level level, const ipx_ctx_t *ctx, const char *fmt, ...);
148148

149-
150-
#ifndef __cplusplus
151149
/** Size of an error buffer message */
152150
#define IPX_STRERROR_SIZE 128
153151

152+
/**
153+
* \brief Convert standard error code to an error string (internal function)
154+
* \param[in] errnum Error code
155+
* \param[in] buffer Buffer for the error string
156+
* \param[in] buffer_size Size of the buffer
157+
* \return #IPX_OK on success and the \p buffer is properly filled
158+
* \return #IPX_ERR_ARG in case of invalid error code and the \p buffer is filled with an error
159+
* message
160+
*/
161+
IPX_API int
162+
ipx_strerror_fn(int errnum, char *buffer, size_t buffer_size);
163+
154164
/**
155165
* \def ipx_strerror
156166
* \brief Re-entrant strerror wrapper
@@ -166,17 +176,10 @@ ipx_verb_ctx_print(enum ipx_verb_level level, const ipx_ctx_t *ctx, const char *
166176
* \param[in] errnum An error code
167177
* \param[out] buffer Pointer to the local buffer
168178
*/
169-
#define ipx_strerror(errnum, buffer) \
170-
char ipx_strerror_buffer[IPX_STRERROR_SIZE]; \
171-
(buffer) = _Generic((&strerror_r), \
172-
char *(*)(int, char *, size_t): /* GNU-specific */ \
173-
strerror_r((errnum), ipx_strerror_buffer, IPX_STRERROR_SIZE), \
174-
int (*)(int, char *, size_t): /* XSI-compliant */ \
175-
(strerror_r((errnum), ipx_strerror_buffer, IPX_STRERROR_SIZE) >= 0 \
176-
? ipx_strerror_buffer \
177-
: "Unknown error (strerror_r failed!)") \
178-
)
179-
#endif
179+
#define ipx_strerror(errnum, buffer) \
180+
char ipx_strerror_buffer[IPX_STRERROR_SIZE]; \
181+
ipx_strerror_fn((errnum), ipx_strerror_buffer, IPX_STRERROR_SIZE); \
182+
(buffer) = ipx_strerror_buffer;
180183

181184
/**@}*/
182185
#ifdef __cplusplus

pkg/CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ set(CPACK_PACKAGE_VENDOR "CESNET z.s.p.o.")
1313
# Short package description
1414
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "IPFIX Collector Toolset")
1515
# Long package description
16-
set(CPACK_PACKAGE_DESCRIPTION "\
17-
IPFIXcol is a flexible IPFIX (RFC 7011) flow data collector designed to \
18-
be extensible by plugins.\
19-
")
16+
set(CPACK_PACKAGE_DESCRIPTION
17+
"IPFIXcol is a flexible IPFIX (RFC 7011) flow data collector designed to "
18+
"be extensible by plugins."
19+
)
2020

2121
# Create a top level directory in an archive with the same name as the archive
2222
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 1)
@@ -53,8 +53,6 @@ if (NOT CPACK_PACKAGE_CONTACT OR CPACK_PACKAGE_CONTACT STREQUAL "")
5353
"- using a name and email from the git configuration")
5454
string(CONCAT CPACK_PACKAGE_CONTACT
5555
${GIT_USER_NAME} " <" ${GIT_USER_EMAIL} ">")
56-
else()
57-
message(WARNING "Maintainer contact for packages is not specified.")
5856
endif()
5957
endif()
6058

pkg/deb/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ add_custom_target(deb_hierarchy
8585

8686
# DEB hierarchy requires already prepared TGZ archive
8787
add_dependencies(deb_hierarchy
88-
tgz_package
88+
tgz
8989
)
9090

9191
# New target that will pack all source codes into a source package and build DEB packages
92-
add_custom_target(deb_package
92+
add_custom_target(deb
9393
COMMENT "Generating source and DEB packages..."
9494
WORKING_DIRECTORY ${DEB_UNPACKED_DIR}
9595

@@ -98,12 +98,12 @@ add_custom_target(deb_package
9898
)
9999

100100
# The directory structure must be prepared before package building
101-
add_dependencies(deb_package
101+
add_dependencies(deb
102102
deb_hierarchy
103103
)
104104

105105
# Post build (show a message where DEB files are located)
106-
add_custom_command(TARGET deb_package POST_BUILD
106+
add_custom_command(TARGET deb POST_BUILD
107107
WORKING_DIRECTORY "${DEB_BUILD_DIR}"
108108
COMMENT "Source and DEB packages are located in ${DEB_BUILD_DIR}/"
109109
COMMAND ;

pkg/rpm/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ set(SRC_ARCHIVE
4040
)
4141

4242
# New target that will pack all source codes into a SRPM package and build RPM packages
43-
add_custom_target(rpm_package
43+
add_custom_target(rpm
4444
COMMENT "Generating SRPM and RPM packages..."
4545
WORKING_DIRECTORY "${RPM_BUILD_DIR}"
4646

@@ -52,12 +52,12 @@ add_custom_target(rpm_package
5252
)
5353

5454
# RPM target must call TGZ builder first
55-
add_dependencies(rpm_package
56-
tgz_package
55+
add_dependencies(rpm
56+
tgz
5757
)
5858

5959
# Post build (show a message where RPM files are located)
60-
add_custom_command(TARGET rpm_package POST_BUILD
60+
add_custom_command(TARGET rpm POST_BUILD
6161
WORKING_DIRECTORY "${RPM_BUILD_DIR}"
6262
COMMENT "SRPM and RPM packages are located in ${RPM_BUILD_DIR}/"
6363
COMMAND ;

pkg/tgz/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (PATH_CPACK)
1919
)
2020

2121
# New target that will pack all source codes into a TAR.GZ archive
22-
add_custom_target(tgz_package
22+
add_custom_target(tgz
2323
COMMENT "Generating tar.gz package..."
2424
COMMAND "${PATH_CPACK}" "--config" "${FILE_CFG_OUT}"
2525
)

src/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
cmake_policy(SET CMP0063 NEW)
1+
if (POLICY CMP0063)
2+
cmake_policy(SET CMP0063 NEW)
3+
endif()
24

35
# Configure a header file to pass some CMake variables
46
configure_file(
@@ -24,4 +26,4 @@ include_directories(
2426
# Project subdirectories
2527
add_subdirectory(core)
2628
add_subdirectory(plugins)
27-
add_subdirectory(tools)
29+
add_subdirectory(tools)

src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ set(CORE_SOURCE
3535
session.c
3636
verbose.c
3737
verbose.h
38+
utils.c
3839
utils.h
3940

4041
"${PROJECT_BINARY_DIR}/src/build_config.h"

src/core/fpipe.c

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

42-
#include <stdatomic.h>
4342
#include <stdint.h>
4443
#include <stdlib.h>
4544
#include <unistd.h>
@@ -61,8 +60,9 @@ struct ipx_fpipe {
6160
int fd_read;
6261
/** Pipe file descriptor for an IPFIX message parser */
6362
int fd_write;
63+
6464
/** Control variable that will be set when a request is ready */
65-
atomic_flag sync_flag;
65+
volatile unsigned int lock;
6666
/** Records in the pipe */
6767
volatile uint32_t cnt;
6868
};
@@ -84,7 +84,7 @@ ipx_fpipe_create()
8484

8585
ret->fd_write = pipefd[1];
8686
ret->fd_read = pipefd[0];
87-
atomic_flag_clear(&ret->sync_flag);
87+
ret->lock = 0; // unlocked by default
8888
ret->cnt = 0;
8989

9090
return ret;
@@ -136,23 +136,23 @@ ipx_fpipe_write(ipx_fpipe_t *fpipe, ipx_msg_t *msg)
136136
}
137137

138138
// Success - spin until the lock is acquired
139-
while (atomic_flag_test_and_set_explicit(&fpipe->sync_flag, memory_order_acquire));
139+
while (__sync_lock_test_and_set(&fpipe->lock, 1));
140140
fpipe->cnt++;
141-
atomic_flag_clear_explicit(&fpipe->sync_flag, memory_order_release);
141+
__sync_lock_release(&fpipe->lock);
142142
return;
143143
}
144144

145145
ipx_msg_t *
146146
ipx_fpipe_read(ipx_fpipe_t *fpipe)
147147
{
148148
// Spin until the lock is acquired
149-
while (atomic_flag_test_and_set_explicit(&fpipe->sync_flag, memory_order_acquire));
149+
while (__sync_lock_test_and_set(&fpipe->lock, 1));
150150
uint32_t cnt = fpipe->cnt;
151151
if (fpipe->cnt > 0) {
152152
fpipe->cnt--;
153153
}
154154
// Release the lock
155-
atomic_flag_clear_explicit(&fpipe->sync_flag, memory_order_release);
155+
__sync_lock_release(&fpipe->lock);
156156

157157
if (cnt == 0) {
158158
return NULL;

src/core/utils.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* \file src/core/utils.c
3+
* \author Lukas Hutak <[email protected]>
4+
* \brief Internal core utilities (source file)
5+
* \date 2018
6+
*/
7+
8+
/* Copyright (C) 2018 CESNET, z.s.p.o.
9+
*
10+
* Redistribution and use in source and binary forms, with or without
11+
* modification, are permitted provided that the following conditions
12+
* are met:
13+
* 1. Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
* 2. Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in
17+
* the documentation and/or other materials provided with the
18+
* distribution.
19+
* 3. Neither the name of the Company nor the names of its contributors
20+
* may be used to endorse or promote products derived from this
21+
* software without specific prior written permission.
22+
*
23+
* ALTERNATIVELY, provided that this notice is retained in full, this
24+
* product may be distributed under the terms of the GNU General Public
25+
* License (GPL) version 2 or later, in which case the provisions
26+
* of the GPL apply INSTEAD OF those given above.
27+
*
28+
* This software is provided ``as is'', and any express or implied
29+
* warranties, including, but not limited to, the implied warranties of
30+
* merchantability and fitness for a particular purpose are disclaimed.
31+
* In no event shall the company or contributors be liable for any
32+
* direct, indirect, incidental, special, exemplary, or consequential
33+
* damages (including, but not limited to, procurement of substitute
34+
* goods or services; loss of use, data, or profits; or business
35+
* interruption) however caused and on any theory of liability, whether
36+
* in contract, strict liability, or tort (including negligence or
37+
* otherwise) arising in any way out of the use of this software, even
38+
* if advised of the possibility of such damage.
39+
*
40+
*/
41+
42+
// Make sure that XSI-version is used
43+
#undef _GNU_SOURCE
44+
#define _POSIX_C_SOURCE 200809L
45+
46+
#include <string.h>
47+
#include <stdio.h>
48+
#include "utils.h"
49+
50+
int
51+
ipx_strerror_fn(int errnum, char *buffer, size_t buffer_size)
52+
{
53+
// Expecting XSI strerror_r version
54+
if (strerror_r(errnum, buffer, buffer_size) == 0) {
55+
return IPX_OK;
56+
}
57+
58+
snprintf(buffer, buffer_size, "strerror_r() failed: Unable process error code %d!", errnum);
59+
return IPX_ERR_ARG;
60+
}

src/core/utils.h

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,53 @@
1-
//
2-
// Created by lukashutak on 21/03/18.
3-
//
1+
/**
2+
* \file src/core/utils.h
3+
* \author Lukas Hutak <[email protected]>
4+
* \brief Internal core utilities (header file)
5+
* \date 2018
6+
*/
47

8+
/* Copyright (C) 2018 CESNET, z.s.p.o.
9+
*
10+
* Redistribution and use in source and binary forms, with or without
11+
* modification, are permitted provided that the following conditions
12+
* are met:
13+
* 1. Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
* 2. Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in
17+
* the documentation and/or other materials provided with the
18+
* distribution.
19+
* 3. Neither the name of the Company nor the names of its contributors
20+
* may be used to endorse or promote products derived from this
21+
* software without specific prior written permission.
22+
*
23+
* ALTERNATIVELY, provided that this notice is retained in full, this
24+
* product may be distributed under the terms of the GNU General Public
25+
* License (GPL) version 2 or later, in which case the provisions
26+
* of the GPL apply INSTEAD OF those given above.
27+
*
28+
* This software is provided ``as is'', and any express or implied
29+
* warranties, including, but not limited to, the implied warranties of
30+
* merchantability and fitness for a particular purpose are disclaimed.
31+
* In no event shall the company or contributors be liable for any
32+
* direct, indirect, incidental, special, exemplary, or consequential
33+
* damages (including, but not limited to, procurement of substitute
34+
* goods or services; loss of use, data, or profits; or business
35+
* interruption) however caused and on any theory of liability, whether
36+
* in contract, strict liability, or tort (including negligence or
37+
* otherwise) arising in any way out of the use of this software, even
38+
* if advised of the possibility of such damage.
39+
*
40+
*/
541
#ifndef IPFIXCOL_UTILS_H
642
#define IPFIXCOL_UTILS_H
743

44+
#ifdef __cplusplus
45+
extern "C" {
46+
#endif
847

9-
#include <string.h>
10-
11-
/** Size of an error buffer message */
12-
#define IPX_STRERROR_SIZE 128
13-
14-
/**
15-
* \def ipx_strerror
16-
* \brief Re-entrant strerror wrapper
17-
*
18-
* Main purpose is to solve issues with different strerror_r definitions.
19-
* \warning The function is defined as a macro that creates a local buffer for an error message.
20-
* Therefore, it cannot be called multiple times at the same scope.
21-
* \code{.c}
22-
* const char *err_str;
23-
* ipx_strerror(errno, err_str);
24-
* printf("ERROR: %s\n", err_str);
25-
* \endcode
26-
* \param[in] errnum An error code
27-
* \param[out] buffer Pointer to the local buffer
28-
*/
29-
#define ipx_strerror(errnum, buffer) \
30-
char ipx_strerror_buffer[IPX_STRERROR_SIZE]; \
31-
(buffer) = _Generic((&strerror_r), \
32-
char *(*)(int, char *, size_t): /* GNU-specific */ \
33-
strerror_r((errnum), ipx_strerror_buffer, IPX_STRERROR_SIZE), \
34-
int (*)(int, char *, size_t): /* XSI-compliant */ \
35-
(strerror_r((errnum), ipx_strerror_buffer, IPX_STRERROR_SIZE) >= 0 \
36-
? ipx_strerror_buffer \
37-
: "Unknown error (strerror_r failed!)") \
38-
)
48+
#include <ipfixcol2.h>
3949

40-
#endif //IPFIXCOL_UTILS_H
50+
#ifdef __cplusplus
51+
}
52+
#endif
53+
#endif // IPFIXCOL_UTILS_H

0 commit comments

Comments
 (0)