|
39 | 39 | * |
40 | 40 | */ |
41 | 41 |
|
| 42 | +#define _GNU_SOURCE /* See feature_test_macros(7) */ |
| 43 | +#include <stdio.h> |
42 | 44 | #include <string.h> |
43 | 45 | #include <inttypes.h> |
44 | 46 | #include "unirecplugin.h" |
@@ -77,7 +79,7 @@ translate_bool(const struct fds_drec_field *field, struct conf_unirec *conf, |
77 | 79 |
|
78 | 80 |
|
79 | 81 | // Path to unirec elements config file |
80 | | -const char *UNIREC_ELEMENTS_FILE = "./unirec-elements.txt"; //TODO is this where it should be located |
| 82 | +const char *UNIREC_ELEMENTS_FILE = "unirec-elements.txt"; |
81 | 83 |
|
82 | 84 | /** |
83 | 85 | * \brief Creates IPFIX id from string |
@@ -113,12 +115,26 @@ unirecField_t *load_IPFIX2UR_mapping(ipx_ctx_t *ctx, uint32_t *urcount, uint32_t |
113 | 115 | uint32_t numurfields = 0; |
114 | 116 | uint32_t numipfixfields = 0; |
115 | 117 |
|
| 118 | + const char *sysconfdir = ipx_api_cfg_dir(); |
| 119 | + if (sysconfdir == NULL) { |
| 120 | + /* if the IPFIXcol2's path to config dir is not known, use current dir */ |
| 121 | + IPX_CTX_WARNING(ctx, "IPFIXcol2 did not supply path to config files, using \"./\" instead."); |
| 122 | + sysconfdir = "."; |
| 123 | + } |
| 124 | + char *path_conf = NULL; |
| 125 | + if (asprintf(&path_conf, "%s/%s", sysconfdir, UNIREC_ELEMENTS_FILE) == -1) { |
| 126 | + IPX_CTX_ERROR(ctx, "Could not allocate memory (%s:%d).", __FILE__, __LINE__); |
| 127 | + return NULL; |
| 128 | + } |
| 129 | + |
116 | 130 | /* Open the file */ |
117 | | - uef = fopen(UNIREC_ELEMENTS_FILE, "r"); |
| 131 | + uef = fopen(path_conf, "r"); |
118 | 132 | if (uef == NULL) { |
119 | | - IPX_CTX_ERROR(ctx, "Could not open file \"%s\" (%s:%d)", UNIREC_ELEMENTS_FILE, __FILE__, __LINE__); |
| 133 | + IPX_CTX_ERROR(ctx, "Could not open file \"%s\" (%s:%d)", path_conf, __FILE__, __LINE__); |
120 | 134 | return NULL; |
121 | 135 | } |
| 136 | + free(path_conf); |
| 137 | + path_conf = NULL; |
122 | 138 |
|
123 | 139 | /* Init buffer */ |
124 | 140 | line = malloc(lineSize); |
|
0 commit comments