19
19
#include "util_logging.h"
20
20
21
21
#define BILLION (1000000000L)
22
+ #define UUID_LEN 32 // 128 bits, 32 hex characters
22
23
23
24
typedef struct _nrh_status_codes_t {
24
25
const char * code ;
@@ -44,11 +45,16 @@ static nrh_status_codes_t health_statuses[NRH_MAX_STATUS] = {
44
45
45
46
static struct timespec start_time = {0 , 0 };
46
47
static nrhealth_t last_error_code = NRH_HEALTHY ;
47
- static char health_filename [] = "health- bc21b5891f5e44fc9272caef924611a8.yml " ;
48
+ static char health_uuid [] = "bc21b5891f5e44fc9272caef924611a8" ;
48
49
49
- static char * nrh_get_uuid (void ) {
50
- // TODO: UUID generation logic
51
- return nr_strdup ("bc21b5891f5e44fc9272caef924611a8" );
50
+ nr_status_t nrh_set_uuid (char * uuid ) {
51
+ if (UUID_LEN != nr_strlen (uuid )) {
52
+ return NR_FAILURE ;
53
+ }
54
+
55
+ nr_strlcpy (& health_uuid [0 ], uuid , UUID_LEN + 1 );
56
+
57
+ return NR_SUCCESS ;
52
58
}
53
59
54
60
char * nrh_strip_scheme_prefix (char * uri ) {
@@ -78,31 +84,7 @@ char* nrh_strip_scheme_prefix(char* uri) {
78
84
}
79
85
80
86
char * nrh_get_health_filename (void ) {
81
- return health_filename ;
82
- }
83
-
84
- nr_status_t nrh_set_health_filename (void ) {
85
- char * uuid = NULL ;
86
- char * fname = NULL ;
87
-
88
- uuid = nrh_get_uuid ();
89
-
90
- if (NULL == uuid ) {
91
- return NR_FAILURE ;
92
- }
93
-
94
- fname = nr_formatf ("health-%s.yml" , uuid );
95
-
96
- if (nr_strlen (fname ) != nr_strlen (health_filename )) {
97
- nr_free (uuid );
98
- return NR_FAILURE ;
99
- }
100
-
101
- nr_strcpy (& health_filename [0 ], fname );
102
-
103
- nr_free (uuid );
104
- nr_free (fname );
105
- return NR_SUCCESS ;
87
+ return nr_formatf ("health-%s.yml" , health_uuid );
106
88
}
107
89
108
90
char * nrh_get_health_location (char * uri ) {
@@ -134,12 +116,18 @@ char* nrh_get_health_location(char* uri) {
134
116
135
117
char * nrh_get_health_filepath (char * filedir ) {
136
118
char * filepath = NULL ;
119
+ char * filename = NULL ;
137
120
138
121
if (NULL == filedir ) {
139
122
return NULL ;
140
123
}
141
124
142
- filepath = nr_formatf ("%s/%s" , filedir , health_filename );
125
+ filename = nrh_get_health_filename ();
126
+ if (NULL == filename ) {
127
+ return NULL ;
128
+ }
129
+
130
+ filepath = nr_formatf ("%s/%s" , filedir , filename );
143
131
144
132
return filepath ;
145
133
}
0 commit comments