summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/tests/test_utils.c6
-rw-r--r--lib/utils_base.c8
-rw-r--r--lib/utils_base.h1
3 files changed, 14 insertions, 1 deletions
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index 057c4845..763392a8 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -32,6 +32,7 @@ main (int argc, char **argv)
32 state_key *temp_state_key = NULL; 32 state_key *temp_state_key = NULL;
33 state_data *temp_state_data; 33 state_data *temp_state_data;
34 time_t current_time; 34 time_t current_time;
35 char *temp_filename;
35 36
36 plan_tests(81+23); 37 plan_tests(81+23);
37 38
@@ -259,10 +260,15 @@ main (int argc, char **argv)
259 temp_string = np_state_generate_key(argv); 260 temp_string = np_state_generate_key(argv);
260 ok(!strcmp(temp_string, "Ahash"), "Got hash" ); 261 ok(!strcmp(temp_string, "Ahash"), "Got hash" );
261 262
263 temp_string = _np_state_calculate_location_prefix();
264 ok(!strcmp(temp_string, NP_SHAREDSTATE_DIR), "Got default directory" );
265
262 ok(temp_state_key==NULL, "temp_state_key initially empty"); 266 ok(temp_state_key==NULL, "temp_state_key initially empty");
263 temp_state_key = np_state_init("check_test", temp_string, 54); 267 temp_state_key = np_state_init("check_test", temp_string, 54);
264 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); 268 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
265 ok( !strcmp(temp_state_key->name, temp_string), "Got key name" ); 269 ok( !strcmp(temp_state_key->name, temp_string), "Got key name" );
270 printf("Filename=%s\n", temp_state_key->_filename);
271
266 ok( !strcmp(temp_state_key->_filename, "Tobedone"), "Got internal filename" ); 272 ok( !strcmp(temp_state_key->_filename, "Tobedone"), "Got internal filename" );
267 ok( temp_state_key->data_version==54, "Version set" ); 273 ok( temp_state_key->data_version==54, "Version set" );
268 274
diff --git a/lib/utils_base.c b/lib/utils_base.c
index fb442400..b717a99a 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -321,6 +321,10 @@ char *np_state_generate_key(char **argv) {
321 return "Ahash"; 321 return "Ahash";
322} 322}
323 323
324char* _np_state_calculate_location_prefix(){
325 return NP_SHAREDSTATE_DIR;
326}
327
324/* 328/*
325 * Initiatializer for state routines. 329 * Initiatializer for state routines.
326 * Sets variables. Generates filename. Returns np_state_key. die with 330 * Sets variables. Generates filename. Returns np_state_key. die with
@@ -328,6 +332,7 @@ char *np_state_generate_key(char **argv) {
328 */ 332 */
329state_key *np_state_init(char *plugin_name, char *keyname, int expected_data_version) { 333state_key *np_state_init(char *plugin_name, char *keyname, int expected_data_version) {
330 state_key *this_state = NULL; 334 state_key *this_state = NULL;
335 char *temp_filename = NULL;
331 336
332 this_state = (state_key *) malloc(sizeof(state_key)); 337 this_state = (state_key *) malloc(sizeof(state_key));
333 338
@@ -339,7 +344,8 @@ state_key *np_state_init(char *plugin_name, char *keyname, int expected_data_ver
339 this_state->data_version=expected_data_version; 344 this_state->data_version=expected_data_version;
340 345
341 /* Calculate filename */ 346 /* Calculate filename */
342 this_state->_filename="Tobedone"; 347 asprintf(&temp_filename, "%s/%s", _np_state_calculate_location_prefix(), plugin_name);
348 this_state->_filename=temp_filename;
343 349
344 return this_state; 350 return this_state;
345} 351}
diff --git a/lib/utils_base.h b/lib/utils_base.h
index bec6c66f..b6eb57e1 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -28,6 +28,7 @@ typedef struct thresholds_struct {
28 range *critical; 28 range *critical;
29 } thresholds; 29 } thresholds;
30 30
31#define NP_SHAREDSTATE_DIR "/tmp"
31#define STATE_FORMAT_VERSION "1" 32#define STATE_FORMAT_VERSION "1"
32 33
33typedef struct state_data_struct { 34typedef struct state_data_struct {