int check_create_dir(const char *file_orig) {
struct stat statbuf;
- char file_copy[512];
- char dir[512];
- int dir_len = 512;
+ char file_copy[PATH_MAX];
+ char dir[PATH_MAX];
char *fields[16];
int fields_num;
char *ptr;
if ((len = strlen(file_orig)) < 1)
return -1;
- else if (len >= sizeof(file_copy))
+ else if (len >= sizeof(file_copy)) {
+ ERROR("check_create_dir: name (%s) is too long.", file_orig);
return -1;
+ }
/*
* If `file_orig' ends in a slash the last component is a directory,
* Join the components together again
*/
dir[0] = '/';
- if (strjoin(dir + path_is_absolute, (size_t)(dir_len - path_is_absolute),
- fields, (size_t)(i + 1), "/") < 0) {
+ if (strjoin(dir + path_is_absolute,
+ (size_t)(sizeof(dir) - path_is_absolute), fields,
+ (size_t)(i + 1), "/") < 0) {
ERROR("strjoin failed: `%s', component #%i", file_orig, i);
return -1;
}
"CHRONOLOG", "DUMBCLOCK", "ULINK_M320", "PCF", /* 32-35 */
"WWV_AUDIO", "GPS_FG", "HOPF_S", "HOPF_P", /* 36-39 */
"JJY", "TT_IRIG", "GPS_ZYFER", "GPS_RIPENCC", /* 40-43 */
- "NEOCLK4X" /* 44 */
+ "NEOCLK4X", "PCI_TSYNC", "GPSD_JSON" /* 44-46 */
};
static size_t refclock_names_num = STATIC_ARRAY_SIZE(refclock_names);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
return 0;
} /* int ntpd_get_name_refclock */
-static int ntpd_get_name(char *buffer, size_t buffer_size,
- struct info_peer_summary const *peer_info) {
- uint32_t addr = ntohl(peer_info->srcadr);
-
- if (!peer_info->v6_flag && ((addr & REFCLOCK_MASK) == REFCLOCK_ADDR))
- return ntpd_get_name_refclock(buffer, buffer_size, peer_info);
- else
- return ntpd_get_name_from_address(buffer, buffer_size, peer_info,
- do_reverse_lookups);
-} /* int ntpd_addr_to_name */
-
static int ntpd_read(void) {
struct info_kernel *ik;
int ik_num;
ptr = ps + i;
- status = ntpd_get_name(peername, sizeof(peername), ptr);
+ int is_refclock = !ptr->v6_flag &&
+ ((ntohl(ptr->srcadr) & REFCLOCK_MASK) == REFCLOCK_ADDR);
+
+ if (is_refclock)
+ status = ntpd_get_name_refclock(peername, sizeof(peername), ptr);
+ else
+ status = ntpd_get_name_from_address(peername, sizeof(peername), ptr,
+ do_reverse_lookups);
+
if (status != 0) {
ERROR("ntpd plugin: Determining name of peer failed.");
continue;
M_LFPTOD(ntohl(ptr->offset_int), ntohl(ptr->offset_frc), offset);
DEBUG("peer %i:\n"
+ " is_refclock= %d\n"
+ " refclock_id= %d\n"
" peername = %s\n"
" srcadr = 0x%08x\n"
" reach = 0%03o\n"
" offset_frc = %i\n"
" offset = %f\n"
" dispersion = %f\n",
- i, peername, ntohl(ptr->srcadr), ptr->reach, ntpd_read_fp(ptr->delay),
+ i, is_refclock, (is_refclock > 0) ? refclock_id : 0, peername,
+ ntohl(ptr->srcadr), ptr->reach, ntpd_read_fp(ptr->delay),
ntohl(ptr->offset_int), ntohl(ptr->offset_frc), offset,
ntpd_read_fp(ptr->dispersion));
- if (refclock_id !=
- 1) /* not the system clock (offset will always be zero.. */
- ntpd_submit_reach("time_offset", peername, ptr->reach, offset);
ntpd_submit_reach("time_dispersion", peername, ptr->reach,
ntpd_read_fp(ptr->dispersion));
- if (refclock_id == 0) /* not a reference clock */
+
+ /* not the system clock (offset will always be zero) */
+ if (!(is_refclock && refclock_id == 1))
+ ntpd_submit_reach("time_offset", peername, ptr->reach, offset);
+
+ if (!is_refclock) /* not a reference clock */
ntpd_submit_reach("delay", peername, ptr->reach,
ntpd_read_fp(ptr->delay));
}
if ((status != 0) || (rc == NULL)) {
rc = malloc(sizeof(*rc));
if (rc == NULL) {
+ ERROR("rrdtool plugin: malloc failed: %s", STRERRNO);
pthread_mutex_unlock(&cache_lock);
return -1;
}
}
char filename[PATH_MAX];
- if (value_list_to_filename(filename, sizeof(filename), vl) != 0)
+ if (value_list_to_filename(filename, sizeof(filename), vl) != 0) {
+ ERROR("rrdtool plugin: failed to build filename");
return -1;
+ }
char values[32 * (ds->ds_num + 1)];
- if (value_list_to_string(values, sizeof(values), ds, vl) != 0)
+ if (value_list_to_string(values, sizeof(values), ds, vl) != 0) {
+ ERROR("rrdtool plugin: failed to build values string");
return -1;
+ }
struct stat statbuf = {0};
if (stat(filename, &statbuf) == -1) {
if (errno == ENOENT) {
if (cu_rrd_create_file(filename, ds, vl, &rrdcreate_config) != 0) {
+ ERROR("rrdtool plugin: cu_rrd_create_file (%s) failed.", filename);
return -1;
} else if (rrdcreate_config.async) {
return 0;
int ret = 0;
token->key = index_key;
- token->str = strndup(input + t_off, n);
+ /* copy at most n bytes from input with offset t_off into token->str */
+ input += t_off;
+ size_t len = strlen(input);
+ if (n < len)
+ len = n;
+
+ token->str = malloc(len + 1);
if (token->str == NULL)
goto free_offset_error;
+ memcpy(token->str, input, len);
+ token->str[len] = '\0';
+
*offset = t_off;
ret = c_avl_insert(tree, (void *)offset, (void *)token);
/* Parsing input string if necessary */
if (td->index_keys[i].regex) {
- regmatch_t m = {-1, -1};
+ regmatch_t m;
/* Parsing input string */
ret = snmp_agent_parse_index_key(ptr, &td->index_keys[i].regex_info,