ovni/src/common.h
Kevin Sala 7b4ebca002 Add OVNI_TRACEDIR envar to change trace directory
This commit introduces the OVNI_TRACEDIR environment variable to change
the directory where traces are generated. By default, when the envar is
not defined, the trace is still generated in the ovni directory. The
envar can take a trace directory name, a relative path to the directory,
or its absolute path. In the first case, the directory is created in the
current path $PWD.

Both libovni (rt) and ovnisync read this environment variable.
2023-10-23 07:49:28 +00:00

52 lines
1.2 KiB
C

/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: MIT */
#ifndef COMMON_H
#define COMMON_H
#include <stdio.h>
#include <sys/types.h>
extern int is_debug_enabled;
/* Path and file utilities */
int mkpath(const char *path, mode_t mode, int is_dir);
/* Debug macros */
void progname_set(char *name);
const char *progname_get(void);
void enable_debug(void);
void verr(const char *prefix, const char *func, const char *errstr, ...);
void vdie(const char *prefix, const char *func, const char *errstr, ...);
/* clang-format off */
#define rerr(...) fprintf(stderr, __VA_ARGS__)
#define err(...) verr("ERROR", __func__, __VA_ARGS__)
#define die(...) vdie("FATAL", __func__, __VA_ARGS__)
#define info(...) verr("INFO", NULL, __VA_ARGS__)
#define warn(...) verr("WARN", NULL, __VA_ARGS__)
#define dbg(...) do { \
if (unlikely(is_debug_enabled)) verr("DEBUG", __func__, __VA_ARGS__); \
} while (0);
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define UNUSED(x) (void)(x)
/* Poison assert */
#pragma GCC poison assert
#define USE_RET __attribute__((warn_unused_result))
#define ARRAYLEN(x) (sizeof(x)/sizeof((x)[0]))
/* clang-format on */
#endif /* COMMON_H */