fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash
[lttng-tools.git] / src / bin / lttng / conf.cpp
index d79fba989f1368bc75cfcb2575f8b459b232b7cb..65be35a158f70518dda1317f78900347ba67b117 100644 (file)
@@ -6,6 +6,12 @@
  */
 
 #define _LGPL_SOURCE
+#include "conf.hpp"
+
+#include <common/common.hpp>
+#include <common/compat/errno.hpp>
+#include <common/utils.hpp>
+
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <unistd.h>
 
-#include <common/compat/errno.hpp>
-#include <common/common.hpp>
-#include <common/utils.hpp>
-
-#include "conf.hpp"
-
 /*
  * Returns the path with '/CONFIG_FILENAME' added to it;
  * path will be NULL if an error occurs.
@@ -32,7 +32,7 @@ char *config_get_file_path(const char *path)
        ret = asprintf(&file_path, "%s/%s", path, CONFIG_FILENAME);
        if (ret < 0) {
                ERR("Fail allocating config file path");
-               file_path = NULL;
+               file_path = nullptr;
        }
 
        return file_path;
@@ -44,16 +44,16 @@ char *config_get_file_path(const char *path)
  */
 static FILE *open_config(const char *path, const char *mode)
 {
-       FILE *fp = NULL;
+       FILE *fp = nullptr;
        char *file_path;
 
        file_path = config_get_file_path(path);
-       if (file_path == NULL) {
+       if (file_path == nullptr) {
                goto error;
        }
 
        fp = fopen(file_path, mode);
-       if (fp == NULL) {
+       if (fp == nullptr) {
                goto error;
        }
 
@@ -73,7 +73,7 @@ static int create_config_file(const char *path)
        FILE *fp;
 
        fp = open_config(path, "w+");
-       if (fp == NULL) {
+       if (fp == nullptr) {
                ERR("Unable to create config file");
                ret = -1;
                goto error;
@@ -97,7 +97,7 @@ static int write_config(const char *file_path, size_t size, char *data)
        int ret = 0;
 
        fp = open_config(file_path, "a");
-       if (fp == NULL) {
+       if (fp == nullptr) {
                ret = -1;
                goto end;
        }
@@ -123,7 +123,7 @@ void config_destroy(const char *path)
        char *config_path;
 
        config_path = config_get_file_path(path);
-       if (config_path == NULL) {
+       if (config_path == nullptr) {
                return;
        }
 
@@ -143,10 +143,10 @@ end:
 /*
  * Destroys the default config
  */
-void config_destroy_default(void)
+void config_destroy_default()
 {
        const char *path = utils_get_home_dir();
-       if (path == NULL) {
+       if (path == nullptr) {
                return;
        }
        config_destroy(path);
@@ -167,34 +167,35 @@ int config_exists(const char *path)
        return S_ISREG(info.st_mode) || S_ISDIR(info.st_mode);
 }
 
-static
-int _config_read_session_name(const char *path, char **name)
+static int _config_read_session_name(const char *path, char **name)
 {
        int ret = 0;
        FILE *fp;
        char var[NAME_MAX], *session_name;
 
 #if (NAME_MAX == 255)
-#define NAME_MAX_SCANF_IS_A_BROKEN_API "254"
+#define NAME_MAX_SCANF_IS_A_BROKEN_API "254"
 #endif
 
-       session_name = (char *) zmalloc(NAME_MAX);
-       if (session_name == NULL) {
+       session_name = calloc<char>(NAME_MAX);
+       if (session_name == nullptr) {
                ret = -ENOMEM;
                ERR("Out of memory");
                goto error;
        }
 
        fp = open_config(path, "r");
-       if (fp == NULL) {
+       if (fp == nullptr) {
                ret = -ENOENT;
                goto error;
        }
 
        while (!feof(fp)) {
-               if ((ret = fscanf(fp, "%" NAME_MAX_SCANF_IS_A_BROKEN_API
-                               "[^'=']=%" NAME_MAX_SCANF_IS_A_BROKEN_API "s\n",
-                               var, session_name)) != 2) {
+               if ((ret = fscanf(fp,
+                                 "%" NAME_MAX_SCANF_IS_A_BROKEN_API
+                                 "[^'=']=%" NAME_MAX_SCANF_IS_A_BROKEN_API "s\n",
+                                 var,
+                                 session_name)) != 2) {
                        if (ret == -1) {
                                ERR("Missing session=NAME in config file.");
                                goto error_close;
@@ -231,7 +232,7 @@ found:
 char *config_read_session_name(const char *path)
 {
        int ret;
-       char *name = NULL;
+       char *name = nullptr;
 
        ret = _config_read_session_name(path, &name);
        if (ret == -ENOENT) {
@@ -252,7 +253,7 @@ char *config_read_session_name(const char *path)
  */
 char *config_read_session_name_quiet(const char *path)
 {
-       char *name = NULL;
+       char *name = nullptr;
 
        (void) _config_read_session_name(path, &name);
        return name;
@@ -295,7 +296,7 @@ int config_init(const char *session_name)
        const char *path;
 
        path = utils_get_home_dir();
-       if (path == NULL) {
+       if (path == nullptr) {
                ret = -1;
                goto error;
        }
This page took 0.02556 seconds and 4 git commands to generate.