diff options
-rw-r--r-- | .github/workflows/build-archlinux.yml | 2 | ||||
-rw-r--r-- | .github/workflows/build-openwrt.yml | 1 | ||||
-rw-r--r-- | nDPId-test.c | 6 | ||||
-rw-r--r-- | nDPId.c | 9 | ||||
-rw-r--r-- | nio.h | 16 | ||||
-rw-r--r-- | utils.h | 13 |
6 files changed, 44 insertions, 3 deletions
diff --git a/.github/workflows/build-archlinux.yml b/.github/workflows/build-archlinux.yml index b0a12f79c..3a864a673 100644 --- a/.github/workflows/build-archlinux.yml +++ b/.github/workflows/build-archlinux.yml @@ -15,6 +15,8 @@ on: jobs: build: runs-on: ubuntu-latest + env: + CMAKE_C_FLAGS: -Werror steps: - uses: actions/checkout@v3 with: diff --git a/.github/workflows/build-openwrt.yml b/.github/workflows/build-openwrt.yml index 3984246a9..b97afdef3 100644 --- a/.github/workflows/build-openwrt.yml +++ b/.github/workflows/build-openwrt.yml @@ -57,6 +57,7 @@ jobs: FEED_DIR: ${{ github.workspace }}/packages/openwrt FEEDNAME: ndpid_openwrt_packages_ci PACKAGES: nDPId-testing + V: s - name: Store packages uses: actions/upload-artifact@v3 diff --git a/nDPId-test.c b/nDPId-test.c index 88338e3d2..0e72ddfe2 100644 --- a/nDPId-test.c +++ b/nDPId-test.c @@ -1557,7 +1557,11 @@ static int nio_selftest() char const wbuf[] = "AAAA"; size_t const wlen = strnlen(wbuf, sizeof(wbuf)); - write(pipefds[1], wbuf, wlen); + if (write(pipefds[1], wbuf, wlen) < 0) + { + logger(1, "Write '%s' (%zu bytes) to pipe failed with: %s", wbuf, wlen, strerror(errno)); + goto error; + } if (nio_run(&io, 1000) != NIO_SUCCESS) { @@ -89,6 +89,8 @@ name.var = value; \ pthread_mutex_init(&name.var_mutex, NULL); \ } while (0) + +WARN_UNUSED static inline uint64_t mt_pt_get_and_add(volatile uint64_t * value, uint64_t add, pthread_mutex_t * mutex) { uint64_t result; @@ -98,7 +100,10 @@ static inline uint64_t mt_pt_get_and_add(volatile uint64_t * value, uint64_t add pthread_mutex_unlock(mutex); return result; } + #define MT_GET_AND_ADD(name, value) mt_pt_get_and_add(&name.var, value, &name.var_mutex) + +WARN_UNUSED static inline uint64_t mt_pt_get_and_sub(volatile uint64_t * value, uint64_t sub, pthread_mutex_t * mutex) { uint64_t result; @@ -591,7 +596,7 @@ static char * const subopt_token[] = {[MAX_FLOWS_PER_THREAD] = "max-flows-per-th NULL}; static void sighandler(int signum); -static int processing_threads_error_or_eof(void); +static WARN_UNUSED int processing_threads_error_or_eof(void); static void free_workflow(struct nDPId_workflow ** const workflow); static void serialize_and_send(struct nDPId_reader_thread * const reader_thread); static void jsonize_flow_event(struct nDPId_reader_thread * const reader_thread, @@ -4622,7 +4627,7 @@ static void * processing_thread(void * const ndpi_thread_arg) return NULL; } -static int processing_threads_error_or_eof(void) +static WARN_UNUSED int processing_threads_error_or_eof(void) { for (unsigned long long int i = 0; i < nDPId_options.reader_thread_count; ++i) { @@ -3,6 +3,8 @@ #include <poll.h> +#define WARN_UNUSED __attribute__((__warn_unused_result__)) + enum { NIO_SUCCESS = 0, @@ -34,41 +36,55 @@ struct nio void nio_init(struct nio * io); +WARN_UNUSED int nio_use_poll(struct nio * io, nfds_t max_fds); +WARN_UNUSED int nio_use_epoll(struct nio * io, int max_events); +WARN_UNUSED int nio_add_fd(struct nio * io, int fd, int event_flags, void * ptr); +WARN_UNUSED int nio_mod_fd(struct nio * io, int fd, int event_flags, void * ptr); +WARN_UNUSED int nio_del_fd(struct nio * io, int fd); +WARN_UNUSED int nio_run(struct nio * io, int timeout); +WARN_UNUSED static inline int nio_get_nready(struct nio const * const io) { return io->nready; } +WARN_UNUSED int nio_check(struct nio * io, int index, int events); +WARN_UNUSED int nio_is_valid(struct nio const * const io, int index); +WARN_UNUSED int nio_get_fd(struct nio * io, int index); +WARN_UNUSED void * nio_get_ptr(struct nio * io, int index); +WARN_UNUSED static inline int nio_has_input(struct nio * io, int index) { return nio_check(io, index, NIO_EVENT_INPUT); } +WARN_UNUSED static inline int nio_can_output(struct nio * io, int index) { return nio_check(io, index, NIO_EVENT_OUTPUT); } +WARN_UNUSED static inline int nio_has_error(struct nio * io, int index) { return nio_check(io, index, NIO_EVENT_ERROR); @@ -3,6 +3,8 @@ #include <stdarg.h> +#define WARN_UNUSED __attribute__((__warn_unused_result__)) + #define CMDARG(_default_value) \ { \ .value = NULL, .default_value = (_default_value) \ @@ -16,20 +18,26 @@ struct cmdarg void set_cmdarg(struct cmdarg * const ca, char const * const val); +WARN_UNUSED char const * get_cmdarg(struct cmdarg const * const ca); +WARN_UNUSED int is_cmdarg_set(struct cmdarg const * const ca); +WARN_UNUSED int is_path_absolute(char const * const prefix, char const * const path); void daemonize_enable(void); +WARN_UNUSED int is_daemonize_enabled(void); +WARN_UNUSED int daemonize_with_pidfile(char const * const pidfile); int daemonize_shutdown(char const * const pidfile); +WARN_UNUSED int change_user_group(char const * const user, char const * const group, char const * const pidfile, @@ -42,12 +50,15 @@ void log_app_info(void); void shutdown_logging(void); +WARN_UNUSED int enable_file_logger(char const * const log_file); +WARN_UNUSED int get_log_file_fd(void); void enable_console_logger(void); +WARN_UNUSED int is_console_logger_enabled(void); void vlogger(int is_error, char const * const format, va_list ap); @@ -56,8 +67,10 @@ __attribute__((format(printf, 2, 3))) void logger(int is_error, char const * con __attribute__((format(printf, 2, 3))) void logger_early(int is_error, char const * const format, ...); +WARN_UNUSED int set_fd_cloexec(int fd); +WARN_UNUSED char const * get_nDPId_version(void); #endif |