Merge branch 'collectd-5.8'
[collectd.git] / src / utils_rrdcreate.c
index 86f7f3f..8f92cfd 100644 (file)
@@ -61,7 +61,7 @@ static int rra_types_num = STATIC_ARRAY_SIZE(rra_types);
 static pthread_mutex_t librrd_lock = PTHREAD_MUTEX_INITIALIZER;
 #endif
 
-static async_create_file_t *async_creation_list = NULL;
+static async_create_file_t *async_creation_list;
 static pthread_mutex_t async_creation_lock = PTHREAD_MUTEX_INITIALIZER;
 
 /*
@@ -96,7 +96,7 @@ static srrd_create_args_t *srrd_create_args_create(const char *filename,
 
   args = calloc(1, sizeof(*args));
   if (args == NULL) {
-    ERROR("srrd_create_args_create: calloc failed.");
+    P_ERROR("srrd_create_args_create: calloc failed.");
     return NULL;
   }
   args->filename = NULL;
@@ -106,14 +106,14 @@ static srrd_create_args_t *srrd_create_args_create(const char *filename,
 
   args->filename = strdup(filename);
   if (args->filename == NULL) {
-    ERROR("srrd_create_args_create: strdup failed.");
+    P_ERROR("srrd_create_args_create: strdup failed.");
     srrd_create_args_destroy(args);
     return NULL;
   }
 
   args->argv = calloc((size_t)(argc + 1), sizeof(*args->argv));
   if (args->argv == NULL) {
-    ERROR("srrd_create_args_create: calloc failed.");
+    P_ERROR("srrd_create_args_create: calloc failed.");
     srrd_create_args_destroy(args);
     return NULL;
   }
@@ -121,7 +121,7 @@ static srrd_create_args_t *srrd_create_args_create(const char *filename,
   for (args->argc = 0; args->argc < argc; args->argc++) {
     args->argv[args->argc] = strdup(argv[args->argc]);
     if (args->argv[args->argc] == NULL) {
-      ERROR("srrd_create_args_create: strdup failed.");
+      P_ERROR("srrd_create_args_create: strdup failed.");
       srrd_create_args_destroy(args);
       return NULL;
     }
@@ -208,11 +208,11 @@ static int rra_get(char ***ret, const value_list_t *vl, /* {{{ */
       if (rra_num >= rra_max)
         break;
 
-      status = ssnprintf(buffer, sizeof(buffer), "RRA:%s:%.10f:%u:%u",
-                         rra_types[j], cfg->xff, cdp_len, cdp_num);
+      status = snprintf(buffer, sizeof(buffer), "RRA:%s:%.10f:%u:%u",
+                        rra_types[j], cfg->xff, cdp_len, cdp_num);
 
       if ((status < 0) || ((size_t)status >= sizeof(buffer))) {
-        ERROR("rra_get: Buffer would have been truncated.");
+        P_ERROR("rra_get: Buffer would have been truncated.");
         continue;
       }
 
@@ -251,9 +251,7 @@ static int ds_get(char ***ret, /* {{{ */
 
   ds_def = calloc(ds->ds_num, sizeof(*ds_def));
   if (ds_def == NULL) {
-    char errbuf[1024];
-    ERROR("rrdtool plugin: calloc failed: %s",
-          sstrerror(errno, errbuf, sizeof(errbuf)));
+    P_ERROR("ds_get: calloc failed: %s", STRERRNO);
     return -1;
   }
 
@@ -273,25 +271,25 @@ static int ds_get(char ***ret, /* {{{ */
     else if (d->type == DS_TYPE_ABSOLUTE)
       type = "ABSOLUTE";
     else {
-      ERROR("rrdtool plugin: Unknown DS type: %i", d->type);
+      P_ERROR("ds_get: Unknown DS type: %i", d->type);
       break;
     }
 
     if (isnan(d->min)) {
       sstrncpy(min, "U", sizeof(min));
     } else
-      ssnprintf(min, sizeof(min), "%f", d->min);
+      snprintf(min, sizeof(min), "%f", d->min);
 
     if (isnan(d->max)) {
       sstrncpy(max, "U", sizeof(max));
     } else
-      ssnprintf(max, sizeof(max), "%f", d->max);
+      snprintf(max, sizeof(max), "%f", d->max);
 
-    status = ssnprintf(buffer, sizeof(buffer), "DS:%s:%s:%i:%s:%s", d->name,
-                       type, (cfg->heartbeat > 0)
-                                 ? cfg->heartbeat
-                                 : (int)CDTIME_T_TO_TIME_T(2 * vl->interval),
-                       min, max);
+    status = snprintf(
+        buffer, sizeof(buffer), "DS:%s:%s:%i:%s:%s", d->name, type,
+        (cfg->heartbeat > 0) ? cfg->heartbeat
+                             : (int)CDTIME_T_TO_TIME_T(2 * vl->interval),
+        min, max);
     if ((status < 1) || ((size_t)status >= sizeof(buffer)))
       break;
 
@@ -337,8 +335,8 @@ static int srrd_create(const char *filename, /* {{{ */
   status = rrd_create_r(filename_copy, pdp_step, last_up, argc, (void *)argv);
 
   if (status != 0) {
-    WARNING("rrdtool plugin: rrd_create_r (%s) failed: %s", filename,
-            rrd_get_error());
+    P_WARNING("srrd_create: rrd_create_r (%s) failed: %s", filename,
+              rrd_get_error());
   }
 
   sfree(filename_copy);
@@ -362,15 +360,15 @@ static int srrd_create(const char *filename, /* {{{ */
   new_argc = 6 + argc;
   new_argv = malloc((new_argc + 1) * sizeof(*new_argv));
   if (new_argv == NULL) {
-    ERROR("rrdtool plugin: malloc failed.");
+    P_ERROR("srrd_create: malloc failed.");
     return -1;
   }
 
   if (last_up == 0)
     last_up = time(NULL) - 10;
 
-  ssnprintf(pdp_step_str, sizeof(pdp_step_str), "%lu", pdp_step);
-  ssnprintf(last_up_str, sizeof(last_up_str), "%lu", (unsigned long)last_up);
+  snprintf(pdp_step_str, sizeof(pdp_step_str), "%lu", pdp_step);
+  snprintf(last_up_str, sizeof(last_up_str), "%lu", (unsigned long)last_up);
 
   new_argv[0] = "create";
   new_argv[1] = (void *)filename;
@@ -390,8 +388,8 @@ static int srrd_create(const char *filename, /* {{{ */
   pthread_mutex_unlock(&librrd_lock);
 
   if (status != 0) {
-    WARNING("rrdtool plugin: rrd_create (%s) failed: %s", filename,
-            rrd_get_error());
+    P_WARNING("srrd_create: rrd_create (%s) failed: %s", filename,
+              rrd_get_error());
   }
 
   sfree(new_argv);
@@ -489,21 +487,22 @@ static void *srrd_create_thread(void *targs) /* {{{ */
   status = lock_file(args->filename);
   if (status != 0) {
     if (status == EEXIST)
-      NOTICE("srrd_create_thread: File \"%s\" is already being created.",
-             args->filename);
+      P_NOTICE("srrd_create_thread: File \"%s\" is already being created.",
+               args->filename);
     else
-      ERROR("srrd_create_thread: Unable to lock file \"%s\".", args->filename);
+      P_ERROR("srrd_create_thread: Unable to lock file \"%s\".",
+              args->filename);
     srrd_create_args_destroy(args);
     return 0;
   }
 
-  ssnprintf(tmpfile, sizeof(tmpfile), "%s.async", args->filename);
+  snprintf(tmpfile, sizeof(tmpfile), "%s.async", args->filename);
 
   status = srrd_create(tmpfile, args->pdp_step, args->last_up, args->argc,
                        (void *)args->argv);
   if (status != 0) {
-    WARNING("srrd_create_thread: srrd_create (%s) returned status %i.",
-            args->filename, status);
+    P_WARNING("srrd_create_thread: srrd_create (%s) returned status %i.",
+              args->filename, status);
     unlink(tmpfile);
     unlock_file(args->filename);
     srrd_create_args_destroy(args);
@@ -512,9 +511,8 @@ static void *srrd_create_thread(void *targs) /* {{{ */
 
   status = rename(tmpfile, args->filename);
   if (status != 0) {
-    char errbuf[1024];
-    ERROR("srrd_create_thread: rename (\"%s\", \"%s\") failed: %s", tmpfile,
-          args->filename, sstrerror(errno, errbuf, sizeof(errbuf)));
+    P_ERROR("srrd_create_thread: rename (\"%s\", \"%s\") failed: %s", tmpfile,
+            args->filename, STRERRNO);
     unlink(tmpfile);
     unlock_file(args->filename);
     srrd_create_args_destroy(args);
@@ -559,9 +557,7 @@ static int srrd_create_async(const char *filename, /* {{{ */
 
   status = pthread_create(&thread, &attr, srrd_create_thread, args);
   if (status != 0) {
-    char errbuf[1024];
-    ERROR("srrd_create_async: pthread_create failed: %s",
-          sstrerror(status, errbuf, sizeof(errbuf)));
+    P_ERROR("srrd_create_async: pthread_create failed: %s", STRERROR(status));
     pthread_attr_destroy(&attr);
     srrd_create_args_destroy(args);
     return status;
@@ -592,12 +588,12 @@ int cu_rrd_create_file(const char *filename, /* {{{ */
     return -1;
 
   if ((rra_num = rra_get(&rra_def, vl, cfg)) < 1) {
-    ERROR("cu_rrd_create_file failed: Could not calculate RRAs");
+    P_ERROR("cu_rrd_create_file failed: Could not calculate RRAs");
     return -1;
   }
 
   if ((ds_num = ds_get(&ds_def, ds, vl, cfg)) < 1) {
-    ERROR("cu_rrd_create_file failed: Could not calculate DSes");
+    P_ERROR("cu_rrd_create_file failed: Could not calculate DSes");
     rra_free(rra_num, rra_def);
     return -1;
   }
@@ -605,9 +601,7 @@ int cu_rrd_create_file(const char *filename, /* {{{ */
   argc = ds_num + rra_num;
 
   if ((argv = malloc(sizeof(*argv) * (argc + 1))) == NULL) {
-    char errbuf[1024];
-    ERROR("cu_rrd_create_file failed: %s",
-          sstrerror(errno, errbuf, sizeof(errbuf)));
+    P_ERROR("cu_rrd_create_file failed: %s", STRERRNO);
     rra_free(rra_num, rra_def);
     ds_free(ds_num, ds_def);
     return -1;
@@ -631,25 +625,25 @@ int cu_rrd_create_file(const char *filename, /* {{{ */
     status = srrd_create_async(filename, stepsize, last_up, argc,
                                (const char **)argv);
     if (status != 0)
-      WARNING("cu_rrd_create_file: srrd_create_async (%s) "
-              "returned status %i.",
-              filename, status);
+      P_WARNING("cu_rrd_create_file: srrd_create_async (%s) "
+                "returned status %i.",
+                filename, status);
   } else /* synchronous */
   {
     status = lock_file(filename);
     if (status != 0) {
       if (status == EEXIST)
-        NOTICE("cu_rrd_create_file: File \"%s\" is already being created.",
-               filename);
+        P_NOTICE("cu_rrd_create_file: File \"%s\" is already being created.",
+                 filename);
       else
-        ERROR("cu_rrd_create_file: Unable to lock file \"%s\".", filename);
+        P_ERROR("cu_rrd_create_file: Unable to lock file \"%s\".", filename);
     } else {
       status =
           srrd_create(filename, stepsize, last_up, argc, (const char **)argv);
 
       if (status != 0) {
-        WARNING("cu_rrd_create_file: srrd_create (%s) returned status %i.",
-                filename, status);
+        P_WARNING("cu_rrd_create_file: srrd_create (%s) returned status %i.",
+                  filename, status);
       } else {
         DEBUG("cu_rrd_create_file: Successfully created RRD file \"%s\".",
               filename);