Skip to content

Commit

Permalink
[logging] report error in case logging buffer is bigger than PIPE_BUF
Browse files Browse the repository at this point in the history
See #148

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Aug 3, 2018
1 parent 2eaaeaf commit 722b281
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libknet/libknet.h
Expand Up @@ -14,6 +14,7 @@
#include <time.h>
#include <netinet/in.h>
#include <unistd.h>
#include <limits.h>

/**
* @file libknet.h
Expand Down Expand Up @@ -109,6 +110,9 @@ typedef struct knet_handle *knet_handle_t;
* Make sure to either read from this filedescriptor properly and/or
* mark it O_NONBLOCK, otherwise if the fd becomes full, libknet could
* block.
* It is strongly encouraged to use pipes (ex: pipe(2) or pipe2(2)) for
* logging fds due to the atomic nature of writes between fds.
* See also libknet test suite for reference and guidance.
*
* default_log_level -
* If logfd is specified, it will initialize all subsystems to log
Expand Down Expand Up @@ -1916,6 +1920,9 @@ uint8_t knet_log_get_loglevel_id(const char *name);
*/

#define KNET_MAX_LOG_MSG_SIZE 254
#if KNET_MAX_LOG_MSG_SIZE > PIPE_BUF
#error KNET_MAX_LOG_MSG_SIZE cannot be bigger than PIPE_BUF for guaranteed system atomic writes
#endif

struct knet_log_msg {
char msg[KNET_MAX_LOG_MSG_SIZE];
Expand Down

0 comments on commit 722b281

Please sign in to comment.